Skip to content

Commit

Permalink
Fixed bug when iterating over mutations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bicarlsen committed Nov 1, 2021
1 parent 26c30e3 commit a1c003d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/md_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@ export function captionObserver( plugin: Plugin ) {
return new MutationObserver( ( mutations, observer ) => {
for ( const mutation of mutations ) {
if ( !mutation.target.matches( 'span.image-embed' ) ) {
return;
continue;
}

const caption_text = mutation.target.getAttribute( 'alt' );
if ( caption_text === mutation.target.getAttribute( 'src' ) ) {
// default caption, skip
return;
continue;
}

if ( mutation.target.querySelector( plugin.caption_selector ) ) {
// caption already added
return;
continue;
}

addCaption( mutation.target, caption_text, plugin );
updateFigureIndices( plugin );
} // end for..of

updateFigureIndices( plugin );
plugin.removeObserver( observer );

} );
}

Expand Down

0 comments on commit a1c003d

Please sign in to comment.