remove H1 from the text during import if it matches note title

This commit is contained in:
zadam 2019-08-31 22:45:57 +02:00
parent fe6f19e611
commit a5e38165ef

View File

@ -273,6 +273,8 @@ async function importTar(importContext, fileBuffer, importRootNote) {
content = mdWriter.render(parsed);
}
const noteTitle = getNoteTitle(filePath, noteMeta);
if (type === 'text') {
function isUrlAbsolute(url) {
return /^(?:[a-z]+:)?\/\//i.test(url);
@ -301,6 +303,15 @@ async function importTar(importContext, fileBuffer, importRootNote) {
return `href="#root/${targetNoteId}"`;
});
content = content.replace(/<h1>([^<]*)<\/h1>/g, (match, text) => {
if (noteTitle.trim() === text.trim()) {
return ""; // remove whole H1 tag
}
else {
return match;
}
});
}
if (type === 'relation-map' && noteMeta) {
@ -320,8 +331,6 @@ async function importTar(importContext, fileBuffer, importRootNote) {
await note.setContent(content);
}
else {
const noteTitle = getNoteTitle(filePath, noteMeta);
({note} = await noteService.createNote(parentNoteId, noteTitle, content, {
noteId,
type,