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

58 lines
1.4 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/commnet.ts — 注释/评论扩展语法处理(拼写: commnet 文件名保留)。 */
import { Tokens, MarkedExtension } from "marked";
import { Extension } from "./extension";
const commentRegex = /^%%([\s\S]*?)%%/;
export class Comment extends Extension {
markedExtension(): MarkedExtension {
return {
extensions: [{
name: 'CommentInline',
level: 'inline',
start(src: string) {
let index;
let indexSrc = src;
while (indexSrc) {
index = indexSrc.indexOf('%%');
if (index === -1) return;
return index;
}
},
tokenizer(src: string) {
const match = src.match(commentRegex);
if (match) {
return {
type: 'CommentInline',
raw: match[0],
text: match[1],
};
}
},
renderer(token: Tokens.Generic) {
return '';
}
},
{
name: 'CommentBlock',
level: 'block',
tokenizer(src: string) {
const match = src.match(commentRegex);
if (match) {
return {
type: 'CommentBlock',
raw: match[0],
text: match[1],
};
}
},
renderer(token: Tokens.Generic) {
return '';
}
},
]
}
}
}