feat: add `Strikethrough` syntax (#557)

feat: add `Strikethrough` rule
pull/558/head
boojack 2 years ago committed by GitHub
parent 50d41c456b
commit abcd3cfafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);

@ -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,
};

@ -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];

Loading…
Cancel
Save