mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix extra paragraph in task list
This commit is contained in:
@@ -44,7 +44,9 @@ function listParagraph(turndownService: _TurndownService) {
|
|||||||
|
|
||||||
function orderedListItem(turndownService: _TurndownService) {
|
function orderedListItem(turndownService: _TurndownService) {
|
||||||
turndownService.addRule('orderedListItem', {
|
turndownService.addRule('orderedListItem', {
|
||||||
filter: 'li',
|
filter: function (node: HTMLInputElement) {
|
||||||
|
return node.nodeName === 'LI' && node.getAttribute('data-type') !== 'taskItem';
|
||||||
|
},
|
||||||
replacement: (content: string, node: HTMLInputElement, options: any) => {
|
replacement: (content: string, node: HTMLInputElement, options: any) => {
|
||||||
const parent = node.parentNode as HTMLElement;
|
const parent = node.parentNode as HTMLElement;
|
||||||
if (parent.nodeName !== 'OL' && parent.nodeName !== 'UL') {
|
if (parent.nodeName !== 'OL' && parent.nodeName !== 'UL') {
|
||||||
@@ -96,25 +98,17 @@ function taskList(turndownService: _TurndownService) {
|
|||||||
node.parentNode.nodeName === 'UL'
|
node.parentNode.nodeName === 'UL'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
replacement: function (content: string, node: HTMLInputElement) {
|
replacement: function (_content: string, node: HTMLInputElement) {
|
||||||
const checkbox = node.querySelector(
|
const isChecked = node.getAttribute('data-checked') === 'true';
|
||||||
'input[type="checkbox"]',
|
const div = node.querySelector('div');
|
||||||
) as HTMLInputElement;
|
const text = div ? div.textContent.trim() : node.textContent.trim();
|
||||||
const isChecked = checkbox.checked;
|
|
||||||
|
|
||||||
// Process content like regular list items
|
|
||||||
content = content
|
|
||||||
.replace(/^\n+/, '') // remove leading newlines
|
|
||||||
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
|
|
||||||
.replace(/\n/gm, '\n '); // indent nested content with 2 spaces
|
|
||||||
|
|
||||||
// Create the checkbox prefix
|
|
||||||
const prefix = `- ${isChecked ? '[x]' : '[ ]'} `;
|
const prefix = `- ${isChecked ? '[x]' : '[ ]'} `;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
prefix +
|
prefix +
|
||||||
content +
|
text +
|
||||||
(node.nextSibling && !/\n$/.test(content) ? '\n' : '')
|
(node.nextSibling && !/\n$/.test(text) ? '\n' : '')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user