@@ -140,7 +140,8 @@ const calloutLineRegex = new RegExp(/^> *\[\!\w+\|?.*?\][+-]?.*$/gm)
140140const tagRegex = new RegExp (
141141 / (?< = ^ | ) # ( (?: [ - _ \p{ L} \p{ Emoji} \p{ M} \d ] ) + (?: \/ [ - _ \p{ L} \p{ Emoji} \p{ M} \d ] + ) * ) / gu,
142142)
143- const blockReferenceRegex = new RegExp ( / \^ ( [ - _ A - Z a - z 0 - 9 ] + ) $ / g)
143+ // const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)?$/g)
144+ const blockReferenceRegex = new RegExp ( / \^ ( [ - _ A - Z a - z 0 - 9 ] + ) \s * ?$ / g)
144145const ytLinkRegex = / ^ .* ( y o u t u .b e \/ | v \/ | u \/ \w \/ | e m b e d \/ | w a t c h \? v = | \& v = ) ( [ ^ # \& \? ] * ) .* /
145146const ytPlaylistLinkRegex = / [ ? & ] l i s t = ( [ ^ # ? & ] * ) /
146147const videoExtensionRegex = new RegExp ( / \. ( m p 4 | w e b m | o g g | a v i | m o v | f l v | w m v | m k v | m p g | m p e g | 3 g p | m 4 v ) $ / )
@@ -557,7 +558,6 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
557558 const blockTagTypes = new Set ( [ "blockquote" ] )
558559 return ( tree : HtmlRoot , file ) => {
559560 file . data . blocks = { }
560-
561561 visit ( tree , "element" , ( node , index , parent ) => {
562562 if ( blockTagTypes . has ( node . tagName ) ) {
563563 const nextChild = parent ?. children . at ( index ! + 2 ) as Element
@@ -619,6 +619,47 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
619619 }
620620 }
621621 }
622+
623+ const first = node . children . at ( 0 ) as Literal
624+ if ( first && first . value && typeof first . value === "string" ) { // yoma
625+ const matches = first . value . match ( blockReferenceRegex )
626+ if ( matches && matches . length >= 1 ) {
627+ first . value = first . value . slice ( 0 , - matches [ 0 ] . length )
628+ const block = matches [ 0 ] . slice ( 1 ) . trim ( )
629+
630+ if ( first . value === "" ) {
631+ // this is an inline block ref but the actual block
632+ // is the previous element above it
633+ let idx = ( index ?? 1 ) - 1
634+ while ( idx >= 0 ) {
635+ const element = parent ?. children . at ( idx )
636+ if ( ! element ) break
637+ if ( element . type !== "element" ) {
638+ idx -= 1
639+ } else {
640+ if ( ! Object . keys ( file . data . blocks ! ) . includes ( block ) ) {
641+ element . properties = {
642+ ...element . properties ,
643+ id : block ,
644+ }
645+ file . data . blocks ! [ block ] = element
646+ }
647+ return
648+ }
649+ }
650+ } else {
651+ // normal paragraph transclude
652+ if ( ! Object . keys ( file . data . blocks ! ) . includes ( block ) ) {
653+ node . properties = {
654+ ...node . properties ,
655+ id : block ,
656+ }
657+ file . data . blocks ! [ block ] = node
658+ }
659+ }
660+ }
661+ }
662+
622663 }
623664 } )
624665
0 commit comments