Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[gatsby-transformer-remark] Section titles with code in ``s creates escaped HTML <code> tags #13608
Comments
This comment has been minimized.
This comment has been minimized.
|
This looks like the same thing as #5764, but I'm not using the Here's my |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I made a dirty edit of
and replace All it does is replace pinging @pieh, what do you think about this approach? It could be a bit more generalized i.e user can pass in an option to ignore inline code in certain elements etc. |
This comment has been minimized.
This comment has been minimized.
|
@d4rekanguok yep that fixed it for me! Thanks so much. Looking forward to seeing the fix upstream |
This comment has been minimized.
This comment has been minimized.
|
@d4rekanguok I'm not sure I like the idea - as it would remove I'm not sure if there's better alternative tho |
This comment has been minimized.
This comment has been minimized.
|
@pieh We'd still keep the But it looks like all it does is attaching a class name to inline code -- could we just add a |
This comment has been minimized.
This comment has been minimized.
|
That works, I managed to retain the class name generated by remark-prismjs for inline code inside headings while
I'm specifically targeting if (parent.type === `heading`) {
if (!node.data) node.data = {};
node.data.hProperties = { className: [className] }
}
else {
node.type = `html`;
node.value = `<code class="${className}">${highlightCode(languageName, node.value)}</code>`;
} |
This comment has been minimized.
This comment has been minimized.
|
I think we potentially try to approach this from wrong direction - right now we are trying to workaround that |
This comment has been minimized.
This comment has been minimized.
|
oh, do you mean to strip out html code during mdast to toc transformation? That would certainly be a lot cleaner |
This comment has been minimized.
This comment has been minimized.
BarryThePenguin
commented
Apr 25, 2019
|
I don't have much knowledge of gatsby, or the gatsby ecosystem, so I'm looking at this issue with a 10,000 foot view In regards to syntax highlighting,
I'm wondering if this issue stems from a similar circumstance? Looking at |
This comment has been minimized.
This comment has been minimized.
|
@BarryThePenguin Thank you for the quick response, and great suggestions!
I was exploring the option of turning Because of this, I was hoping to be able to resolve |


Ameobea commentedApr 24, 2019
Description
When using the automatic TOC generation from
gatsby-transformer-remarkwith markdown section titles that contain code in backticks, the generated TOC heading contains escaped HTML<code>tags that show up in the document. Instead of actually emitting the<code>tag in the HTML string, it's escaped and the HTML is rendered as text.Steps to reproduce
Create a markdown remark with a heading like this:
## Generating TOCs with `gatsby-transformer-remark`This will generate the following HTML string for the TOC:
<ul>\n<li><a href=\"/demo/#generating-tocs-with-code-classlanguage-textgatsby-transformer-remarkcode\">Generating TOCs with <code class=\"language-text\">gatsby-transformer-remark</code></a></li>\n</ul>Expected result
The
<code>tag shouldn't be escaped and should be emitted directlyActual result
The
<code>tag is escaped, causing it to be rendered as text rather than as HTML.Environment