A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: add support for link markdown syntax (#2576)
Muhammad Alic2351ab2d3be
diff --git a/packages/editor/src/extensions/link/index.ts b/packages/editor/src/extensions/link/index.tsnew file mode 100644index 000000000..f63fec1d8--- /dev/null+++ b/packages/editor/src/extensions/link/index.ts@@ -0,0 +1,23 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/+import { Link } from "./link";++export * from "./link";++export default Link;diff --git a/packages/editor/src/extensions/link/link.ts b/packages/editor/src/extensions/link/link.tsnew file mode 100644index 000000000..49db86316--- /dev/null+++ b/packages/editor/src/extensions/link/link.ts@@ -0,0 +1,37 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/+import { markInputRule } from "@tiptap/core";+import TiptapLink from "@tiptap/extension-link";++const linkRegex = /(?:__|[*#])|\[(.*?)\]\(.*?\)/gm;+const regExp = /\((.*?)\)/;++export const Link = TiptapLink.extend({+ addInputRules() {+ return [+ markInputRule({+ find: linkRegex,+ type: this.type,+ getAttributes: (match) => ({+ href: regExp.exec(match[0])?.[1]+ })+ })+ ];+ }+});diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex 588b936ff..bf7283d17 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -27,7 +27,7 @@ import CharacterCount from "@tiptap/extension-character-count";import { Code } from "@tiptap/extension-code";import Color from "@tiptap/extension-color";import HorizontalRule from "@tiptap/extension-horizontal-rule";-import { Link } from "@tiptap/extension-link";+import { Link } from "./extensions/link";import Placeholder from "@tiptap/extension-placeholder";import Subscript from "@tiptap/extension-subscript";import Superscript from "@tiptap/extension-superscript";