mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +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");
|
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", () =>
|
test("note title should allow trailing space", () =>
|
||||||
noteTest({ title: "Hello ", content: TEST_NOTE.content }).then(
|
noteTest({ title: "Hello ", content: TEST_NOTE.content }).then(
|
||||||
async ({ db, id }) => {
|
async ({ db, id }) => {
|
||||||
|
|||||||
@@ -61,13 +61,15 @@ export default Tiny;
|
|||||||
function getHeadlineFromText(text) {
|
function getHeadlineFromText(text) {
|
||||||
for (var i = 0; i < text.length; ++i) {
|
for (var i = 0; i < text.length; ++i) {
|
||||||
const char = text[i];
|
const char = text[i];
|
||||||
|
const nextChar = text[i + 1];
|
||||||
if (
|
if (
|
||||||
char === "\n" ||
|
char === "\n" ||
|
||||||
char === "\t" ||
|
char === "\t" ||
|
||||||
char === "\r" ||
|
char === "\r" ||
|
||||||
char === "." ||
|
(char === "." && nextChar === " ") ||
|
||||||
i >= 120
|
i >= 120
|
||||||
) {
|
) {
|
||||||
|
if (char === ".") ++i;
|
||||||
return text.substring(0, i);
|
return text.substring(0, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user