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

fix(gatsby-remark-prismjs): prevent additional blank line from appearing #10209

Merged
merged 3 commits into from
Nov 29, 2018

Conversation

DSchau
Copy link
Contributor

@DSchau DSchau commented Nov 29, 2018

This PR fixes a small bug where an extra line character is rendered as the generated HTML contains a structure like </span>\n</span>. This new line character causes a blank line to be inserted into the resultant highlighted code.

I've validated that this doesn't seem to cause any regressions with the kitchen sink.

Changes in this PR

screen shot 2018-11-29 at 1 59 50 pm

Published version

screen shot 2018-11-29 at 2 01 56 pm

"<span class=\\"gatsby-highlight-code-line\\"> return \\"hello world\\"
</span>"
`;
exports[`highlighting a line range highlight-line highlights line 1`] = `"<span class=\\"gatsby-highlight-code-line\\"> return \\"hello world\\"</span>"`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diffs are a little messy, but it just removes the hard line breaks from the diffs. This will be handled via HTML start/end tags anyways, so this should be just fine.

@@ -47,7 +47,7 @@ const stripComment = line =>
)

const wrap = line =>
[`<span class="gatsby-highlight-code-line">`, `${line}\n`, `</span>`].join(``)
[`<span class="gatsby-highlight-code-line">`, `${line}`, `</span>`].join(``)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix. One character 🆗

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 Thanks @DSchau!

@pieh pieh merged commit 71d7f23 into gatsbyjs:master Nov 29, 2018
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…ing (gatsbyjs#10209)

* fix(gatsby-remark-prismjs): prevent additional blank line from appearing

* chore: don't use template literals; not needed

* test: update snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants