File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -167,11 +167,25 @@ export async function renderMarkdown(
167
167
168
168
const cache = app . metadataCache . getFileCache ( file ) ;
169
169
170
- const lines = data ?. split ( "\n" ) ?? [ ] ;
171
-
172
- Object . entries ( cache ?. blocks ?? { } ) . forEach ( ( [ key , c ] ) => {
173
- const idx = c . position . end . line ;
174
- lines [ idx ] = `<span id="^${ key } " class="blockid"></span>\n` + lines [ idx ] ;
170
+ // const lines = data?.split("\n") ?? [];
171
+ // Object.entries(cache?.blocks ?? {}).forEach(([key, c]) => {
172
+ // const idx = c.position.end.line;
173
+ // lines[idx] = `<span id="^${key}" class="blockid"></span>\n` + lines[idx];
174
+ // });
175
+
176
+ const blocks = new Map ( Object . entries ( cache ?. blocks ?? { } ) ) ;
177
+ const lines = ( data ?. split ( "\n" ) ?? [ ] ) . map ( ( line , i ) => {
178
+ for ( const {
179
+ id,
180
+ position : { start, end } ,
181
+ } of blocks . values ( ) ) {
182
+ const blockid = `^${ id } ` ;
183
+ if ( line . includes ( blockid ) && i >= start . line && i <= end . line ) {
184
+ blocks . delete ( id ) ;
185
+ return line . replace ( blockid , `<span id="${ blockid } " class="blockid"></span> ${ blockid } ` ) ;
186
+ }
187
+ }
188
+ return line ;
175
189
} ) ;
176
190
177
191
const fragment = {
You can’t perform that action at this time.
0 commit comments