feat: support markdown

This commit is contained in:
guanghechen 2024-07-10 16:17:23 +08:00
parent bd230ddd4f
commit 85d144a1e9
34 changed files with 2350 additions and 4 deletions

View file

@ -0,0 +1,20 @@
import { Paragraph, ParagraphType, Root, TextType } from "@yozora/ast";
import { GfmExParser as Parser } from "@yozora/parser-gfm-ex";
export const parser = new Parser({
defaultParseOptions: {
shouldReservePosition: false,
},
});
export const hasHighlightContent = (content: string): boolean => {
const data: Root = parser.parse(content);
if (data.children.length === 0) return false;
for (const node of data.children) {
if (node.type !== ParagraphType) return true;
const paragraph = node as Paragraph;
if (paragraph.children.some(v => v.type !== TextType)) return true;
}
return false;
};