Getting started
Usage
Parse with the kv plugin, create a runtime model, and bind kv paths in Vue — the three integration steps.
Parse with the plugin
parse.ts
import { parseMarkdown } from 'comark'
import kv from 'comark-kv'
const tree = await parseMarkdown(content, {
plugins: [kv()],
})
// tree.meta.kv → KvDescriptor (single) or KvNamespaceMap (multi)
Create a runtime model
model.ts
import { createKvModel, isSingleDriverSchema } from 'comark-kv/model'
const { model, ready, dispose, storages } = await createKvModel(tree.meta.kv!)
await ready
// Single-driver
model.get('kv.name')
model.set('kv.name', 'Bob')
// Multi-driver
model.get('kv.config.name')
model.set('kv.config.name', 'Bob')
// HTTP URL shortcut (resource namespace)
model.get('kv.todos') // remote JSON
model.get('kv.todos.0.title') // nested path into the resource
// Access individual storages for advanced use / testing
storages['config'].getItem('user-config:name')
dispose()
Bind in Vue
App.vue
<script setup lang="ts">
import { parseMarkdown } from 'comark'
import kv from 'comark-kv'
import { useKvModel } from 'comark-kv/vue'
const tree = await parseMarkdown(markdown, { plugins: [kv()] })
const { model, ready } = useKvModel(tree)
await ready
</script>
<template>
<Markdown :value="tree" :model="model" />
</template>
Try the todo desk example in the playground.