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.12is 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:
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 inmanifest.json:
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 throughregisterMethod:
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 exposecallPlugin on __PLUGIN_API__ too, with the same usage.
Handling a missing dependency
Implementation approach
Provider: register methods
Once activated, MarkdownLib’sdist/index.html exposes marked’s capabilities to the plugin system through registerMethod:
registerMethod(methodName, fn):fnmay 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 throughcallPlugin:
Why embed instead of using a CDN
MarkdownLib embedsmarked.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 thedependencies array of manifest.json and validated by the backend at install and startup:
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: