Skip to content

Commit 4279357

Browse files
committed
fix: escape text in code block when lang is text or not specified vuejs#31
1 parent 86d4055 commit 4279357

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

lib/markdown/highlight.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const chalk = require('chalk')
22
const prism = require('prismjs')
33
const loadLanguages = require('prismjs/components/index')
4+
const escapeHtml = require('escape-html')
45

56
// required to make embedded highlighting work...
67
loadLanguages(['markup', 'css', 'javascript'])
78

89
function wrap (code, lang) {
10+
if (lang === 'text') {
11+
code = escapeHtml(code)
12+
}
913
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
1014
}
1115

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"copy-webpack-plugin": "^4.5.1",
5252
"css-loader": "^0.28.11",
5353
"es6-promise": "^4.2.4",
54+
"escape-html": "^1.0.3",
5455
"file-loader": "^1.1.11",
5556
"globby": "^8.0.1",
5657
"html-webpack-plugin": "^3.2.0",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ es6-promise@^4.2.4:
15781578
version "4.2.4"
15791579
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.4.tgz#dc4221c2b16518760bd8c39a52d8f356fc00ed29"
15801580

1581-
escape-html@~1.0.1:
1581+
escape-html@^1.0.3, escape-html@~1.0.1:
15821582
version "1.0.3"
15831583
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
15841584

0 commit comments

Comments
 (0)