mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
fix: period is stripped from headline extraction
This commit is contained in:
@@ -63,6 +63,18 @@ test("note without a title should get title from content", () =>
|
||||
expect(note.title).toBe("HelloThis is colorful");
|
||||
}));
|
||||
|
||||
test("note should get headline from content", () =>
|
||||
noteTest({
|
||||
...TEST_NOTE,
|
||||
content: {
|
||||
type: TEST_NOTE.content.type,
|
||||
data: "<p>This is a very colorful existence.</p>",
|
||||
},
|
||||
}).then(async ({ db, id }) => {
|
||||
let note = db.notes.note(id);
|
||||
expect(note.headline).toBe("This is a very colorful existence.");
|
||||
}));
|
||||
|
||||
test("note title should allow trailing space", () =>
|
||||
noteTest({ title: "Hello ", content: TEST_NOTE.content }).then(
|
||||
async ({ db, id }) => {
|
||||
|
||||
@@ -61,13 +61,15 @@ export default Tiny;
|
||||
function getHeadlineFromText(text) {
|
||||
for (var i = 0; i < text.length; ++i) {
|
||||
const char = text[i];
|
||||
const nextChar = text[i + 1];
|
||||
if (
|
||||
char === "\n" ||
|
||||
char === "\t" ||
|
||||
char === "\r" ||
|
||||
char === "." ||
|
||||
(char === "." && nextChar === " ") ||
|
||||
i >= 120
|
||||
) {
|
||||
if (char === ".") ++i;
|
||||
return text.substring(0, i);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user