@ogygia/content · Macros
Inline markdown
import.meta.og.md(text) renders a markdown passage when you build, through your app's own markdown settings, and puts the HTML in the module as a static region. For prose that lives in a component rather than in a collection.
On this page
Some prose belongs to a component rather than to a collection: the intro on a landing page, the help text beside a form. import.meta.og.md(text) renders a markdown passage at build time, through your app’s own markdown settings (the same remark and rehype plugins, the same highlighted code), so it comes out as it would in a .md file. The build replaces the call with the HTML as a region, and you render it with <Region of={…} />. It ships no JavaScript.
md comes with @ogygia/content: list its content() plugin beside ogygia() and add /// <reference types="@ogygia/content/types" /> to src/ogygia.d.ts (Install). It works without the markdown option, at the default markdown settings. Without the plugin, a call fails the build with macro_needs_plugin.
<script lang="ts">
import { Region } from 'ogygia';
const intro = import.meta.og.md(`
## Getting started
Install the package, then add the plugin. Code blocks are highlighted too:
\`\`\`ts
export const csr = false;
\`\`\`
`);
</script>
<Region of={intro} />Output
Everything static the markdown pipeline does: headings with ids and link anchors, lists, emphasis, links, tables, callouts (::: tip) and highlighted code blocks. Indentation the lines share is taken off first, as code does, so you can write the passage nested in the call.
A frontmatter block at the top is read and dropped, since there’s no entry to give it to.
Static content
A region made by md() is plain HTML, so the passage can’t hold anything that has to run. If it compiles to a <script>, a component tag, an island import or a Svelte expression (a { in the prose), the build fails with content_md_dynamic. Tab groups count: ::: code-group and ::: tabs become an island, so they fail too. A component name in backticks or in a code block is text and is fine. For a live part, write it as a component next to the region, or move the passage to a .svx file in a collection, where islands are allowed.
With markdown.overrides on, links, images and inline code become components, so any passage that has one fails with content_md_dynamic.
Rules
textis written in the source. A string, or a template literal with no${…}. An interpolation fails withcontent_code_interpolated, a variable or expression withcontent_code_not_static, and a call without exactly one argument withcontent_md_arity.- It’s rewritten in scripts. A
.tsor.jsmodule or a.sveltecomponent’s<script>, not the template (macro_in_markup). The<script>of a.svxor.mdfile isn’t compiled for it yet, and a call there fails the build with the same code. Call it in a.tsmodule and import the region into the page. - No local images. A passage has no file of its own, so a relative image path has nothing to resolve from. Put the image in the component, with
<Img>; with@ogygia/imagelisted, a local image in a passage fails the build withimage_markdown_no_file.
md vs code
code renders one highlighted snippet, with a language and the code block’s meta. md renders a passage, with headings, lists and prose, and code blocks inside it. Use code for exactly one block, md for a passage. Both give a region you render the same way.