mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
fix(import/zip): remove nesting of ck-content divs
This commit is contained in:
parent
f32b76d047
commit
f3b866fa7b
2208
demo/!!!meta.json
2208
demo/!!!meta.json
File diff suppressed because it is too large
Load Diff
@ -82,4 +82,37 @@ describe("removeTriliumTags", () => {
|
||||
const expected = `\n<p>Hello world</p>\n`;
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
|
||||
it("removes ckeditor tags from HTML", () => {
|
||||
const output = removeTriliumTags(trimIndentation`\
|
||||
<body>
|
||||
<div class="content">
|
||||
<h1 data-trilium-h1>21 - Thursday</h1>
|
||||
|
||||
<div class="ck-content">
|
||||
<p>TODO:</p>
|
||||
<ul class="todo-list">
|
||||
<li>
|
||||
<label class="todo-list__label">
|
||||
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description"> </span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`).split("\n").filter((l) => l.trim()).join("\n");
|
||||
const expected = trimIndentation`\
|
||||
<body>
|
||||
<p>TODO:</p>
|
||||
<ul class="todo-list">
|
||||
<li>
|
||||
<label class="todo-list__label">
|
||||
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description"> </span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</body>`;
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
@ -659,11 +659,17 @@ function resolveNoteType(type: string | undefined): NoteType {
|
||||
export function removeTriliumTags(content: string) {
|
||||
const tagsToRemove = [
|
||||
"<h1 data-trilium-h1>([^<]*)<\/h1>",
|
||||
"<title data-trilium-title>([^<]*)<\/title>"];
|
||||
"<title data-trilium-title>([^<]*)<\/title>"
|
||||
];
|
||||
for (const tag of tagsToRemove) {
|
||||
let re = new RegExp(tag, "gi");
|
||||
content = content.replace(re, "");
|
||||
}
|
||||
|
||||
// Remove ckeditor tags
|
||||
content = content.replace(/<div class="ck-content">(.*)<\/div>/gms, "$1");
|
||||
content = content.replace(/<div class="content">(.*)<\/div>/gms, "$1");
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user