Skip to content

Commit

Permalink
Footnote: only replace attribute if footnotes were detected
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jul 25, 2024
1 parent 32838e8 commit 2611959
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/core-data/src/footnotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export function updateFootnotesFromMeta( blocks, meta ) {
? RichTextData.fromHTMLString( value )
: new RichTextData( value );

let hasFootnotes = false;

richTextValue.replacements.forEach( ( replacement ) => {
if ( replacement.type === 'core/footnote' ) {
const id = replacement.attributes[ 'data-fn' ];
Expand All @@ -92,13 +94,16 @@ export function updateFootnotesFromMeta( blocks, meta ) {
replacement.innerHTML = toHTMLString( {
value: countValue,
} );
hasFootnotes = true;
}
} );

attributes[ key ] =
typeof value === 'string'
? richTextValue.toHTMLString()
: richTextValue;
if ( hasFootnotes ) {
attributes[ key ] =
typeof value === 'string'
? richTextValue.toHTMLString()
: richTextValue;
}
}

return attributes;
Expand Down

0 comments on commit 2611959

Please sign in to comment.