- increased text size a bit - removed unused css from kbd tag - removed unused white link css - added space before all headers except h1 - moved type decclaration files to one directory - replaced tag icon to hashtag - redesigned post card - removed unnecessary margin from post card titles - removed post card content preview - organized recursive parsing code
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import markdownIt from "markdown-it" // rendering markdown
|
|
import markdownItTexMath from "markdown-it-texmath" // rendering mathematical expression
|
|
import markdownItAnchor from "markdown-it-anchor" // markdown anchor
|
|
import markdownItTaskCheckbox from "markdown-it-task-checkbox"
|
|
import hljs from "highlight.js" // code block highlighting
|
|
import katex from "katex" // rendering mathematical expression
|
|
import { nthIndex } from "./util"
|
|
|
|
const md = markdownIt({
|
|
// https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
|
|
highlight: function (str, lang) {
|
|
if (lang && hljs.getLanguage(lang)) {
|
|
try {
|
|
return hljs.highlight(str, { language: lang }).value
|
|
// eslint-disable-next-line no-empty
|
|
} catch (error) {}
|
|
}
|
|
|
|
return "" // use external default escaping
|
|
},
|
|
html: true,
|
|
})
|
|
.use(markdownItTaskCheckbox)
|
|
.use(markdownItTexMath, {
|
|
engine: katex,
|
|
delimiters: "dollars",
|
|
katexOptions: { macros: { "\\RR": "\\mathbb{R}" } },
|
|
})
|
|
.use(markdownItAnchor, {})
|
|
|
|
export default function parseMarkdown(markdownRaw: string): string {
|
|
return (
|
|
md.render(markdownRaw.slice(nthIndex(markdownRaw, "---", 2) + 3)) || ""
|
|
)
|
|
}
|