Skip to content

Commit

Permalink
fix: dataviewjs in codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jul 28, 2024
1 parent 027df8e commit 3afa1e5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils/dataview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @credit oleeskild
* @link https://github.com/oleeskild/obsidian-digital-garden/blob/main/src/compiler/DataviewCompiler.ts
*/

import { Component, htmlToMarkdown } from "obsidian";
import type { GlobalSettings } from "../interface";
import {
Expand Down Expand Up @@ -114,11 +119,16 @@ class DataviewCompiler {
* @link https://blacksmithgu.github.io/obsidian-dataview/api/intro/
*/
async dataviewJS(query: string) {
const { isInsideCallout, finalQuery } = this.sanitizeQuery(query);
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 this.removeDataviewQueries(div.innerHTML);
const markdown = this.removeDataviewQueries(div.innerHTML);
if (isInsideCallout) {
return this.surroundWithCalloutBlock(markdown);
}
return markdown;
}
/**
* Inline DQL Dataview - The SQL-like Dataview Query Language in inline
Expand Down

0 comments on commit 3afa1e5

Please sign in to comment.