mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 16:02:35 +10:00
preserve details tag in markdown export
This commit is contained in:
@ -18,13 +18,12 @@ export function turndown(html: string): string {
|
|||||||
highlightedCodeBlock,
|
highlightedCodeBlock,
|
||||||
taskList,
|
taskList,
|
||||||
callout,
|
callout,
|
||||||
toggleListTitle,
|
preserveDetail,
|
||||||
toggleListBody,
|
|
||||||
listParagraph,
|
listParagraph,
|
||||||
mathInline,
|
mathInline,
|
||||||
mathBlock,
|
mathBlock,
|
||||||
]);
|
]);
|
||||||
|
console.log(turndownService.turndown(html));
|
||||||
return turndownService.turndown(html).replaceAll('<br>', ' ');
|
return turndownService.turndown(html).replaceAll('<br>', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,29 +73,23 @@ function taskList(turndownService: TurndownService) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleListTitle(turndownService: TurndownService) {
|
function preserveDetail(turndownService: TurndownService) {
|
||||||
turndownService.addRule('toggleListTitle', {
|
turndownService.addRule('preserveDetail', {
|
||||||
filter: function (node: HTMLInputElement) {
|
filter: function (node: HTMLInputElement) {
|
||||||
return (
|
return node.nodeName === 'DETAILS';
|
||||||
node.nodeName === 'SUMMARY' && node.parentNode.nodeName === 'DETAILS'
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
replacement: function (content: any, node: HTMLInputElement) {
|
replacement: function (content: any, node: HTMLInputElement) {
|
||||||
return '- ' + content;
|
// TODO: preserve summary of nested details
|
||||||
},
|
const summary = node.querySelector(':scope > summary');
|
||||||
});
|
let detailSummary = '';
|
||||||
}
|
|
||||||
|
|
||||||
function toggleListBody(turndownService: TurndownService) {
|
if (summary) {
|
||||||
turndownService.addRule('toggleListContent', {
|
detailSummary = `<summary>${turndownService.turndown(summary.innerHTML)}</summary>`;
|
||||||
filter: function (node: HTMLInputElement) {
|
summary.remove();
|
||||||
return (
|
}
|
||||||
node.getAttribute('data-type') === 'detailsContent' &&
|
|
||||||
node.parentNode.nodeName === 'DETAILS'
|
const detailsContent = turndownService.turndown(node.innerHTML);
|
||||||
);
|
return `\n<details>\n${detailSummary}\n\n${detailsContent}\n\n</details>\n`;
|
||||||
},
|
|
||||||
replacement: function (content: any, node: HTMLInputElement) {
|
|
||||||
return ` ${content.replace(/\n/g, '\n ')} `;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -124,7 +117,7 @@ function mathBlock(turndownService: TurndownService) {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
replacement: function (content: any, node: HTMLInputElement) {
|
replacement: function (content: any, node: HTMLInputElement) {
|
||||||
return `$$${content}$$`;
|
return `\n$$${content}$$\n`;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user