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: refactor diff highlighter extension
Abdullah Attacc0be4565db3
diff --git a/packages/editor/src/extensions/diff-highlighter/diff-highlighter.ts b/packages/editor/src/extensions/diff-highlighter/diff-highlighter.tsnew file mode 100644index 000000000..a3953921f--- /dev/null+++ b/packages/editor/src/extensions/diff-highlighter/diff-highlighter.ts@@ -0,0 +1,70 @@+/*+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 DiffHighlighter = Mark.create({+ name: "diffHighlighter",++ addAttributes() {+ return {+ class: {+ rendered: true,+ keepOnSplit: false+ },+ type: {+ rendered: false+ }+ };+ },++ parseHTML() {+ return [+ {+ tag: "ins.diffins",+ attrs: { class: "diffins", type: "ins" }+ },+ {+ tag: "ins.diffmod",+ attrs: { class: "diffmod", type: "ins" }+ },+ {+ tag: "ins.mod",+ attrs: { class: "mod", type: "ins" }+ },+ {+ tag: "del.diffdel",+ attrs: { class: "diffdel", type: "del" }+ },+ {+ tag: "del.diffmod",+ attrs: { class: "diffmod", type: "del" }+ }+ ];+ },++ renderHTML({ HTMLAttributes, mark }) {+ return [+ `${mark.attrs.type}`,+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: mark.attrs.class+ }),+ 0+ ];+ }+});diff --git a/packages/editor/src/extensions/highlight-diff/index.ts b/packages/editor/src/extensions/diff-highlighter/index.tssimilarity index 86%rename from packages/editor/src/extensions/highlight-diff/index.tsrename to packages/editor/src/extensions/diff-highlighter/index.tsindex 4fc9bc6b2..eb0a576e7 100644--- a/packages/editor/src/extensions/highlight-diff/index.ts+++ b/packages/editor/src/extensions/diff-highlighter/index.ts@@ -17,8 +17,4 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { HighlightDiff } from "./highlight-diff";--export * from "./highlight-diff";--export default HighlightDiff;+export * from "./diff-highlighter";diff --git a/packages/editor/src/extensions/highlight-diff/highlight-diff.ts b/packages/editor/src/extensions/highlight-diff/highlight-diff.tsdeleted file mode 100644index f570f80c9..000000000--- a/packages/editor/src/extensions/highlight-diff/highlight-diff.ts+++ /dev/null@@ -1,122 +0,0 @@-/*-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/index.ts b/packages/editor/src/index.tsindex 7938298d8..7b463d5a2 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -84,7 +84,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";+import { DiffHighlighter } from "./extensions/diff-highlighter";interface TiptapStorage {portalProviderAPI?: PortalProviderAPI;@@ -212,11 +212,7 @@ const useTiptap = (];}}),- HighlightDiff.Insert,- HighlightDiff.Mod,- HighlightDiff.DiffMod,- HighlightDiff.Del,- HighlightDiff.DelMod,+ DiffHighlighter,Paragraph.configure({doubleSpaced: doubleSpacedLines}),diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.cssindex 15e537733..ff9a12844 100644--- a/packages/editor/styles/styles.css+++ b/packages/editor/styles/styles.css@@ -782,9 +782,14 @@ ins.diffmod,ins.mod,ins.diffins {background-color: rgba(46, 160, 67, 0.4);+ text-decoration: none;}del.diffmod,del.diffdel {background-color: rgba(248, 81, 73, 0.4);+}++del.diffdel {+ text-decoration: none;}\ No newline at end of file