mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +03:00
fix: html characters not escaped in code blocks (fixes #378)
if lang is not specified
This commit is contained in:
parent
a5e4e2aeaa
commit
fef9ec476c
|
@ -5,6 +5,13 @@ import * as slugify from 'slugify';
|
||||||
import * as Remarkable from 'remarkable';
|
import * as Remarkable from 'remarkable';
|
||||||
import { StringMap } from './';
|
import { StringMap } from './';
|
||||||
|
|
||||||
|
function HTMLescape(html: string): string {
|
||||||
|
return document.createElement('div')
|
||||||
|
.appendChild(document.createTextNode(html))
|
||||||
|
.parentElement
|
||||||
|
.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
declare var Prism: any;
|
declare var Prism: any;
|
||||||
const md = new Remarkable({
|
const md = new Remarkable({
|
||||||
html: true,
|
html: true,
|
||||||
|
@ -15,7 +22,7 @@ const md = new Remarkable({
|
||||||
if (lang === 'json') lang = 'js';
|
if (lang === 'json') lang = 'js';
|
||||||
let grammar = Prism.languages[lang];
|
let grammar = Prism.languages[lang];
|
||||||
// fallback to click
|
// fallback to click
|
||||||
if (!grammar) return str;
|
if (!grammar) return HTMLescape(str);
|
||||||
return Prism.highlight(str, grammar);
|
return Prism.highlight(str, grammar);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user