From 1ea74dfd0d3b62bd4e26754fcd87723b841244d2 Mon Sep 17 00:00:00 2001 From: boojack Date: Sun, 4 Dec 2022 10:52:11 +0800 Subject: [PATCH] chore: remove table syntax (#669) --- web/src/labs/marked/marked.test.ts | 37 ------------------------ web/src/labs/marked/parser/Table.ts | 45 ----------------------------- web/src/labs/marked/parser/index.ts | 14 +-------- 3 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 web/src/labs/marked/parser/Table.ts diff --git a/web/src/labs/marked/marked.test.ts b/web/src/labs/marked/marked.test.ts index 04414fea..fb9f5e5a 100644 --- a/web/src/labs/marked/marked.test.ts +++ b/web/src/labs/marked/marked.test.ts @@ -157,43 +157,6 @@ console.log("hello world!") expect(unescape(marked(t.markdown))).toBe(t.want); } }); - test("parse table", () => { - const tests = [ - { - markdown: `text above the table -| a | b | c | -|---|---|---| -| 1 | 2 | 3 | -| 4 | 5 | 6 | -text below the table -`, - want: `

text above the table

- - - - - - - - - -
abc
123
456
-

text below the table

-`, - }, - { - markdown: `| a | b | c | -| 1 | 2 | 3 | -| 4 | 5 | 6 |`, - want: `

| a | b | c |

-

| 1 | 2 | 3 |

-

| 4 | 5 | 6 |

`, - }, - ]; - for (const t of tests) { - expect(unescape(marked(t.markdown))).toBe(t.want); - } - }); test("parse full width space", () => { const tests = [ { diff --git a/web/src/labs/marked/parser/Table.ts b/web/src/labs/marked/parser/Table.ts deleted file mode 100644 index e267a3cd..00000000 --- a/web/src/labs/marked/parser/Table.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Match markdown table - * example: - * | a | b | c | - * |---|---|---| - * | 1 | 2 | 3 | - * | 4 | 5 | 6 | - */ -export const TABLE_REG = /^(\|.*\|)(?:(?:\n(?:\|-*)+\|))((?:\n\|.*\|)+)(\n?)/; - -const renderer = (rawStr: string): string => { - const matchResult = rawStr.match(TABLE_REG); - if (!matchResult) { - return rawStr; - } - const tableHeader = matchResult[1] - .split("|") - .filter((str) => str !== "") - .map((str) => str.trim()); - const tableBody = matchResult[2] - .trim() - .split("\n") - .map((str) => - str - .split("|") - .filter((str) => str !== "") - .map((str) => str.trim()) - ); - return ` - - - ${tableHeader.map((str) => ``).join("")} - - - - ${tableBody.map((row) => `${row.map((str) => ``).join("")}`).join("")} - -
${str}
${str}
${matchResult[3]}`; -}; - -export default { - name: "table", - regex: TABLE_REG, - renderer, -}; diff --git a/web/src/labs/marked/parser/index.ts b/web/src/labs/marked/parser/index.ts index 89434adf..fcf28d82 100644 --- a/web/src/labs/marked/parser/index.ts +++ b/web/src/labs/marked/parser/index.ts @@ -12,7 +12,6 @@ import Emphasis from "./Emphasis"; import PlainLink from "./PlainLink"; import InlineCode from "./InlineCode"; import PlainText from "./PlainText"; -import Table from "./Table"; import BoldEmphasis from "./BoldEmphasis"; import Blockquote from "./Blockquote"; import HorizontalRules from "./HorizontalRules"; @@ -24,20 +23,9 @@ export { DONE_LIST_REG } from "./DoneList"; export { TAG_REG } from "./Tag"; export { IMAGE_REG } from "./Image"; export { LINK_REG } from "./Link"; -export { TABLE_REG } from "./Table"; export { HORIZONTAL_RULES_REG } from "./HorizontalRules"; // The order determines the order of execution. -export const blockElementParserList = [ - HorizontalRules, - Table, - CodeBlock, - Blockquote, - TodoList, - DoneList, - OrderedList, - UnorderedList, - Paragraph, -]; +export const blockElementParserList = [HorizontalRules, CodeBlock, Blockquote, TodoList, DoneList, OrderedList, UnorderedList, Paragraph]; export const inlineElementParserList = [Image, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Strikethrough, Tag, PlainText]; export const parserList = [...blockElementParserList, ...inlineElementParserList];