Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: add `Strikethrough` syntax (#557)

boojackabcd3cfafb8a
diff --git a/web/src/labs/marked/parser/DoneList.ts b/web/src/labs/marked/parser/DoneList.ts
index e366f3ab6..e27434db3 100644
--- a/web/src/labs/marked/parser/DoneList.ts
+++ b/web/src/labs/marked/parser/DoneList.ts
@@ -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);
diff --git a/web/src/labs/marked/parser/Strikethrough.ts b/web/src/labs/marked/parser/Strikethrough.ts
new file mode 100644
index 000000000..db9b8e554
--- /dev/null
+++ b/web/src/labs/marked/parser/Strikethrough.ts
@@ -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,
+};
diff --git a/web/src/labs/marked/parser/index.ts b/web/src/labs/marked/parser/index.ts
index 80ff1e2d3..89434adf7 100644
--- a/web/src/labs/marked/parser/index.ts
+++ b/web/src/labs/marked/parser/index.ts
@@ -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];