Files
note2any/src/markdown/embed-block-mark.ts
2025-10-08 09:18:20 +08:00

42 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 文件markdown/embed-block-mark.ts — 处理嵌入式块级标记语言扩展。 */
import { Tokens, MarkedExtension } from "marked";
import { Extension } from "./extension";
const BlockMarkRegex = /^\^[0-9A-Za-z-]+$/;
export class EmbedBlockMark extends Extension {
allLinks:string[] = [];
async prepare() {
this.allLinks = [];
}
markedExtension(): MarkedExtension {
return {
extensions: [{
name: 'EmbedBlockMark',
level: 'inline',
start(src: string) {
let index = src.indexOf('^');
if (index === -1) {
return;
}
return index;
},
tokenizer(src: string) {
const match = src.match(BlockMarkRegex);
if (match) {
return {
type: 'EmbedBlockMark',
raw: match[0],
text: match[0]
};
}
},
renderer: (token: Tokens.Generic) => {
return `<span data-txt="${token.text}"></span}`;
}
}]
}
}
}