Skip to main content

MarkdownLib Library plugin

MarkdownLib is a library that wraps Markdown parsing as a Library plugin (Library plugin), which any plugin can call through callPlugin to render Markdown text as HTML.
  • Plugin ID: top.qomicex.markdown
  • Version: 1.2.1
  • Dependency: none
  • Bundling: marked v15.0.12 is embedded, with no external CDN dependency (not affected by the Tauri CSP)

Why you need it

QML plugins run inside a Tauri WebView, and after packaging the CSP blocks all external requests and external <script src> loads. If a plugin references marked straight from a CDN in its HTML:
the CSP blocks it in packaged builds, marked is undefined, and Markdown cannot be rendered. Once marked lives in its own Library plugin:
  • the marked code is embedded in the MarkdownLib package, so no external CDN is needed and CSP is bypassed naturally;
  • multiple plugins can share a single rendering implementation instead of embedding duplicate code;
  • plugin dependencies manage it, so versions are explicit and upgradeable.

Installation

After you install the MarkdownLib Library plugin, other plugins declare the dependency in manifest.json:
Dependency fields: Supported version syntax: >=1.2.0, <=1.2.0, >1.0, <2.0, =1.0.1, exact 1.2.0, and multiple conditions separated by spaces ">=1.0 <2.0".

Interface

MarkdownLib exposes the following methods through registerMethod:

renderMarkdown(md)

Renders a full Markdown text as an HTML string.

renderMarkdownInline(md)

Renders inline Markdown as HTML (no block-level elements).

stripHtml(html)

Removes HTML tags and returns plain text.

Calling methods

Call through __PLUGIN_API__.callPlugin:

Examples

Basic rendering

Inline rendering + stripping tags

Using it in an overlay window

Overlay windows expose callPlugin on __PLUGIN_API__ too, with the same usage.

Handling a missing dependency

Implementation approach

Provider: register methods

Once activated, MarkdownLib’s dist/index.html exposes marked’s capabilities to the plugin system through registerMethod:
Key points:
  • registerMethod(methodName, fn): fn may return a plain value or a Promise (async methods are supported too);
  • a plugin can register multiple methods;
  • all methods are unregistered automatically when the plugin is disabled;
  • name methods meaningfully so they do not clash with other plugins.

Consumer: call methods

Dependent plugins call through callPlugin:
Call flow:

Why embed instead of using a CDN

MarkdownLib embeds marked.min.js in the plugin package instead of referencing it through <script src="CDN">:
  • CSP-safe after packaging: external scripts are blocked, embedded ones are not;
  • works offline: no network needed;
  • locked version: bundled into the plugin, so the version is deterministic and reproducible.

How it is defined

Plugin dependency mechanism

Dependencies are declared in the dependencies array of manifest.json and validated by the backend at install and startup:
Dependent plugins register methods with registerMethod on __PLUGIN_API__, and the methods are stored in the main window’s __pluginRegistry. Disabling a plugin removes its methods automatically.

How method registration and calls work

Error handling

callPlugin rejects on failure, so always wrap it in try/catch on the caller side:

Revision history