Skip to content

Commit e9976d7

Browse files
committed
Add input rule for checkboxes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent b9f3e6d commit e9976d7

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/EditorFactory.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
Heading,
2626
Code,
2727
Link,
28-
BulletList,
2928
OrderedList,
3029
Blockquote,
3130
CodeBlock,
@@ -35,7 +34,7 @@ import {
3534
Placeholder,
3635
} from 'tiptap-extensions'
3736
import { Strong, Italic, Strike } from './marks'
38-
import { Image, PlainTextDocument, ListItem } from './nodes'
37+
import { Image, PlainTextDocument, ListItem, BulletList } from './nodes'
3938
import MarkdownIt from 'markdown-it'
4039
import taskLists from 'markdown-it-task-lists'
4140
import { translate as t } from '@nextcloud/l10n'

src/nodes/BulletList.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
3+
*
4+
* @author Julius Härtl <jus@bitgrid.net>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import { BulletList as TiptapBulletList } from 'tiptap-extensions'
24+
25+
export default class BulletList extends TiptapBulletList {
26+
27+
/* The bullet list input rules are handled in the ListItem node so we can make sure that "- [ ]" can still trigger todo list items */
28+
inputRules() {
29+
return []
30+
}
31+
32+
}

src/nodes/ListItem.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import { ListItem as TiptapListItem } from 'tiptap-extensions'
2424
import { Plugin } from 'tiptap'
25-
import { toggleList } from 'tiptap-commands'
25+
import { toggleList, wrappingInputRule } from 'tiptap-commands'
2626
import { findParentNode, findParentNodeClosestToPos } from 'prosemirror-utils'
2727

2828
const TYPES = {
@@ -139,6 +139,17 @@ export default class ListItem extends TiptapListItem {
139139
}
140140
}
141141

142+
inputRules({ type }) {
143+
return [
144+
wrappingInputRule(/^\s*([-+*])\s(\[ \])\s$/, type, (match) => {
145+
return {
146+
type: TYPES.CHECKBOX,
147+
}
148+
}),
149+
wrappingInputRule(/^\s*([-+*])\s[^\s[]$/, type),
150+
]
151+
}
152+
142153
get plugins() {
143154
return [
144155
new Plugin({

src/nodes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import Image from './Image'
2424
import PlainTextDocument from './PlainTextDocument'
2525
import ListItem from './ListItem'
26+
import BulletList from './BulletList'
2627

2728
export {
2829
Image,
2930
PlainTextDocument,
3031
ListItem,
32+
BulletList,
3133
}

0 commit comments

Comments
 (0)