Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix(TaskList): Add class name to rendered HTML #6341

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/e2e/shortcuts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('keyboard shortcuts', () => {
it('codeblock', () => testShortcut(`${modKey}{alt}c`, 'pre'))
it('ordered-list', () => testShortcut(`${modKey}{shift}7`, 'ol'))
it('unordered-list', () => testShortcut(`${modKey}{shift}8`, 'ul'))
it('task-list', () => testShortcut(`${modKey}{shift}9`, 'ul[data-type="taskList"]'))
it('task-list', () => testShortcut(`${modKey}{shift}9`, 'ul.contains-task-list'))

// Headings
const levels = [1, 2, 3, 4, 5, 6]
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Workspace', function() {
;[
['unordered-list', 'ul'],
['ordered-list', 'ol'],
['task-list', 'ul[data-type="taskList"]'],
['task-list', 'ul.contains-task-list'],
].forEach(([button, tag]) => testButton(button, tag, 'List me'))
})

Expand Down
4 changes: 2 additions & 2 deletions src/nodes/TaskItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 @@ -87,7 +87,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 @@ -21,6 +21,7 @@
*/

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

const TaskList = TiptapTaskList.extend({

Expand All @@ -31,6 +32,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 @@ -20,4 +20,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>')
})
})
Loading