diff --git a/packages/block-library/src/table-of-contents/edit.js b/packages/block-library/src/table-of-contents/edit.js index d20a5981021ce..67936ea269ce4 100644 --- a/packages/block-library/src/table-of-contents/edit.js +++ b/packages/block-library/src/table-of-contents/edit.js @@ -187,7 +187,13 @@ export default function TableOfContentsEdit( { headingAttributes.anchor !== ''; _latestHeadings.push( { - content: stripHTML( headingAttributes.content ), + // Convert line breaks to spaces, and get rid of HTML tags in the headings. + content: stripHTML( + headingAttributes.content.replace( + /(
)+/g, + ' ' + ) + ), level: headingAttributes.level, link: canBeLinked ? `${ headingPageLink }#${ headingAttributes.anchor }`