Skip to content

Commit

Permalink
fix(TaskList): Add class name to rendered HTML
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mejo- committed Sep 6, 2024
1 parent 5d5f5dd commit d000c8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nodes/TaskItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const TaskItem = TipTapTaskItem.extend({
],

renderHTML({ node, HTMLAttributes }) {
const listAttributes = { class: 'checkbox-item' }
const listAttributes = { class: 'task-list-item checkbox-item' }
const checkboxAttributes = { type: 'checkbox', class: '', contenteditable: false }
if (node.attrs.checked) {
checkboxAttributes.checked = true
Expand Down Expand Up @@ -70,7 +70,7 @@ const TaskItem = TipTapTaskItem.extend({
state.renderContent(node)
},

addInputRules() {
addInputRules() {
return [
...this.parent(),
wrappingInputRule({
Expand Down
5 changes: 5 additions & 0 deletions src/nodes/TaskList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import TiptapTaskList from '@tiptap/extension-task-list'
import { mergeAttributes } from '@tiptap/core'

const TaskList = TiptapTaskList.extend({

Expand All @@ -14,6 +15,10 @@ const TaskList = TiptapTaskList.extend({
},
],

renderHTML({ HTMLAttributes }) {
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: 'contains-task-list' }), 0]
},

addAttributes() {
return {
...this.parent?.(),
Expand Down
5 changes: 5 additions & 0 deletions src/tests/tiptap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ describe('TipTap', () => {
const markdown = 'Hard line break \nNext Paragraph'
expect(renderedHTML(markdown)).toEqual('<p>Hard line break<br>Next Paragraph</p>')
})

it('render taskList', () => {
const markdown = '* [ ] item 1\n'
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>')
})
})

0 comments on commit d000c8f

Please sign in to comment.