File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,27 @@ export class PreviewView extends ItemView implements PreviewViewState {
3434 return 'Marp Preview' ;
3535 }
3636
37+
38+ // Function to replace Wikilinks with the desired format
39+ replaceImageWikilinks ( markdown : string ) : string {
40+ const wikilinkRegex = / ! \[ \[ ( [ ^ \] ] + ) \] \] / g;
41+ const lines = markdown . split ( "\n" ) ;
42+ const replacedLines = lines . map ( ( line ) => {
43+ const replacedLine = line . replace ( wikilinkRegex , ( match , name ) => {
44+ // Modify the format of the Wikilink as needed
45+ const url = this . app . vault . adapter . getResourcePath ( name ) ;
46+ return `` ;
47+ } ) ;
48+ return replacedLine ;
49+ } ) ;
50+ return replacedLines . join ( "\n" ) ;
51+ }
52+
53+
3754 async renderPreview ( ) {
3855 if ( ! this . file ) return ;
39- const content = await this . app . vault . cachedRead ( this . file ) ;
56+ const originContent = await this . app . vault . cachedRead ( this . file ) ;
57+ const content = this . replaceImageWikilinks ( originContent ) ;
4058 const { html, css } = marp . render ( content ) ;
4159 const doc = await convertHtml ( html ) ;
4260 const container = this . containerEl . children [ 1 ] ;
You can’t perform that action at this time.
0 commit comments