fix: period is stripped from headline extraction

This commit is contained in:
thecodrr
2021-02-22 09:27:02 +05:00
parent ee30d30506
commit 83e896ce1e
2 changed files with 15 additions and 1 deletions

View File

@@ -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 }) => {

View File

@@ -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);
}
}