mirror of
https://github.com/usememos/memos.git
synced 2025-02-21 21:57:47 +01:00
chore: update marked (#325)
This commit is contained in:
parent
0b2a9d8511
commit
0b34b142c8
@ -123,14 +123,6 @@ console.log("hello world!")
|
||||
markdown: `Important: ***Minecraft/123***`,
|
||||
want: `<p>Important: <strong><em>Minecraft/123</em></strong></p>`,
|
||||
},
|
||||
{
|
||||
markdown: `Important: **Minecraft*123***`,
|
||||
want: `<p>Important: <strong>Minecraft<em>123</em></strong></p>`,
|
||||
},
|
||||
{
|
||||
markdown: `Important: **Minecraft*123*456**`,
|
||||
want: `<p>Important: <strong>Minecraft<em>123</em>456</strong></p>`,
|
||||
},
|
||||
{
|
||||
markdown: `Important: ***[baidu](https://baidu.com)***`,
|
||||
want: `<p>Important: <strong><em><a class='link' target='_blank' rel='noreferrer' href='https://baidu.com'>baidu</a></em></strong></p>`,
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { marked } from "..";
|
||||
import Emphasis from "./Emphasis";
|
||||
import Link from "./Link";
|
||||
|
||||
export const BOLD_REG = /\*\*([\S *]+)\*\*/;
|
||||
export const BOLD_REG = /\*\*([\S ]+?)\*\*/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = rawStr.match(BOLD_REG);
|
||||
@ -10,7 +9,7 @@ const renderer = (rawStr: string): string => {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], [Emphasis, Link]);
|
||||
const parsedContent = marked(matchResult[1], [], [Link]);
|
||||
return `<strong>${parsedContent}</strong>`;
|
||||
};
|
||||
|
||||
|
20
web/src/labs/marked/parser/BoldEmphasis.ts
Normal file
20
web/src/labs/marked/parser/BoldEmphasis.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { marked } from "..";
|
||||
import Link from "./Link";
|
||||
|
||||
export const BOLD_EMPHASIS_REG = /\*\*\*([\S ]+?)\*\*\*/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = rawStr.match(BOLD_EMPHASIS_REG);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], [Link]);
|
||||
return `<strong><em>${parsedContent}</em></strong>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "bold emphasis",
|
||||
regex: BOLD_EMPHASIS_REG,
|
||||
renderer,
|
||||
};
|
@ -1,5 +1,4 @@
|
||||
import { marked } from "..";
|
||||
import Bold from "./Bold";
|
||||
import Link from "./Link";
|
||||
|
||||
export const EMPHASIS_REG = /\*([\S ]+?)\*/;
|
||||
@ -10,7 +9,7 @@ const renderer = (rawStr: string): string => {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], [Bold, Link]);
|
||||
const parsedContent = marked(matchResult[1], [], [Link]);
|
||||
return `<em>${parsedContent}</em>`;
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@ import Emphasis from "./Emphasis";
|
||||
import Bold from "./Bold";
|
||||
import { marked } from "..";
|
||||
import InlineCode from "./InlineCode";
|
||||
import BoldEmphasis from "./BoldEmphasis";
|
||||
|
||||
export const LINK_REG = /\[(.*?)\]\((.+?)\)/;
|
||||
|
||||
@ -11,7 +12,7 @@ const renderer = (rawStr: string): string => {
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
const parsedContent = marked(matchResult[1], [], [InlineCode, Emphasis, Bold]);
|
||||
const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold]);
|
||||
return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@ import PlainLink from "./PlainLink";
|
||||
import InlineCode from "./InlineCode";
|
||||
import PlainText from "./PlainText";
|
||||
import Table from "./Table";
|
||||
import BoldEmphasis from "./BoldEmphasis";
|
||||
|
||||
export { CODE_BLOCK_REG } from "./CodeBlock";
|
||||
export { TODO_LIST_REG } from "./TodoList";
|
||||
@ -26,5 +27,5 @@ export { TABLE_REG } from "./Table";
|
||||
|
||||
// The order determines the order of execution.
|
||||
export const blockElementParserList = [Table, CodeBlock, TodoList, DoneList, OrderedList, UnorderedList, Paragraph];
|
||||
export const inlineElementParserList = [Image, Mark, Bold, Emphasis, Link, InlineCode, PlainLink, Tag, PlainText];
|
||||
export const inlineElementParserList = [Image, Mark, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Tag, PlainText];
|
||||
export const parserList = [...blockElementParserList, ...inlineElementParserList];
|
||||
|
Loading…
x
Reference in New Issue
Block a user