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

escape text in code block when lang is 'text' or not specified #31

Closed
lazzzis opened this issue Apr 15, 2018 · 1 comment
Closed

escape text in code block when lang is 'text' or not specified #31

lazzzis opened this issue Apr 15, 2018 · 1 comment

Comments

@lazzzis
Copy link
Contributor

lazzzis commented Apr 15, 2018

Content in my markdown file:

Run vuepress dev, it throws an error:

Run vuepress build, it doesn't throw an error. But the page is not rendered as expected:


I guess the cause is that code isn't escaped, when lang is 'text' or not specified.

function wrap (code, lang) {
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
}

Since prism would automatically escape code:

> prism.highlight('<scheme>', prism.languages['html'], 'html')
'<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scheme</span><span class="token punctuation">></span></span>'

A quick solution might be:

const escapeHtml = require('escape-html')

function wrap (code, lang) {
  if (lang === 'text') {
    code = escapeHtml(code)
  }
  return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
}

This solution works well both on vuepress dev and vuepress build. But I don't know if this is a good solution

@ulivz
Copy link
Member

ulivz commented Apr 15, 2018

PR welcome.

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

No branches or pull requests

3 participants