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.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: inline code within link (#321)
winwin2011180ae206c70b
diff --git a/web/src/labs/marked/index.ts b/web/src/labs/marked/index.tsindex c7580be89..24473a96c 100644--- a/web/src/labs/marked/index.ts+++ b/web/src/labs/marked/index.ts@@ -26,7 +26,7 @@ export const marked = (markdownStr: string, blockParsers = blockElementParserLislet matchedInlineParser = undefined;let matchedIndex = -1;- for (const parser of inlineElementParserList) {+ for (const parser of inlineParsers) {if (parser.name === "plain text" && matchedInlineParser !== undefined) {continue;}diff --git a/web/src/labs/marked/marked.test.ts b/web/src/labs/marked/marked.test.tsindex 1dd0fda57..031403229 100644--- a/web/src/labs/marked/marked.test.ts+++ b/web/src/labs/marked/marked.test.ts@@ -73,6 +73,18 @@ console.log("hello world!")expect(unescape(marked(t.markdown))).toBe(t.want);}});+ test("parse inline code within inline element", () => {+ const tests = [+ {+ markdown: `Link: [\`baidu\`](https://baidu.com)`,+ want: `<p>Link: <a class='link' target='_blank' rel='noreferrer' href='https://baidu.com'><code>baidu</code></a></p>`,+ },+ ];++ for (const t of tests) {+ expect(unescape(marked(t.markdown))).toBe(t.want);+ }+ });test("parse plain link", () => {const tests = [{diff --git a/web/src/labs/marked/parser/Link.ts b/web/src/labs/marked/parser/Link.tsindex 8ebd6aa59..52d58e8bb 100644--- a/web/src/labs/marked/parser/Link.ts+++ b/web/src/labs/marked/parser/Link.ts@@ -1,4 +1,8 @@import { escape } from "lodash-es";+import Emphasis from "./Emphasis";+import Bold from "./Bold";+import { marked } from "..";+import InlineCode from "./InlineCode";export const LINK_REG = /\[(.*?)\]\((.+?)\)/;@@ -7,8 +11,8 @@ const renderer = (rawStr: string): string => {if (!matchResult) {return rawStr;}-- return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${escape(matchResult[1])}</a>`;+ const parsedContent = marked(matchResult[1], [], [InlineCode, Emphasis, Bold]);+ return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;};export default {diff --git a/web/src/less/memo-content.less b/web/src/less/memo-content.lessindex bfe9211f0..3d85f0637 100644--- a/web/src/less/memo-content.less+++ b/web/src/less/memo-content.less@@ -31,7 +31,10 @@}.link {- @apply text-blue-600 cursor-pointer underline break-all hover:opacity-80;+ @apply text-blue-600 cursor-pointer underline break-all hover:opacity-80 decoration-1;+ code {+ @apply underline decoration-1;+ }}.ol-block,