diff --git a/src/EditorFactory.js b/src/EditorFactory.js index ff87f087e04..e69e4b7e360 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -24,7 +24,6 @@ import { HardBreak, Heading, Code, - BulletList, OrderedList, Blockquote, CodeBlock, @@ -34,7 +33,7 @@ import { Placeholder, } from 'tiptap-extensions' import { Strong, Italic, Strike, Link } from './marks' -import { Image, PlainTextDocument, ListItem } from './nodes' +import { Image, PlainTextDocument, ListItem, BulletList } from './nodes' import MarkdownIt from 'markdown-it' import taskLists from 'markdown-it-task-lists' import { translate as t } from '@nextcloud/l10n' diff --git a/src/nodes/BulletList.js b/src/nodes/BulletList.js new file mode 100644 index 00000000000..f8bacc36789 --- /dev/null +++ b/src/nodes/BulletList.js @@ -0,0 +1,32 @@ +/* + * @copyright Copyright (c) 2020 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { BulletList as TiptapBulletList } from 'tiptap-extensions' + +export default class BulletList extends TiptapBulletList { + + /* The bullet list input rules are handled in the ListItem node so we can make sure that "- [ ]" can still trigger todo list items */ + inputRules() { + return [] + } + +} diff --git a/src/nodes/ListItem.js b/src/nodes/ListItem.js index bf017f1865c..b06bb4e18e9 100644 --- a/src/nodes/ListItem.js +++ b/src/nodes/ListItem.js @@ -22,7 +22,7 @@ import { ListItem as TiptapListItem } from 'tiptap-extensions' import { Plugin } from 'tiptap' -import { toggleList } from 'tiptap-commands' +import { toggleList, wrappingInputRule } from 'tiptap-commands' import { findParentNode, findParentNodeClosestToPos } from 'prosemirror-utils' const TYPES = { @@ -139,6 +139,23 @@ export default class ListItem extends TiptapListItem { } } + inputRules({ type }) { + return [ + wrappingInputRule(/^\s*([-+*])\s(\[ \])\s$/, type, (match) => { + return { + type: TYPES.CHECKBOX, + } + }), + wrappingInputRule(/^\s*([-+*])\s(\[(x|X)\])\s$/, type, (match) => { + return { + type: TYPES.CHECKBOX, + done: true, + } + }), + wrappingInputRule(/^\s*([-+*])\s[^\s[]$/, type), + ] + } + get plugins() { return [ new Plugin({ diff --git a/src/nodes/index.js b/src/nodes/index.js index c24428ee794..a8ad44d30c3 100644 --- a/src/nodes/index.js +++ b/src/nodes/index.js @@ -23,9 +23,11 @@ import Image from './Image' import PlainTextDocument from './PlainTextDocument' import ListItem from './ListItem' +import BulletList from './BulletList' export { Image, PlainTextDocument, ListItem, + BulletList, }