feat: add Strikethrough syntax (#557)

feat: add `Strikethrough` rule
This commit is contained in:
boojack
2022-11-24 20:05:51 +08:00
committed by GitHub
parent 50d41c456b
commit abcd3cfafb
3 changed files with 22 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
import { inlineElementParserList } from ".";
import { marked } from "..";
export const DONE_LIST_REG = /^- \[x\] (.+)(\n?)/;
export const DONE_LIST_REG = /^- \[[xX]\] (.+)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(DONE_LIST_REG);

View File

@@ -0,0 +1,19 @@
import { marked } from "..";
export const STRIKETHROUGH_REG = /~~(.+?)~~/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(STRIKETHROUGH_REG);
if (!matchResult) {
return rawStr;
}
const parsedContent = marked(matchResult[1], [], []);
return `<del>${parsedContent}</del>`;
};
export default {
name: "Strikethrough",
regex: STRIKETHROUGH_REG,
renderer,
};

View File

@@ -16,6 +16,7 @@ import Table from "./Table";
import BoldEmphasis from "./BoldEmphasis";
import Blockquote from "./Blockquote";
import HorizontalRules from "./HorizontalRules";
import Strikethrough from "./Strikethrough";
export { CODE_BLOCK_REG } from "./CodeBlock";
export { TODO_LIST_REG } from "./TodoList";
@@ -38,5 +39,5 @@ export const blockElementParserList = [
UnorderedList,
Paragraph,
];
export const inlineElementParserList = [Image, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Tag, PlainText];
export const inlineElementParserList = [Image, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Strikethrough, Tag, PlainText];
export const parserList = [...blockElementParserList, ...inlineElementParserList];