This document explains how the sample plugin works inside RefMD. The goal is to provide a minimal yet complete example that authors can inspect and adapt.
- The toolbar exposes a “New Sample Document” command wired to
sample.create. - The Extism backend issues a
createDocumenteffect (type defaults todocument). - A
putKveffect stores{"isSample": true}underkv('sample', docId, 'meta'). - A navigation effect redirects the client to
/sample/:createdDocId.
mount(container, host)is called by the app when the/sample/<docId>route is matched.- The plugin reads
docIdfrom the current path/query parameters. - Records for that document are fetched via
host.exec('host.records.list', { docId, kind: 'sample' }). - Markdown entered in the textarea is rendered using
host.api.renderMarkdown, andhost.ui.hydrateAllenhances the output.
From this point, the user can:
- Click “Create” to send
sample.create_recordthrough Extism, which issues acreateRecordeffect. - Edit or delete existing records (again through Extism effects).
- Re-render markdown using the input textarea.
- Hit “Reload records” to refresh the list from the server.
Everything happens against the demo document that the plugin itself created. No prior doc selection is necessary.
| Action | Backend effect | UI feedback |
|---|---|---|
sample.hello |
showToast |
Toast notification |
sample.create_record |
createRecord + showToast |
List refresh, toast |
sample.update_record |
updateRecord + showToast |
List refresh, toast |
sample.delete_record |
deleteRecord + showToast |
List refresh, toast |
The Extism backend lives in backend/src/lib.rs and uses the shared helper SAMPLE_KIND = "sample" for consistency.
The frontend relies on the bridge utilities exposed by the RefMD host:
host.exec→ dispatch Extism commands (sample.*)host.exec('host.records.list', …),host.api.renderMarkdownhost.ui.hydrateAll→ rehydrate attachment/wiki-link widgets after markdown render
Documents created by the command are marked in plugin KV (meta.isSample = true).
canOpen fetches that flag via host.exec('host.kv.get', …) to decide if a document should be
handled by this plugin. When the route matcher runs, /document/<id> can be
remapped to /sample/<id> whenever the flag is present.
The GitHub Actions workflow packages the distributable files into
sample-plugin.zip, containing:
backend/plugin.wasmfrontend/index.mjsplugin.json
Use the release asset URL (for example,
https://github.com/refmdio/sample-plugin/releases/download/<tag>/sample-plugin.zip)
when installing from RefMD’s /plugins page.