Rich text
A visual editor for formatted content, with a Source mode for the raw Markdown or HTML. Both modes edit the same value.
Add this field under fields in .pages.yml:
- name: body
type: rich-textContent is saved as Markdown by default. As the body field of a Markdown file, it's the text below the front matter. As any other field, it's a string:
intro: 'Welcome to **our** site.'Options
GitHub alerts
Markdown fields recognize GitHub alerts automatically. Start a quote with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION] on its own line:
> [!TIP]
> Save your changes before switching branches.Use Source to set the alert type. Its body stays editable in the visual editor. For a literal marker inside a quote, write > \[!NOTE\] in Source.
Template syntax
If your site uses Hugo shortcodes in a rich-text field, enable the preset on that field:
- name: body
type: rich-text
options:
preserve:
- hugo-shortcodesThe visual editor keeps shortcode tags such as {{< embed … >}} and {{% note %}} intact, including line breaks, URLs and quoted arguments. You can edit the prose between opening and closing tags. Switch to Source to edit the tags themselves. This works in Markdown and HTML fields.
Shortcodes can supply Markdown link and image destinations, including [Docs]({{< ref "docs/intro.md" >}}). Compact tags such as {{<highlight go>}} and escaped tags such as {{</* note */>}} are supported. Shortcodes can also appear in link labels. Common compact forms such as {{<figure src="a.png">}} and {{<br>}} keep their spelling. The editor adds a space after {{< for tags or attributes that could activate HTML, such as {{<button …>}}.
For other template syntax, specify the literal opening and closing strings. For Liquid, configure both pairs to preserve output expressions such as {{ page.title }} and control tags such as {% if page.featured %} and {% endif %}. The prose between tags stays editable:
options:
preserve:
- { start: '{{', end: '}}' }
- { start: '{%', end: '%}' }The longest opening string matches first. A custom pair ends at its first closing string, even inside quotes. Choose the Hugo preset for quoted shortcode arguments. Use Source for nested custom expressions, Liquid raw blocks, or templates containing HTML markup. Multiline Hugo tags within prose or list items preserve paragraph breaks and list indentation. Paired tags around a paragraph keep its line breaks. Use Source for exact spacing around Markdown block elements such as headings or lists.
Snippets
Snippets give editors pre-built content, such as a callout, to insert by typing / and searching for its label:
- name: body
type: rich-text
options:
html:
keep: [div.callout]
snippets:
- label: Callout
source: |
<div class="callout">
<p>Your message.</p>
</div>HTML wrappers in a snippet must also be listed in html.keep, or they're removed on insert.
HTML elements
The visual editor understands standard formatting: headings, lists, links, images, tables and so on. Other HTML, such as a <div class="callout">, is shown as a block you edit in source mode. html lets you change that per element, using CSS selectors:
options:
html:
keep: [div.callout, details, summary]
strip: [span.legacy]
drop: [.internal-note]
attributes: [data-kind]drop takes precedence over strip, and strip over keep. Rules apply when content is opened in the visual editor; switching to source and back doesn't change stored content. Scripts, event handlers, inline styles, iframes and form controls are always removed and can't be allowed.
With format: markdown, ordinary content stays Markdown and kept elements are saved as HTML inside it.
Good to know
- Markdown comments and component tags such as
<Callout />are shown as source blocks and preserved. Complex MDX, such as expressions or object props, should be edited in source mode. - Simple SVG icons display in the editor; scripts and external resources inside them are removed.