Skip to content

Commit d000c8f

Browse files
committed
fix(TaskList): Add class name to rendered HTML
The upstream Tiptap tasklist implementation uses data-type attributes to identify task lists and task items. We use class names instead as we depend on the markdown-it-task-lists plugin. This fixes copy & paste of task lists. Fixes: #5237 Signed-off-by: Jonas <jonas@freesources.org>
1 parent 5d5f5dd commit d000c8f

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/nodes/TaskItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const TaskItem = TipTapTaskItem.extend({
4242
],
4343

4444
renderHTML({ node, HTMLAttributes }) {
45-
const listAttributes = { class: 'checkbox-item' }
45+
const listAttributes = { class: 'task-list-item checkbox-item' }
4646
const checkboxAttributes = { type: 'checkbox', class: '', contenteditable: false }
4747
if (node.attrs.checked) {
4848
checkboxAttributes.checked = true
@@ -70,7 +70,7 @@ const TaskItem = TipTapTaskItem.extend({
7070
state.renderContent(node)
7171
},
7272

73-
addInputRules() {
73+
addInputRules() {
7474
return [
7575
...this.parent(),
7676
wrappingInputRule({

src/nodes/TaskList.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import TiptapTaskList from '@tiptap/extension-task-list'
7+
import { mergeAttributes } from '@tiptap/core'
78

89
const TaskList = TiptapTaskList.extend({
910

@@ -14,6 +15,10 @@ const TaskList = TiptapTaskList.extend({
1415
},
1516
],
1617

18+
renderHTML({ HTMLAttributes }) {
19+
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: 'contains-task-list' }), 0]
20+
},
21+
1722
addAttributes() {
1823
return {
1924
...this.parent?.(),

src/tests/tiptap.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ describe('TipTap', () => {
2525
const markdown = 'Hard line break \nNext Paragraph'
2626
expect(renderedHTML(markdown)).toEqual('<p>Hard line break<br>Next Paragraph</p>')
2727
})
28+
29+
it('render taskList', () => {
30+
const markdown = '* [ ] item 1\n'
31+
expect(renderedHTML(markdown)).toEqual('<ul class="contains-task-list"><li data-checked="false" class="task-list-item checkbox-item"><input type="checkbox" class="" contenteditable="false"><label><p>item 1</p></label></li></ul>')
32+
})
2833
})

0 commit comments

Comments
 (0)