You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
This commit is contained in:
@@ -216,12 +216,19 @@ const markdownUtils = {
|
||||
|
||||
titleFromBody(body: string) {
|
||||
if (!body) return '';
|
||||
const spaceEntities = / /g;
|
||||
body = body.replace(spaceEntities, ' ');
|
||||
const lines = body.trim().split('\n');
|
||||
const title = lines[0].trim();
|
||||
|
||||
const mdLinkRegex = /!?\[([^\]]+?)\]\(.+?\)/g;
|
||||
const emptyMdLinkRegex = /!?\[\]\((.+?)\)/g;
|
||||
const filterRegex = /^[# \n\t*`-]*/;
|
||||
const lines = body.trim().split('\n');
|
||||
const title = lines[0].trim();
|
||||
return title.replace(filterRegex, '').replace(mdLinkRegex, '$1').replace(emptyMdLinkRegex, '$1').substring(0, 80);
|
||||
return title
|
||||
.replace(filterRegex, '')
|
||||
.replace(mdLinkRegex, '$1')
|
||||
.replace(emptyMdLinkRegex, '$1')
|
||||
.substring(0, 80);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -106,23 +106,17 @@ describe('markdownUtils', () => {
|
||||
}
|
||||
}));
|
||||
|
||||
it('replace markdown link with description', (async () => {
|
||||
|
||||
const testCases = [
|
||||
['Test case [one](link)', 'Test case one'],
|
||||
['Test case ', 'Test case two'],
|
||||
['**# -Test case three', 'Test case three'],
|
||||
['This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a [link](linkurl) at the end', 'This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a li'],
|
||||
['', ''],
|
||||
['These are [link1](one), [link2](two) and ', 'These are link1, link2 and link3'],
|
||||
['No description link to [](https://joplinapp.org)', 'No description link to https://joplinapp.org'],
|
||||
];
|
||||
|
||||
for (let i = 0; i < testCases.length; i++) {
|
||||
const md = testCases[i][0];
|
||||
const expected = testCases[i][1];
|
||||
expect(markdownUtils.titleFromBody(md)).toBe(expected);
|
||||
}
|
||||
}));
|
||||
it.each([
|
||||
['Test case [one](link)', 'Test case one'],
|
||||
['Test case ', 'Test case two'],
|
||||
['**# -Test case three', 'Test case three'],
|
||||
['This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a [link](linkurl) at the end', 'This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a li'],
|
||||
['', ''],
|
||||
['These are [link1](one), [link2](two) and ', 'These are link1, link2 and link3'],
|
||||
['No description link to [](https://joplinapp.org)', 'No description link to https://joplinapp.org'],
|
||||
[' \n\nThis is a test test.', 'This is a test test.'],
|
||||
])('should create a default note title from the note body (%j -> %j)', (body, expectedTitle) => {
|
||||
expect(markdownUtils.titleFromBody(body)).toBe(expectedTitle);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user