💄 Optimize file previewer

This commit is contained in:
2025-11-06 19:48:45 +08:00
parent ae1ba62d1a
commit cd7894ec87
4 changed files with 160 additions and 29 deletions

View File

@@ -9,13 +9,46 @@ export function useMarkdownProcessor() {
html: true,
linkify: true,
typographer: true
// @ts-ignore
// @ts-ignore
}).use(texmath, {
engine: katex,
delimiters: 'dollars',
delimiters: "dollars",
katexOptions: { macros: { "\\RR": "\\mathbb{R}" } }
})
const defaultParagraphRenderer =
processor.renderer.rules.paragraph_open ||
((tokens, idx, options, env, self) =>
self.renderToken(tokens, idx, options))
processor.renderer.rules.paragraph_open = function (
tokens,
idx,
options,
env,
self
) {
let result = ""
if (idx > 1) {
const inline = tokens[idx - 2]
const paragraph = tokens[idx]
if (
inline &&
inline.type === "inline" &&
inline.map &&
inline.map[1] &&
paragraph &&
paragraph.map &&
paragraph.map[0]
) {
const diff = paragraph.map[0] - inline.map[1]
if (diff > 0) {
result = "<br>".repeat(diff)
}
}
}
return result + defaultParagraphRenderer(tokens, idx, options, env, self)
}
return {
render: (content: string) => processor.render(content)
}