Skip to content

Build your personal knowledge base with Trilium Notes

feat(script-api): add markdownToHtml to backend script API

Elian Doranfaa7809fed2f
diff --git a/packages/trilium-core/src/services/backend_script_api.ts b/packages/trilium-core/src/services/backend_script_api.ts
index 2a58dcd55d..3e21bbab5b 100644
--- a/packages/trilium-core/src/services/backend_script_api.ts
+++ b/packages/trilium-core/src/services/backend_script_api.ts
@@ -36,7 +36,8 @@ import { getSql } from "./sql/index";
import treeService from "./tree.js";
import { escapeHtml, randomString, unescapeHtml } from "./utils/index";
import ws from "./ws.js";
-import markdown from "./export/markdown.js";
+import markdownExport from "./export/markdown.js";
+import markdownImport from "./import/markdown.js";
/**
* A whole number
@@ -60,16 +61,22 @@ interface NoteAndBranch {
branch: BBranch;
}
-
export interface Api {
-
- /**
+ /**
* Converts the given HTML string to Markdown.
*
* @param html - HTML content to convert
* @returns Markdown representation of the input HTML
*/
- htmlToMarkdown(html: string): string
+ htmlToMarkdown(html: string): string;
+
+ /**
+ * Converts the given Markdown string to HTML.
+ *
+ * @param markdown - Markdown content to convert
+ * @returns HTML representation of the input Markdown
+ */
+ markdownToHtml(markdown: string): string;
/**
* Note where the script execution started — the entry point of the current script bundle
@@ -519,7 +526,8 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.getOptions = () => optionsService.getOptions();
this.getAttribute = (attributeId) => becca.getAttribute(attributeId);
- this.htmlToMarkdown = (html) => markdown.toMarkdown(html);
+ this.htmlToMarkdown = (html) => markdownExport.toMarkdown(html);
+ this.markdownToHtml = (markdown) => markdownImport.renderToHtml(markdown, "");
this.searchForNotes = (query, searchParams = {}) => {
if (searchParams.includeArchivedNotes === undefined) {