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: support pasting math Signed-off-by: 01zulfi <[email protected]>
01zulfi02960fb5a958
diff --git a/packages/editor/src/extensions/math/math-block.ts b/packages/editor/src/extensions/math/math-block.tsindex 903aa30e6..ce4e3573e 100644--- a/packages/editor/src/extensions/math/math-block.ts+++ b/packages/editor/src/extensions/math/math-block.ts@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { Node, mergeAttributes } from "@tiptap/core";+import { Node, mergeAttributes, nodePasteRule } from "@tiptap/core";import { insertMathNode } from "./plugin/index.js";import { NodeSelection } from "prosemirror-state";import { tiptapKeys } from "@notesnook/common";@@ -32,6 +32,8 @@ declare module "@tiptap/core" {// simple inputrule for block mathconst REGEX_BLOCK_MATH_DOLLARS = /\$\$\$\s+$/; //new RegExp("\$\$\s+$", "i");+const REGEX_PASTE_BLOCK_MATH_DOLLARS = /\$\$\$([\s\S]*?)\$\$\$/g;+export const MathBlock = Node.create({name: "mathBlock",group: "block math",@@ -99,5 +101,20 @@ export const MathBlock = Node.create({}}];+ },++ addPasteRules() {+ return [+ nodePasteRule({+ find: REGEX_PASTE_BLOCK_MATH_DOLLARS,+ type: this.type,+ getAttributes: (match) => {+ return { content: match[1] };+ },+ getContent: (attrs) => {+ return attrs.content ? [{ type: "text", text: attrs.content }] : [];+ }+ })+ ];}});diff --git a/packages/editor/src/extensions/math/math-inline.ts b/packages/editor/src/extensions/math/math-inline.tsindex 00314b414..cf2187dd5 100644--- a/packages/editor/src/extensions/math/math-inline.ts+++ b/packages/editor/src/extensions/math/math-inline.ts@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { Node, mergeAttributes } from "@tiptap/core";+import { Node, mergeAttributes, nodePasteRule } from "@tiptap/core";import { mathPlugin } from "./plugin/index.js";declare module "@tiptap/core" {@@ -40,6 +40,7 @@ const REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/; //new RegExp("\$(.+)\$", "i");// return REGEX_INLINE_MATH_DOLLARS;// }// })();+const REGEX_PASTE_INLINE_MATH_DOLLARS = /\$\$([\s\S]*?)\$\$/g;export const MathInline = Node.create({name: "mathInline",@@ -107,5 +108,20 @@ export const MathInline = Node.create({}}];+ },++ addPasteRules() {+ return [+ nodePasteRule({+ find: REGEX_PASTE_INLINE_MATH_DOLLARS,+ type: this.type,+ getAttributes: (match) => {+ return { content: match[1] };+ },+ getContent: (attrs) => {+ return attrs.content ? [{ type: "text", text: attrs.content }] : [];+ }+ })+ ];}});