Skip to content

Commit

Permalink
fix(dataview): dataviewjs (codeblock) inside callout
Browse files Browse the repository at this point in the history
close #354
  • Loading branch information
Mara-Li committed Jul 28, 2024
1 parent 96a4649 commit 5261c6c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/conversion/compiler/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ class DataviewCompiler {
* @link https://blacksmithgu.github.io/obsidian-dataview/api/intro/
*/
async dataviewJS(query: string) {
const { isInsideCallout, finalQuery } = sanitizeQuery(query);
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
const div = createEl("div");
const component = new Component();
await this.dvApi.executeJs(query, div, component, this.path);
await this.dvApi.executeJs(finalQuery, div, component, this.path);
component.load();
return removeDataviewQueries(div.innerHTML, this.properties.frontmatter.general);
const markdown = removeDataviewQueries(
div.innerHTML,
this.properties.frontmatter.general
);
if (isInsideCallout) {
return surroundWithCalloutBlock(markdown);
}
return markdown;
}

/**
Expand Down Expand Up @@ -331,7 +339,6 @@ function sanitizeQuery(query: string): { isInsideCallout: boolean; finalQuery: s
let isInsideCallout = false;
const parts = query.split("\n");
const sanitized = [];

for (const part of parts) {
if (part.startsWith(">")) {
isInsideCallout = true;
Expand All @@ -340,7 +347,10 @@ function sanitizeQuery(query: string): { isInsideCallout: boolean; finalQuery: s
sanitized.push(part);
}
}
const finalQuery = isInsideCallout ? sanitized.join("\n") : query;
let finalQuery = query;
if (isInsideCallout) {
finalQuery = sanitized.join("\n");
}
return { isInsideCallout, finalQuery };
}

Expand Down

0 comments on commit 5261c6c

Please sign in to comment.