diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-06-12 22:27:08 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-12-22 17:42:24 +0300 |
commit | a848b7abb214b55f303360195c9ae3246eaaa7cc (patch) | |
tree | 6f42b30faf2f0a378dd9b39cbdd2e1da040423c2 | |
parent | b92ea121a478cf7264d75084add5de1aa1584285 (diff) |
Add input rule for checkboxes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | src/EditorFactory.js | 3 | ||||
-rw-r--r-- | src/nodes/BulletList.js | 32 | ||||
-rw-r--r-- | src/nodes/ListItem.js | 19 | ||||
-rw-r--r-- | src/nodes/index.js | 2 |
4 files changed, 53 insertions, 3 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index ff87f087e..e69e4b7e3 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 000000000..f8bacc367 --- /dev/null +++ b/src/nodes/BulletList.js @@ -0,0 +1,32 @@ +/* + * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +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 bf017f186..2e31b06c6 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 c24428ee7..a8ad44d30 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, } |