Skip to content

Commit

Permalink
fix: hardbreak added to frontmatter
Browse files Browse the repository at this point in the history
close #358
  • Loading branch information
Mara-Li committed Aug 15, 2024
1 parent 13dbcca commit 0e41c52
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/conversion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ export function addHardLineBreak(
frontmatter: PropertiesConversion
): string {
try {
text = text.replace(/^\s*\\\s*$/gim, "<br/>");
const { exists, contentStart, from } = getFrontMatterInfo(text);
if (frontmatter.hardbreak) {
text = text.replace(/\n/gm, " \n");
if (exists) {
const substring = text
.substring(contentStart)
.replace(/\n/gm, " \n")
.replace(/^\s*\\\s*$/gim, "<br/>");
return `---\n${text.slice(from, contentStart)}${substring}`;
}
return text.replace(/\n/gm, " \n");
} else if (exists) {
const newText = text.substring(contentStart).replace(/^\s*\\\s*$/gim, "<br/>");
return `---\n${text.slice(from, contentStart)}${newText}`;
}
return text;
return text.replace(/^\s*\\\s*$/gim, "<br/>");
} catch (e) {
plugin.console.notif({ e: true }, e);
return text;
Expand Down

0 comments on commit 0e41c52

Please sign in to comment.