import { ObsidianUtils } from "../obsidianUtils" ; export class MultipleFileProcessor { private utils : ObsidianUtils ; private regex = /!\[\[(.*)\]\]/gm ; private excalidrawRegex = /(.*\.excalidraw)/i ; constructor ( utils ) { this . utils = utils ; } process ( markdown ) { return markdown . split ( '\n' ) . map ( ( line , index ) => { if ( this . regex . test ( line ) ) return this . transformLine ( line ) ; return line ; } ) . join ( '\n' ) ; } private transformLine ( line ) { let filePath = line . replace ( "![[" , "" ) . replace ( "]]" , "" ) ; let header = null ; if ( filePath . includes ( '#' ) ) { const split = filePath . split ( '#' ) ; filePath = split [ 0 ] ; header = split [ 1 ] ; } const res = this . getMarkdownFile ( filePath ) ; if ( res === null ) { return line ; } return this . process ( this . utils . parseFile ( res , header ) ) ; } getMarkdownFile ( line ) { if ( this . excalidrawRegex . test ( line ) ) { return null ; } let file = line ; if ( ! line . toLowerCase ( ) . endsWith ( ".md" ) ) { file = file + ".md" ; } return this . utils . getAbsolutePath ( file ) ; } }