Code & Data›Code

core

Code

Inline code span for dynamic content, where backticks cannot reach

Source

import Markdoc from '@markdoc/markdoc';
import type { Config, Node, RenderableTreeNode, Schema } from '@markdoc/markdoc';
import { declareUniversalPosture } from '../lib/index.js';
const { Tag } = Markdoc;

export const code: Schema = {
	inline: true,
	attributes: {},
	transform(node: Node, config: Config) {
		const children = node.transformChildren(config) as RenderableTreeNode[];
		return new Tag('code', { 'data-rune': 'code' }, children);
	},
};

declareUniversalPosture(code, 'inline');

View packages/runes/src/tags/code.ts on GitHub

An inline code span you can put a variable inside.

{% code %}{% $row.name %}{% /code %}

Use backticks unless the content is dynamic

For static code, backticks are still correct and always will be:

Set `href` to make the card clickable.

Reach for this rune only when what goes inside is a variable — a {% data %} row value, a binding passed to an {% include %}. Exactly as **bold** stays correct for static emphasis.

Why backticks can't do it

A code span is literal by definition. Everything between the backticks is text, so Markdoc syntax inside one is never parsed:

`{% $row.name %}`   →   <code>{% $row.name %}</code>

That is standard Markdown, not a refrakt quirk — and it is the only inline construct with this property. Everything else passes a variable through intact:

AuthoredRenders
[{% $row.name %}](/runes/card)a link labelled href
[**{% $row.name %}**](…)bold inside a link
**_{% $row.name %}_**nested emphasis
{% badge %}{% $row.name %}{% /badge %}a badge reading href
`{% $row.name %}`the literal text {% $row.name %}

So this rune exists to close one specific gap, not to offer a second spelling for something Markdown already does well.

In a table cell

The case it was built for — a generated reference table whose first column is an attribute name:

{% data src="_data/rune-attributes.json" root="attributes" where=$own
        headers="Attribute, Type, Required, Description" %}
{% code %}{% $row.name %}{% /code %}
---
{% $row.type %}
---
{% if $row.required %}✓{% else /%}—{% /if %}
---
{% $row.description %}
{% /data %}

See data for the headers attribute.

Output

The same element a backtick span produces, plus the usual rune markers:

<code class="rf-code" data-rune="code">href</code>

The element is the point: Lumina styles code with an element rule, so a paragraph mixing a backtick span and this rune looks uniform without either needing to know about the other. .rf-code is there for a theme that wants to tell them apart — it is not required for the default styling.

Attributes

None.

  • data — the per-row body this was built for
  • include — the other place a variable reaches content
  • snippet — for a block of code read from a file