Move editor stuff to its own module

This commit is contained in:
Jon Staab
2024-08-29 09:23:54 -07:00
parent 88318e9753
commit 719a8a3458
9 changed files with 231 additions and 172 deletions
+3 -2
View File
@@ -16,7 +16,7 @@ export interface LinkAttributes {
declare module "@tiptap/core" {
interface Commands<ReturnType> {
link: {
inlineLink: {
insertLink: (options: {url: string}) => ReturnType
}
}
@@ -24,7 +24,7 @@ declare module "@tiptap/core" {
export const LinkExtension = Node.create({
atom: true,
name: "link",
name: "inlineLink",
group: "inline",
inline: true,
selectable: true,
@@ -74,6 +74,7 @@ export const LinkExtension = Node.create({
const matches = []
for (const match of text.matchAll(LINK_REGEX)) {
console.log(text, match)
try {
matches.push(createPasteRuleMatch(match, {url: match[0]}))
} catch (e) {
+1 -1
View File
@@ -3,7 +3,7 @@ import type {Node as ProsemirrorNode} from "@tiptap/pm/model"
import type {MarkdownSerializerState} from "prosemirror-markdown"
import {createPasteRuleMatch} from "@lib/tiptap/util"
export const TOPIC_REGEX = /(#[^\s]+)/g
export const TOPIC_REGEX = /(?:^|\s)(#[^\s]+)/g
export interface TopicAttributes {
name: string
+6
View File
@@ -1,5 +1,11 @@
import type {JSONContent, PasteRuleMatch} from "@tiptap/core"
export const asInline = (extend: Record<string, any>) => ({
inline: true,
group: "inline",
...extend,
})
export const createPasteRuleMatch = <T extends Record<string, unknown>>(
match: RegExpMatchArray,
data: T,