fix: async highlight and escape html in docs (#2512)

This commit is contained in:
Yash Singh 2021-11-25 12:43:16 -08:00 committed by GitHub
parent 4089ee8786
commit 6e5180bd1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -55,6 +55,10 @@
})
}
function escapeHTML(html) {
return html.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll('\'', '&apos;')
}
window.$docsify = {
search: 'auto',
name: 'mermaid',
@ -73,7 +77,7 @@
currentCodeExample++;
colorize.push(currentCodeExample);
resultingHTML += (
'<pre id="code' + currentCodeExample + '">' + code + '</pre>'
'<pre id="code' + currentCodeExample + '">' + escapeHTML(code) + '</pre>'
)
}
@ -100,10 +104,11 @@
})
hook.afterEach(function (html, next) {
next(html);
(async() => {
while (!window.hasOwnProperty("monaco"))
await new Promise(resolve => setTimeout(resolve, 1000));
colorizeEverything(html).then(newHTML => next(newHTML))
colorizeEverything(html).then(newHTML => document.querySelector('article.markdown-section').innerHTML = newHTML)
})();
})
}