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-prismjs optionally allow additional html entities to be escaped #20128

Closed
patricksimonian opened this issue Dec 13, 2019 · 2 comments · Fixed by #20156
Closed

Comments

@patricksimonian
Copy link
Contributor

patricksimonian commented Dec 13, 2019

Summary

Digging into the gatsby-remark-prismjs code highlights that the most common HTML entities ( <, >, ", ```, etc) are escaped using the lodash.escape function. I have personally encountered the requirement to expand on the number of characters escaped to include curly braces (`{`).

Basic example

Allow another option in the plugin to allow for additional characters to be replaced by an encoded version.
Immediately I foresee two ways to accomplish this:

  1. The plugin stores a dictionary of all HTML entities and their encoded versions and the plugin option allows the user to pass in a list of entities.
{
   resolve: 'gatsby-remark-prismjs`
   options: {
      ...,
     escapeEntities: [ '}',  '{' ],
    },
}
  1. The plugin allows a dictionary to be passed in so that the user is in control of how values get replaced.
{
   resolve: 'gatsby-remark-prismjs`
   options: {
      ...,
     escapeEntities: {
          '{': '&#123;',
      }
    },
}

Motivation

During the support of my application, I encountered a very hard to debug the issue. The static site Server I was using (Caddy Server) was evaluating ansible handle bar code examples {{ .. }} as valid Caddy template variables. This was causing my server to crash.

To me, the most sensible solution allows for additional HTML entities to be escaped.

I initially authored my own remark plugin to escape these entities...which did work but unfortunately, it is not compatible with the remark-prismjs because it requires changing the mdast node.type

@patricksimonian
Copy link
Contributor Author

I'm also happy to make a PR for these changes if the approach is acceptable

@LekoArts
Copy link
Contributor

Option 2 seems like a good idea. Would appreciate a PR!

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 a pull request may close this issue.

2 participants