Skip to content

Commit f1a36b9

Browse files
committed
fix: render exception when there is blockid in the middle of the table (l1xnan#269)
1 parent f10da3a commit f1a36b9

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/render.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,25 @@ export async function renderMarkdown(
167167

168168
const cache = app.metadataCache.getFileCache(file);
169169

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;
175189
});
176190

177191
const fragment = {

0 commit comments

Comments
 (0)