outline / rich-markdown-editor

The open source React and Prosemirror based markdown editor that powers Outline. Want to try it out? Create an account:
https://www.getoutline.com
BSD 3-Clause "New" or "Revised" License
2.87k stars 588 forks source link

Allow # in markdown links #515

Closed asiyani closed 3 years ago

asiyani commented 3 years ago

Hi! 👋

In markdown we can reference other sections(heading) from same page using anchor #. so if url returned from onSearchLink starts with # it should be allowed without adding https://.

using full URL is not always possible, we should be able to use relative urls for reference.

Here is the diff that solved my problem:

diff --git a/node_modules/rich-markdown-editor/dist/components/LinkEditor.js b/node_modules/rich-markdown-editor/dist/components/LinkEditor.js
index 9848f2f..af59daa 100644
--- a/node_modules/rich-markdown-editor/dist/components/LinkEditor.js
+++ b/node_modules/rich-markdown-editor/dist/components/LinkEditor.js
@@ -62,7 +62,7 @@ class LinkEditor extends React.Component {
                 return;
             this.discardInputValue = true;
             const { from, to } = this.props;
-            if (!isUrl_1.default(href) && !href.startsWith("/")) {
+            if (!isUrl_1.default(href) && !href.startsWith("/") && !href.startsWith("#")) {
                 href = `https://${href}`;
             }
             this.props.onSelectLink({ href, title, from, to });

This issue body was partially generated by patch-package.

tommoor commented 3 years ago

Seems reasonable!