Skip to content

Commit d045954

Browse files
authored
Merge pull request #6341 from nextcloud/backport/6323/stable29
[stable29] fix(TaskList): Add class name to rendered HTML
2 parents dd08a42 + e3f5f40 commit d045954

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

cypress/e2e/shortcuts.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('keyboard shortcuts', () => {
6262
it('codeblock', () => testShortcut(`${modKey}{alt}c`, 'pre'))
6363
it('ordered-list', () => testShortcut(`${modKey}{shift}7`, 'ol'))
6464
it('unordered-list', () => testShortcut(`${modKey}{shift}8`, 'ul'))
65-
it('task-list', () => testShortcut(`${modKey}{shift}9`, 'ul[data-type="taskList"]'))
65+
it('task-list', () => testShortcut(`${modKey}{shift}9`, 'ul.contains-task-list'))
6666

6767
// Headings
6868
const levels = [1, 2, 3, 4, 5, 6]

cypress/e2e/workspace.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Workspace', function() {
128128
;[
129129
['unordered-list', 'ul'],
130130
['ordered-list', 'ol'],
131-
['task-list', 'ul[data-type="taskList"]'],
131+
['task-list', 'ul.contains-task-list'],
132132
].forEach(([button, tag]) => testButton(button, tag, 'List me'))
133133
})
134134

src/nodes/TaskItem.js

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

6161
renderHTML({ node, HTMLAttributes }) {
62-
const listAttributes = { class: 'checkbox-item' }
62+
const listAttributes = { class: 'task-list-item checkbox-item' }
6363
const checkboxAttributes = { type: 'checkbox', class: '', contenteditable: false }
6464
if (node.attrs.checked) {
6565
checkboxAttributes.checked = true
@@ -87,7 +87,7 @@ const TaskItem = TipTapTaskItem.extend({
8787
state.renderContent(node)
8888
},
8989

90-
addInputRules() {
90+
addInputRules() {
9191
return [
9292
...this.parent(),
9393
wrappingInputRule({

src/nodes/TaskList.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import TiptapTaskList from '@tiptap/extension-task-list'
24+
import { mergeAttributes } from '@tiptap/core'
2425

2526
const TaskList = TiptapTaskList.extend({
2627

@@ -31,6 +32,10 @@ const TaskList = TiptapTaskList.extend({
3132
},
3233
],
3334

35+
renderHTML({ HTMLAttributes }) {
36+
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: 'contains-task-list' }), 0]
37+
},
38+
3439
addAttributes() {
3540
return {
3641
...this.parent?.(),

src/tests/tiptap.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ describe('TipTap', () => {
2020
const markdown = 'Hard line break \nNext Paragraph'
2121
expect(renderedHTML(markdown)).toEqual('<p>Hard line break<br>Next Paragraph</p>')
2222
})
23+
24+
it('render taskList', () => {
25+
const markdown = '* [ ] item 1\n'
26+
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>')
27+
})
2328
})

0 commit comments

Comments
 (0)