fix: Map hardbreaks to breaks (#9550)

This commit is contained in:
Tom Moor
2025-07-04 20:09:50 -04:00
committed by GitHub
parent 0589f62bde
commit 12d084e8fa
2 changed files with 24 additions and 4 deletions

View File

@@ -23,10 +23,6 @@ export default class HardBreak extends Node {
};
}
get markdownToken() {
return "hardbreak";
}
get rulePlugins() {
return [breakRule];
}

View File

@@ -6,6 +6,30 @@ function isOldHardBreak(token: Token) {
/** Markdown plugin to convert old encoded hard breaks to paragraphs */
export default function markdownBreakToParagraphs(md: MarkdownIt) {
md.core.ruler.after("inline", "hardbreaks", (state) => {
const tokens = state.tokens;
// iterate through tokens and convert hardbreak tokens to br tokens
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (token.children) {
for (let j = 0; j < token.children.length; j++) {
const child = token.children[j];
if (child.type === "hardbreak") {
// convert hardbreak token to br token, we don't care about the difference
child.type = "br";
child.tag = "br";
child.nesting = 0;
}
}
}
}
return false;
});
// insert a new rule after the "inline" rules are parsed
md.core.ruler.after("inline", "breaks", (state) => {
const tokens = state.tokens;