milkdown icon indicating copy to clipboard operation
milkdown copied to clipboard

[Bug] Invalid Regular Expression on Safari (iOS)

Open omarmir opened this issue 1 year ago • 0 comments

Initial checklist

Affected packages and versions

v7.6.3

Link to runnable example

No response

Steps to reproduce

mdast-util-gfm-autolink-literal package uses a lookbehind assertion which is not fully supported in Safari iOS. It causes the component to not render (the Milkdown Editor). This package is used by remark itself. I ended up tracing it through the package chains but I don't have it exactly. In any case, this is likely to cause a problem. @wenxue11 has a forked repo you can override for now: https://github.com/wenxue11/mdast-util-gfm-autolink-literal

I wanted to post it as an issue for anyone else looking to see a fix. I know its not something you can fix on this package (I suppose you can override too but that feels worse?) but it sems like a good idea to document the issue and present a solution.

How to override in pnpm (though maybe fork wenxue11's repo)

"pnpm": {
    "overrides": {
      "mdast-util-gfm-autolink-literal": "github:wenxue11/mdast-util-gfm-autolink-literal"
    }
  }

They have changed the regex for iOS compatability:

/** @type {FromMarkdownTransform} */
function transformGfmAutolinkLiterals(tree) {
  findAndReplace(
    tree,
    [
      [/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
      -[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]
      +[/(?:^|\s|[!"#$%&'()*+,\-./:;<=>?@[\\]^_`{|}~])([-.\\w+]+)@([-\w]+(?:\.[-\w]+)+)/gi, findEmail]
    ],
    {ignore: ['link', 'linkReference']}
  )
}

Expected behavior

For it to render the editor.

Actual behavior

Doesn't render the editor.

Runtime

Safari

OS

Other (please specify in steps to reproduce)

Build and bundle tools

Vite

omarmir avatar Feb 26 '25 05:02 omarmir