mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: inline code within link (#321)
* feat: inline code with link * fix: decoration style
This commit is contained in:
@ -26,7 +26,7 @@ export const marked = (markdownStr: string, blockParsers = blockElementParserLis
|
|||||||
let matchedInlineParser = undefined;
|
let matchedInlineParser = undefined;
|
||||||
let matchedIndex = -1;
|
let matchedIndex = -1;
|
||||||
|
|
||||||
for (const parser of inlineElementParserList) {
|
for (const parser of inlineParsers) {
|
||||||
if (parser.name === "plain text" && matchedInlineParser !== undefined) {
|
if (parser.name === "plain text" && matchedInlineParser !== undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,18 @@ console.log("hello world!")
|
|||||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
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", () => {
|
test("parse plain link", () => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { escape } from "lodash-es";
|
import { escape } from "lodash-es";
|
||||||
|
import Emphasis from "./Emphasis";
|
||||||
|
import Bold from "./Bold";
|
||||||
|
import { marked } from "..";
|
||||||
|
import InlineCode from "./InlineCode";
|
||||||
|
|
||||||
export const LINK_REG = /\[(.*?)\]\((.+?)\)/;
|
export const LINK_REG = /\[(.*?)\]\((.+?)\)/;
|
||||||
|
|
||||||
@ -7,8 +11,8 @@ const renderer = (rawStr: string): string => {
|
|||||||
if (!matchResult) {
|
if (!matchResult) {
|
||||||
return rawStr;
|
return rawStr;
|
||||||
}
|
}
|
||||||
|
const parsedContent = marked(matchResult[1], [], [InlineCode, Emphasis, Bold]);
|
||||||
return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${escape(matchResult[1])}</a>`;
|
return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -31,7 +31,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.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,
|
.ol-block,
|
||||||
|
Reference in New Issue
Block a user