Escape markdown sequences (#2208)
* escape inline markdown character * fix typo * improve document around custom markdown plugin and add escape sequence utils * recover inline escape sequences on edit * remove escape sequences from plain text body * use `s` for strike-through instead of del * escape block markdown sequences * fix remove escape sequence was not removing all slashes from plain text * recover block sequences on edit
This commit is contained in:
25
src/app/plugins/markdown/block/runner.ts
Normal file
25
src/app/plugins/markdown/block/runner.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { replaceMatch } from '../internal';
|
||||
import { BlockMDParser, BlockMDRule } from './type';
|
||||
|
||||
/**
|
||||
* Parses block-level markdown text into HTML using defined block rules.
|
||||
*
|
||||
* @param text - The text to parse.
|
||||
* @param rule - The markdown rule to run.
|
||||
* @param parse - A function that run the parser on remaining parts..
|
||||
* @param parseInline - Optional function to parse inline elements.
|
||||
* @returns The text with the markdown rule applied or `undefined` if no match is found.
|
||||
*/
|
||||
export const runBlockRule = (
|
||||
text: string,
|
||||
rule: BlockMDRule,
|
||||
parse: BlockMDParser,
|
||||
parseInline?: (txt: string) => string
|
||||
): string | undefined => {
|
||||
const matchResult = rule.match(text);
|
||||
if (matchResult) {
|
||||
const content = rule.html(matchResult, parseInline);
|
||||
return replaceMatch(text, matchResult, content, (txt) => [parse(txt, parseInline)]).join('');
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
Reference in New Issue
Block a user