Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-remark-prism]: Hightlighting empty line hides it from source view and moves other lines up #17849

Closed
ethernal opened this issue Sep 24, 2019 · 7 comments
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem type: bug An issue or pull request relating to a bug in Gatsby

Comments

@ethernal
Copy link

Description

Issue was automatically closed. Reopening as new one.

This issue is for gatsby-remark-prism plugin.

When highlighting empty line it disappears due to rendering of empty span.

line-hidden-due-to-empty-span

ex. in case line 3 is empty and lines 3, 5 and 6 should be highlighted the code will produce almost expected results but the lines 5 and 6 will have numbers 4 and 5 and line 3 will be not visible.

Steps to reproduce

Tested in Firefox and Chrome.
CSS files are from documentation site.
Order did not matter.

####gatsby-browser.js

require("prismjs/themes/prism-tomorrow.css")
require("prismjs/plugins/command-line/prism-command-line.css")
require("prismjs/plugins/line-numbers/prism-line-numbers.css")
require("./src/css/prism/line-highlight.css")
require("./src/css/prism/line-numbers.css")
require("./src/css/prism/command-prompt.css")

MDX file

set code options to: javascript {numberLines: true}{4,8,13}

import React from "react"
import Layout from "../components/layout/layout"
import SEO from "../components/seo"

const NotFoundPage = () => (
  <Layout>
    <SEO title="404: Not found" />
    <h1>NOT FOUND</h1>
    <p>You just hit a route that doesn't exist... the sadness.</p>
  </Layout>
)

export default NotFoundPage

Mark empty line to highlight it or include empty line in highlight range.

Expected result

Empty line should be highlighted as removing/hiding it breaks the line numbering logic.

line showing with nbsp

Actual result

Line disappears due to span being empty.

Solution

in directives.js in gatsby-remark-prism

change line:

highlightWrap(line.code)

to:

line.code
            ? (line.code = highlightWrap(line.code))
            : (line.code = highlightWrap("&nbsp;"))

I will make a PR for this and link it here.

It might be that only I am affected as the issue is annoying and would have been reported already, I think.

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 12.1.0 - D:\software\nodejs\node.EXE
Yarn: 1.17.3 - D:\software\yarn\bin\yarn.CMD
npm: 6.9.0 - D:\software\nodejs\npm.CMD
Languages:
Python: 2.7.15 - /c/Users/xxxxxx/.windows-build-tools/python27/python
Browsers:
Edge: 42.17134.1.0
npmPackages:
gatsby: ^2.13.12 => 2.13.12
gatsby-image: ^2.2.4 => 2.2.4
gatsby-plugin-emotion: ^4.1.2 => 4.1.2
gatsby-plugin-manifest: ^2.2.1 => 2.2.1
gatsby-plugin-mdx: ^1.0.11 => 1.0.11
gatsby-plugin-offline: ^2.2.1 => 2.2.1
gatsby-plugin-react-helmet: ^3.1.0 => 3.1.0
gatsby-plugin-sharp: ^2.2.3 => 2.2.3
gatsby-plugin-typography: ^2.3.3 => 2.3.3
gatsby-remark-embed-snippet: ^4.1.2 => 4.1.2
gatsby-remark-emoji: ^0.0.3 => 0.0.3
gatsby-remark-images: ^3.1.3 => 3.1.3
gatsby-remark-prismjs: ^3.3.5 => 3.3.5
gatsby-source-filesystem: ^2.1.3 => 2.1.3
gatsby-transformer-remark: ^2.6.14 => 2.6.14
gatsby-transformer-sharp: ^2.2.1 => 2.2.1

@gatsbot
Copy link

gatsbot bot commented Oct 15, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Oct 15, 2019
@ethernal
Copy link
Author

It is not stale.

@muescha muescha added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Oct 16, 2019
@wardpeet wardpeet added the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Nov 14, 2019
@wardpeet
Copy link
Contributor

Hey @ethernal sorry for the late response.

To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

@ethernal
Copy link
Author

ethernal commented Nov 18, 2019

Here is the repo with code: https://github.com/ethernal/gatsby-remark-prism-example

I removed most data but left all other stuff. Please navigate to Blog->Hello World.

You will see the exact problem. After modifying react prism it will go away.

@JCMais
Copy link

JCMais commented May 1, 2020

same issue

@wardpeet wardpeet added topic: remark/mdx Related to Markdown, remark & MDX ecosystem type: bug An issue or pull request relating to a bug in Gatsby and removed status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels May 13, 2020
@andrew-chang-dewitt
Copy link

andrew-chang-dewitt commented Oct 30, 2020

So #18719 was closed because #21711 supposedly fixed this issue, but I'm still experiencing this bug.

I've updated gatsby & gatsby-prism-js (really all of my dependencies). Has #21711 not landed in a release yet, or is it possible that #18719 needs reopened?

Edit: corrected reference to #18719

andrew-chang-dewitt added a commit to andrew-chang-dewitt/andrew-chang-dewitt-website that referenced this issue Nov 10, 2020
- Didn't fix issue with line highlighting though.
- Looks to be related to gatsbyjs/gatsby/issues/17849
- Found fix in PR gatsbyjs/gatsby/pull/18719, implementing manually
  in `node_modules` helps, but doesn't completely resolve the issue
- Committing updates & pushing to v1.4 minor update, but leaving this
  issue open pending a real resolution.
@LekoArts
Copy link
Contributor

Hi!

I'm closing this as a stale issue as in the meantime Gatsby 4 and related packages were released. You can check our Framework Version Support Page to see which versions currently receive active support.

Please try the mentioned issue on the latest version (using the next tag) and if you still see this problem, open a new bug report. It must include a minimal reproduction.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants