@@ -14,15 +14,15 @@ export default class MarkdownAttributes extends Plugin {
1414 topElement : HTMLElement ,
1515 ctx : MarkdownPostProcessorContext
1616 ) {
17- let str = topElement . innerText ;
1817 const child = topElement . firstElementChild ;
1918 if ( ! child ) return ;
19+ let str : string ;
2020
2121 /** Code blocks have to be handled separately because Obsidian does not
2222 * include any text past the language.
2323 *
2424 * Unfortunately this also means that changes to the code block attributes
25- * require reloading the note to take effect.
25+ * require reloading the note to take effect because they do not trigger the postprocessor .
2626 */
2727 if ( child instanceof HTMLPreElement ) {
2828 /** If getSectionInfo returns null, stop processing. */
@@ -60,17 +60,16 @@ export default class MarkdownAttributes extends Plugin {
6060
6161 /** Test if the element contains attributes. */
6262 if (
63- ! source ||
64- ! source . length ||
65- ! Processor . ONLY_RE . test ( source . trim ( ) )
66- )
67- return ;
68-
69- /** Pull the matched string and add it to the child so the Processor catches it. */
70- let [ attribute_string ] = source . match ( Processor . ONLY_RE ) ?? [ ] ;
71- child . prepend ( new Text ( attribute_string ) ) ;
72-
73- str = topElement . innerText ;
63+ source &&
64+ source . length &&
65+ Processor . ONLY_RE . test ( source . trim ( ) )
66+ ) {
67+ /** Pull the matched string and add it to the child so the Processor catches it. */
68+ let [ attribute_string ] = source . match ( Processor . ONLY_RE ) ?? [ ] ;
69+ child . prepend ( new Text ( attribute_string ) ) ;
70+
71+ str = topElement . innerText ;
72+ }
7473 }
7574
7675 /**
@@ -85,7 +84,7 @@ export default class MarkdownAttributes extends Plugin {
8584 }
8685
8786 /** Test if the element contains attributes. */
88- if ( ! Processor . BASE_RE . test ( str ) ) return ;
87+ if ( ! Processor . BASE_RE . test ( str ?? topElement . innerText ) ) return ;
8988
9089 /** Parse the element using the Processor. */
9190 if ( ! ( child instanceof HTMLElement ) ) return ;
0 commit comments