Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ui/src/components/nodes/Rich.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
DropCursorExtension,
ImageExtension,
ItalicExtension,
LinkExtension,
LinkExtension as RemirrorLinkExtension,
PlaceholderExtension,
ShortcutHandlerProps,
SubExtension,
Expand Down Expand Up @@ -95,6 +95,10 @@ import {
ToggleStrikeButton,
} from "@remirror/react";
import { FloatingToolbar, useExtensionEvent } from "@remirror/react";

import { InputRule } from "@remirror/pm";
import { markInputRule } from "@remirror/core-utils";

import { TableExtension } from "@remirror/extension-react-tables";
import { GenIcon, IconBase } from "@remirror/react-components";
import "remirror/styles/all.css";
Expand All @@ -108,6 +112,26 @@ import {
} from "./extensions/mathExtension";
import { NewPodButtons, level2fontsize } from "./utils";

class LinkExtension extends RemirrorLinkExtension {
createInputRules(): InputRule[] {
return [
markInputRule({
regexp: /\[([^\]]+)\]\(([^)]+)\)/,
type: this.type,
getAttributes: (matches: string[]) => {
const [_, text, href] = matches;
return { text: text, href: href };
},
}),
markInputRule({
regexp: /(?:==|__)([^*_]+)(?:==|__)$/,
type: this.type,
ignoreWhitespace: true,
}),
];
}
}

function useLinkShortcut() {
const [linkShortcut, setLinkShortcut] = useState<
ShortcutHandlerProps | undefined
Expand Down