1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-02 22:49:09 +02:00

All: Resolves #2915: Improve automatic title generation (#2955)

This commit is contained in:
anirudh murali
2020-05-09 20:25:00 +05:30
committed by GitHub
parent dbe8d3a68e
commit 57cf826e2c
3 changed files with 31 additions and 16 deletions

View File

@@ -91,6 +91,16 @@ const markdownUtils = {
return output.join('\n');
},
titleFromBody(body) {
if (!body) return '';
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);
},
};
module.exports = markdownUtils;