Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: allow starting lists with arbitrary number

Abdullah Atta49e7bdf20263
diff --git a/packages/editor/src/extensions/bullet-list/bullet-list.ts b/packages/editor/src/extensions/bullet-list/bullet-list.ts
index 588513830..9acf29dd2 100644
--- a/packages/editor/src/extensions/bullet-list/bullet-list.ts
+++ b/packages/editor/src/extensions/bullet-list/bullet-list.ts
@@ -22,6 +22,7 @@ import TiptapBulletList from "@tiptap/extension-bullet-list";
export const BulletList = TiptapBulletList.extend({
addAttributes() {
return {
+ ...this.parent?.(),
listType: {
default: null,
parseHTML: (element) => element.style.listStyleType,
diff --git a/packages/editor/src/extensions/ordered-list/ordered-list.ts b/packages/editor/src/extensions/ordered-list/ordered-list.ts
index eaf58bef6..19f4444e7 100644
--- a/packages/editor/src/extensions/ordered-list/ordered-list.ts
+++ b/packages/editor/src/extensions/ordered-list/ordered-list.ts
@@ -17,11 +17,14 @@ 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 { mergeAttributes, wrappingInputRule } from "@tiptap/core";
import TiptapOrderedList from "@tiptap/extension-ordered-list";
+const inputRegex = /^(\d+)\.\s$/;
export const OrderedList = TiptapOrderedList.extend({
addAttributes() {
return {
+ ...this.parent?.(),
listType: {
default: null,
parseHTML: (element) => element.style.listStyleType,
@@ -36,5 +39,44 @@ export const OrderedList = TiptapOrderedList.extend({
}
}
};
+ },
+
+ renderHTML({ HTMLAttributes }) {
+ const { start, ...attributesWithoutStart } = HTMLAttributes;
+ console.log("render!", HTMLAttributes);
+ return start === 1
+ ? [
+ "ol",
+ mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart),
+ 0
+ ]
+ : ["ol", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
+ },
+
+ addInputRules() {
+ const inputRule = wrappingInputRule({
+ find: inputRegex,
+ type: this.type,
+ getAttributes: (match) => ({ start: +match[1] }),
+ joinPredicate: (match, node) =>
+ node.childCount + node.attrs.start === +match[1]
+ });
+
+ // if (this.options.keepMarks || this.options.keepAttributes) {
+ // inputRule = wrappingInputRule({
+ // find: inputRegex,
+ // type: this.type,
+ // keepMarks: this.options.keepMarks,
+ // keepAttributes: this.options.keepAttributes,
+ // getAttributes: (match) => ({
+ // start: +match[1],
+ // ...this.editor.getAttributes(TextStyle.name)
+ // }),
+ // joinPredicate: (match, node) =>
+ // node.childCount + node.attrs.start === +match[1],
+ // editor: this.editor
+ // });
+ // }
+ return [inputRule];
}
});