mirror of https://github.com/usememos/memos
feat: update marked (#810)
parent
1838e616fd
commit
ab07c91d42
@ -1,18 +1,24 @@
|
||||
import { escape } from "lodash";
|
||||
|
||||
export const BLOCKQUOTE_REG = /^>\s+(.+)(\n?)/;
|
||||
export const BLOCKQUOTE_REG = /^> ([^\n]+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(BLOCKQUOTE_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = matcher(rawStr);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
return `<blockquote>${escape(matchResult[1])}</blockquote>${matchResult[2]}`;
|
||||
return `<blockquote>${escape(matchResult[1])}</blockquote>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "blockquote",
|
||||
regex: BLOCKQUOTE_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
export const BR_REG = /^(\n+)/;
|
||||
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(BR_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
return rawStr.replaceAll("\n", "<br>");
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "br",
|
||||
regex: BR_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
@ -1,20 +1,26 @@
|
||||
import { inlineElementParserList } from ".";
|
||||
import { marked } from "..";
|
||||
|
||||
export const DONE_LIST_REG = /^- \[[xX]\] (.+)(\n?)/;
|
||||
export const DONE_LIST_REG = /^- \[[xX]\] ([^\n]+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(DONE_LIST_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = matcher(rawStr);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], inlineElementParserList);
|
||||
return `<p class='li-container'><span class='todo-block done' data-value='DONE'>✓</span><span>${parsedContent}</span></p>${matchResult[2]}`;
|
||||
return `<p class='li-container'><span class='todo-block done' data-value='DONE'>✓</span><span>${parsedContent}</span></p>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "done list",
|
||||
regex: DONE_LIST_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
export const HORIZONTAL_RULES_REG = /^---\n|^\*\*\*\n|^___\n/;
|
||||
export const HORIZONTAL_RULES_REG = /^_{3}|^-{3}|^\*{3}/;
|
||||
|
||||
export const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(HORIZONTAL_RULES_REG);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
return `<hr>\n`;
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export const renderer = (rawStr: string): string => {
|
||||
return `<hr>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "horizontal rules",
|
||||
regex: HORIZONTAL_RULES_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -1,20 +1,26 @@
|
||||
import { inlineElementParserList } from ".";
|
||||
import { marked } from "..";
|
||||
|
||||
export const ORDERED_LIST_REG = /^(\d+)\. (.+)(\n?)/;
|
||||
export const ORDERED_LIST_REG = /^(\d+)\. (.+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(ORDERED_LIST_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = matcher(rawStr);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[2], [], inlineElementParserList);
|
||||
return `<p class='li-container'><span class='ol-block'>${matchResult[1]}.</span><span>${parsedContent}</span></p>${matchResult[3]}`;
|
||||
return `<p class='li-container'><span class='ol-block'>${matchResult[1]}.</span><span>${parsedContent}</span></p>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "ordered list",
|
||||
regex: ORDERED_LIST_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
import { inlineElementParserList } from ".";
|
||||
import { marked } from "..";
|
||||
|
||||
export const PARAGRAPH_REG = /^(.*)(\n?)/;
|
||||
export const PARAGRAPH_REG = /^([^\n]+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(PARAGRAPH_REG);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], inlineElementParserList);
|
||||
return `<p>${parsedContent}</p>${matchResult[2]}`;
|
||||
const renderer = (rawStr: string): string => {
|
||||
const parsedContent = marked(rawStr, [], inlineElementParserList);
|
||||
return `<p>${parsedContent}</p>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "paragraph",
|
||||
regex: PARAGRAPH_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -1,23 +1,26 @@
|
||||
import { escape } from "lodash-es";
|
||||
import { inlineElementParserList } from ".";
|
||||
import { marked } from "..";
|
||||
|
||||
export const TODO_LIST_REG = /^- \[ \] (.+)(\n?)/;
|
||||
export const TODO_LIST_REG = /^- \[ \] ([^\n]+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(TODO_LIST_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = matcher(rawStr);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], inlineElementParserList);
|
||||
return `<p class='li-container'><span class='todo-block todo' data-value='TODO'></span><span>${parsedContent}</span></p>${escape(
|
||||
matchResult[2]
|
||||
)}`;
|
||||
return `<p class='li-container'><span class='todo-block todo' data-value='TODO'></span><span>${parsedContent}</span></p>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "todo list",
|
||||
regex: TODO_LIST_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
@ -1,21 +1,26 @@
|
||||
import { escape } from "lodash-es";
|
||||
import { inlineElementParserList } from ".";
|
||||
import { marked } from "..";
|
||||
|
||||
export const UNORDERED_LIST_REG = /^[*-] (.+)(\n?)/;
|
||||
export const UNORDERED_LIST_REG = /^[*-] ([^\n]+)/;
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matcher = (rawStr: string) => {
|
||||
const matchResult = rawStr.match(UNORDERED_LIST_REG);
|
||||
return matchResult;
|
||||
};
|
||||
|
||||
const renderer = (rawStr: string): string => {
|
||||
const matchResult = matcher(rawStr);
|
||||
if (!matchResult) {
|
||||
return rawStr;
|
||||
}
|
||||
|
||||
const parsedContent = marked(matchResult[1], [], inlineElementParserList);
|
||||
return `<p class='li-container'><span class='ul-block'>•</span><span>${parsedContent}</span></p>${escape(matchResult[2])}`;
|
||||
return `<p class='li-container'><span class='ul-block'>•</span><span>${parsedContent}</span></p>`;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "unordered list",
|
||||
regex: UNORDERED_LIST_REG,
|
||||
matcher,
|
||||
renderer,
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue