Your app can read and write the docs of its space as Markdown with matter.docs, as the member,
and open one beside its page in Matter’s own editor with
matter.panels.open({ doc }). Since Matter 0.5.9; set minMatterVersion to it if you use them.
const doc = await matter.docs.create({ title: 'Timesheets nobody reads', markdown: '# Timesheets nobody reads\n\n…' })
await matter.board('content').update(id, { values: { doc: doc.id } })
await matter.panels.open({ doc: doc.id })
// Later: its text, as people left it.
const { markdown } = await matter.docs.get(doc.id)Methods#
| Method | Description |
|---|---|
docs.list({ folderId? }) |
What’s in a folder of the app’s space, or at its top: { id, kind, name } for each, and a
file’s file. Since Matter 0.5.27.
|
docs.get(id) |
Resolves to { id, title, markdown, updatedAt }: the live doc, as people are editing it.
|
docs.create({ title?, markdown?, folderId? }) |
Makes a doc in the app’s space (in folderId, a folder there, if given). Resolves to it.
|
docs.update(id, { title?, markdown? }) |
Changes its title, or replaces its text. The new Markdown goes into the live doc block by block, so anyone editing it keeps their place and the blocks that didn’t change keep their history. |
Folders#
docs.list gives what people keep in the space: folders, docs, files, canvases and decks, in the
order they see them. A file comes with its file, as a files field holds it, to read or download
with matter.files. The item’s own id isn’t the file’s.
const top = await matter.docs.list()
const brand = top.find((item) => item.kind === 'folder' && item.name === 'Brand')
for (const item of brand ? await matter.docs.list({ folderId: brand.id }) : [])
if (item.file) console.log(item.name, await matter.files.download(item.file))Images#
In the Markdown, a doc’s images are their files’ URLs. To add one, upload it with
matter.files.upload and write :
Matter turns it into the doc’s own image, as if someone had dropped it in.
const chart = await matter.files.upload(blob, { name: 'hours.png' })
const { markdown } = await matter.docs.get(id)
await matter.docs.update(id, { markdown: markdown + '\n\n' })What an app reaches#
-
Only docs and folders in the app’s own space: any other id fails with
not_found. Canvases, decks, folders and files aren’t docs. - Everything is done as the member using the app, and Matter records it as theirs, as it does the app’s other writes.
- Docs go through Matter’s server, so they need the computer to be online.