Skip to content

Commit

Permalink
fix(rich-text-link): More lenient regex for input/paste rule (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral committed Dec 19, 2022
1 parent c7434cf commit 98e363f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/extensions/rich-text/rich-text-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import type { LinkOptions } from '@tiptap/extension-link'
/**
* The input regex for Markdown links with title support, and multiple quotation marks (required
* in case the `Typography` extension is being included).
*
* @see https://stephenweiss.dev/regex-markdown-link
*/
const inputRegex = /(?:^|\s)\[([^\]]*)?\]\(([A-Za-z0-9:/.-?]+)(?: ["“](.+)["”])?\)$/
const inputRegex = /(?:^|\s)\[([^\]]*)?\]\((\S+)(?: ["“](.+)["”])?\)$/i

/**
* The paste regex for Markdown links with title support, and multiple quotation marks (required
* in case the `Typography` extension is being included).
*
* @see https://stephenweiss.dev/regex-markdown-link
*/
const pasteRegex = /(?:^|\s)\[([^\]]*)?\]\(([A-Za-z0-9:/.-?]+)(?: ["“](.+)["”])?\)/g
const pasteRegex = /(?:^|\s)\[([^\]]*)?\]\((\S+)(?: ["“](.+)["”])?\)/gi

/**
* Input rule built specifically for the `Link` extension, which ignores the auto-linked URL in
Expand All @@ -30,7 +26,7 @@ function linkInputRule(config: Parameters<typeof markInputRule>[0]) {

return new InputRule({
find: config.find,
handler: (props) => {
handler(props) {
const { tr } = props.state

defaultMarkInputRule.handler(props)
Expand All @@ -51,7 +47,7 @@ function linkPasteRule(config: Parameters<typeof markPasteRule>[0]) {

return new PasteRule({
find: config.find,
handler: (props) => {
handler(props) {
const { tr } = props.state

defaultMarkInputRule.handler(props)
Expand Down

0 comments on commit 98e363f

Please sign in to comment.