mirror of
https://github.com/usememos/memos.git
synced 2025-10-27 14:56:30 +08:00
28 lines
719 B
TypeScript
28 lines
719 B
TypeScript
import Emphasis from "./Emphasis";
|
|
import Bold from "./Bold";
|
|
import { marked } from "..";
|
|
import InlineCode from "./InlineCode";
|
|
import BoldEmphasis from "./BoldEmphasis";
|
|
import PlainText from "./PlainText";
|
|
import { matcher } from "../matcher";
|
|
|
|
export const LINK_REG = /\[(.*?)\]\((.+?)\)$/;
|
|
|
|
const renderer = (rawStr: string) => {
|
|
const matchResult = matcher(rawStr, LINK_REG);
|
|
if (!matchResult) {
|
|
return rawStr;
|
|
}
|
|
const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold, PlainText]);
|
|
return (
|
|
<a className="link" target="_blank" href={matchResult[2]}>
|
|
{parsedContent}
|
|
</a>
|
|
);
|
|
};
|
|
|
|
export default {
|
|
name: "link",
|
|
regexp: LINK_REG,
|
|
renderer,
|
|
};
|