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 highlight diff extension
Ammar Ahmedeca9f221ac0b
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsxindex 1a961377a..a2a1f5f4c 100644--- a/packages/editor-mobile/src/components/editor.tsx+++ b/packages/editor-mobile/src/components/editor.tsx@@ -134,7 +134,7 @@ const Tiptap = ({editorProps: {editable: () => !tab.readonly},- content: globalThis.editorControllers[tab.id]?.content?.current,+ content: "<p>hello world<ins class='diffins'>[diffed text]</ins></p>",isMobile: true,doubleSpacedLines: settings.doubleSpacedLines,openLink: (url) => {diff --git a/packages/editor/src/extensions/highlight-diff/highlight-diff.ts b/packages/editor/src/extensions/highlight-diff/highlight-diff.tsnew file mode 100644index 000000000..f570f80c9--- /dev/null+++ b/packages/editor/src/extensions/highlight-diff/highlight-diff.ts@@ -0,0 +1,122 @@+/*+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 { Mark, mergeAttributes } from "@tiptap/core";++export const HighlightDiff = {+ Insert: Mark.create({+ name: "Insert",+ parseHTML() {+ return [+ {+ tag: "ins.diffins"+ }+ ];+ },++ renderHTML({ HTMLAttributes }) {+ return [+ "ins",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "diffins"+ }),+ 0+ ];+ }+ }),+ DiffMod: Mark.create({+ name: "DiffMod",+ parseHTML() {+ return [+ {+ tag: "ins.diffmod"+ }+ ];+ },++ renderHTML({ HTMLAttributes }) {+ return [+ "ins",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "diffmod"+ }),+ 0+ ];+ }+ }),+ Mod: Mark.create({+ name: "Mod",+ parseHTML() {+ return [+ {+ tag: "ins.mod"+ }+ ];+ },++ renderHTML({ HTMLAttributes }) {+ return [+ "ins",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "mod"+ }),+ 0+ ];+ }+ }),+ Del: Mark.create({+ name: "Del",+ parseHTML() {+ return [+ {+ tag: "del.diffdel"+ }+ ];+ },++ renderHTML({ HTMLAttributes }) {+ return [+ "del",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "diffdel"+ }),+ 0+ ];+ }+ }),+ DelMod: Mark.create({+ name: "DelMod",+ parseHTML() {+ return [+ {+ tag: "del.diffmod"+ }+ ];+ },++ renderHTML({ HTMLAttributes }) {+ return [+ "del",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "del"+ }),+ 0+ ];+ }+ })+};diff --git a/packages/editor/src/extensions/highlight-diff/index.ts b/packages/editor/src/extensions/highlight-diff/index.tsnew file mode 100644index 000000000..4fc9bc6b2--- /dev/null+++ b/packages/editor/src/extensions/highlight-diff/index.ts@@ -0,0 +1,24 @@+/*+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 { HighlightDiff } from "./highlight-diff";++export * from "./highlight-diff";++export default HighlightDiff;diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex c35f4d30e..eb4e87d26 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -88,6 +88,7 @@ import CheckListItem from "./extensions/check-list-item";import { Callout } from "./extensions/callout";import BlockId from "./extensions/block-id";import { useEditorSearchStore } from "./toolbar/stores/search-store";+import HighlightDiff from "./extensions/highlight-diff";interface TiptapStorage {portalProviderAPI?: PortalProviderAPI;@@ -216,6 +217,11 @@ const useTiptap = (];}}),+ HighlightDiff.Insert,+ HighlightDiff.Mod,+ HighlightDiff.DiffMod,+ HighlightDiff.Del,+ HighlightDiff.DelMod,Paragraph.configure({doubleSpaced: doubleSpacedLines}),diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.cssindex 6b9ad157e..15e537733 100644--- a/packages/editor/styles/styles.css+++ b/packages/editor/styles/styles.css@@ -774,3 +774,17 @@ p > *::selection {.ProseMirror div.callout[data-callout-type="cite"] {--callout-color: 158, 158, 158;}+++/* Highlight Diff */++ins.diffmod,+ins.mod,+ins.diffins {+ background-color: rgba(46, 160, 67, 0.4);+}++del.diffmod,+del.diffdel {+ background-color: rgba(248, 81, 73, 0.4);+}\ No newline at end of file