Skip to content

Commit

Permalink
fixing xml/html code example escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed May 31, 2019
1 parent a078187 commit f6e7152
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 3 additions & 5 deletions site/scripts/markdown-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ function collectHeadingMetadata(renderer, metadata) {
exports.collectHeadingMetadata = collectHeadingMetadata;
function changeCodeCreation(renderer) {
function highlight(code, lang) {
if (lang === 'html' || lang === 'xml') {
code = code.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
if (lang != null && languages.indexOf(lang) !== -1) {
return prismjs_1.default.highlight(code, prismjs_1.default.languages[lang]);
}
Expand All @@ -138,6 +133,9 @@ function changeCodeCreation(renderer) {
return line;
})
.join('\n');
if (['html', 'xml'].indexOf(lang) !== -1) {
lang = 'markup';
}
const out = highlight(code, lang);
if (out != null) {
escaped = true;
Expand Down
10 changes: 5 additions & 5 deletions site/scripts/markdown-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ export function collectHeadingMetadata(renderer: marked.Renderer, metadata: Mark

export function changeCodeCreation(renderer: marked.Renderer) {
function highlight(code: string, lang?: string) {
if (lang === 'html' || lang === 'xml') {
code = code.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
if (lang != null && languages.indexOf(lang) !== -1) {
return Prism.highlight(code, Prism.languages[lang]);
}
Expand All @@ -139,6 +134,11 @@ export function changeCodeCreation(renderer: marked.Renderer) {
return line;
})
.join('\n');

// markup type gets escaped properly
if (['html','xml'].indexOf(lang) !== -1) {
lang = 'markup';
}

const out = highlight(code, lang);

Expand Down

0 comments on commit f6e7152

Please sign in to comment.