diff --git a/public/main.ts b/public/main.ts index 2056ae3..a4b997e 100644 --- a/public/main.ts +++ b/public/main.ts @@ -1,7 +1,7 @@ +import 'highlight.js/styles/tokyo-night-dark.css'; import './style.css'; import './markdown.css'; import './favicon.svg'; -import 'highlight.js/styles/tokyo-night-dark.css'; import moment from 'moment'; import md from 'markdown-it'; import hljs from 'highlight.js'; @@ -31,7 +31,22 @@ document.addEventListener('DOMContentLoaded', () => { } document.querySelectorAll('.markdown').forEach((e: HTMLElement) => { - e.innerHTML = md().render(e.innerHTML); + e.innerHTML = md({ + html: true, + highlight: function (str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + console.log(str) + console.log(hljs.highlight(str, {language: lang, ignoreIllegals: false}, false)); + return '
' +
+ hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+ '
';
+ } catch (__) {}
+ }
+
+ return '' + md().utils.escapeHtml(str) + '
';
+ }
+ }).render(e.textContent);
});
document.querySelectorAll