mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-25 16:09:42 +01:00
fix: trim text extracted from html to get correct headline
This commit is contained in:
@@ -75,6 +75,18 @@ test("note should get headline from content", () =>
|
||||
expect(note.headline).toBe("This is a very colorful existence.");
|
||||
}));
|
||||
|
||||
test("note should get headline from content containing only lists", () =>
|
||||
noteTest({
|
||||
...TEST_NOTE,
|
||||
content: {
|
||||
type: TEST_NOTE.content.type,
|
||||
data: `<ol style="list-style-type: decimal;" data-mce-style="list-style-type: decimal;"><li>Hello I won't be a headline :(</li><li>Me too.</li><li>Gold.</li></ol>`,
|
||||
},
|
||||
}).then(async ({ db, id }) => {
|
||||
let note = db.notes.note(id);
|
||||
expect(note.headline).toBe("Hello I won't be a headline :(Me too.Gold.");
|
||||
}));
|
||||
|
||||
test("note title should allow trailing space", () =>
|
||||
noteTest({ title: "Hello ", content: TEST_NOTE.content }).then(
|
||||
async ({ db, id }) => {
|
||||
|
||||
@@ -15,9 +15,9 @@ class Tiny {
|
||||
}
|
||||
|
||||
toTXT() {
|
||||
if (window.DOMParser) {
|
||||
if ("DOMParser" in window || "DOMParser" in global) {
|
||||
let doc = new DOMParser().parseFromString(this.data, "text/html");
|
||||
return (doc.body || doc.firstElementChild).textContent || "";
|
||||
return doc.body.textContent.trim();
|
||||
} else {
|
||||
return decode(
|
||||
this.data.replace(/<br[^>]*>/gi, "\n").replace(/<[^>]+>/g, "")
|
||||
|
||||
Reference in New Issue
Block a user