Skip to content

Markdown

Markdown components are Input Fields that provide a rich text editing experience with a formatting toolbar and an optional live preview panel. The toolbar lets users apply common markdown formatting (headings, bold, italic, quotes, links, lists) without needing to remember the syntax.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
},
],
});

The Markdown component requires a markdown parser to power its live preview. Since the parser is a third-party dependency, it is not bundled with the component. Instead, you provide it at the form level via the dependencies property, keeping the core library decoupled from any specific parser.

Pass dependencies as a property on the form component itself, not inside the widget’s props:

import snarkdown from 'snarkdown';
import { Dependencies } from '@golemui/gui-shared';
const deps: Dependencies = {
markdown: {
parse: (md: string) => snarkdown(md),
},
};
<GolemForm
formDef={formDef}
data={formData}
dependencies={deps}
...
/>

Use these props to customize your Markdown component.

proptypedescription
placeholderstringA placeholder text to display when the editor has no value
hintstringA description to display below the editor
counterModestringMode for the character counter if maxLength is set, possible values are remaining (default) or current
minimumHeightnumberMinimum height of the editor in pixels, defaults to 120
autoGrowbooleanIf true, the editor will automatically expand its height as the user types
defaultOpenPreviewbooleanIf true, the split view preview panel is open by default
toolsMarkdownButtons[]An array of toolbar buttons to display. Defaults to all buttons
headingTitlestringTooltip for the heading button
boldTitlestringTooltip for the bold button
italicTitlestringTooltip for the italic button
strikethroughTitlestringTooltip for the strikethrough button
quoteTitlestringTooltip for the quote button
linkTitlestringTooltip for the link button
orderedListTitlestringTooltip for the ordered list button
unorderedListTitlestringTooltip for the unordered list button
splitViewTitlestringTooltip for the split view button
autocompletestring'on', 'off', or a space-separated list of W3C autofill tokens

The tools prop lets you customize which toolbar buttons are displayed and their order. Available tokens:

TokenButtonMarkdown syntax
HHeading# Title
BBold**some text**
IItalic_some text_
QQuote> some text
LLink[some text](url)
OLOrdered list1. some text
ULUnordered list- some text
|SeparatorVisual separator only
markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
tools: ['H', 'B', 'I', 'S', '|', 'UL'],
},
},
],
});

Use the title props to customize the tooltip text for each toolbar button.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
headingTitle: 'Add heading',
boldTitle: 'Bold text',
italicTitle: 'Italic text',
strikethroughTitle: 'Strikethrough text',
quoteTitle: 'Add quote',
linkTitle: 'Insert link',
orderedListTitle: 'Ordered list',
unorderedListTitle: 'Bullet list',
splitViewTitle: 'Toggle preview',
},
},
],
});

Use the property placeholder to add a placeholder.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
placeholder: 'Write your markdown here...',
},
},
],
});

Use the property hint to add a description.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
hint: 'Supports markdown formatting.',
},
},
],
});

Use the validator maxLength to limit the number of characters and display a character counter. You can change how it counts with counterMode (remaining or current).

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'contentRemaining',
label: 'Content',
props: {
counterMode: 'remaining',
},
validator: {
type: 'string',
maxLength: 200,
required: true,
},
},
{
kind: 'input',
type: 'markdown',
path: 'contentCurrent',
label: 'Content',
props: {
counterMode: 'current',
},
validator: {
type: 'string',
maxLength: 200,
required: true,
},
},
],
});

Use the property autoGrow to allow the editor to expand automatically based on content. You can combine it with minimumHeight to set its initial size.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
autoGrow: true,
minimumHeight: 50,
},
},
],
});

Use the property defaultOpenPreview to open the split view preview panel by default when the component loads.

markdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'markdown',
path: 'content',
label: 'Content',
props: {
defaultOpenPreview: true,
},
},
],
});

Markdown editors can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-space-10Textarea and preview top padding
--gui-space-3Preview horizontal padding, toolbar padding
--gui-space-1Toolbar button padding
--gui-space-2Toolbar button gap, counter top margin
--gui-font-smCounter text font size
--gui-intent-errorCounter error color when max length is exceeded
--gui-intent-primaryActive toolbar button background
--gui-radius-mdWidget border radius
--gui-radius-smToolbar button border radius
--gui-border-defaultWidget border, toolbar border, preview border
--gui-border-focusWidget border color on focus
--gui-shadow-focusWidget box shadow on focus
--gui-text-defaultText and toolbar icon fill color
--gui-bg-surfaceToolbar background color
--gui-bg-surface-hoverToolbar button hover background

This is the anatomy of the Markdown Component in case you want to use your CSS styles.

markdown-anatomy.html
<gui-markdown>
<label for="fieldUid">
Label
<div class="gui-markdown__hint" id="fieldUid_hint">Hint</div>
</label>
<div class="gui-widget">
<nav class="gui-markdown__toolbar">
<ul>
<li><button class="gui-markdown__toolbar-button">H</button></li>
<li><button class="gui-markdown__toolbar-button">B</button></li>
<li><button class="gui-markdown__toolbar-button">I</button></li>
<li><button class="gui-markdown__toolbar-button">Q</button></li>
<li><button class="gui-markdown__toolbar-button">L</button></li>
<li><span class="gui-markdown__toolbar-separator">|</span></li>
<li><button class="gui-markdown__toolbar-button">NL</button></li>
<li><button class="gui-markdown__toolbar-button">UL</button></li>
<li><button class="gui-markdown__toolbar-button">Split</button></li>
</ul>
</nav>
<textarea
id="fieldUid"
placeholder="Custom placeholder"
aria-required="true"
aria-describedby="fieldUid_hint"
></textarea>
<section class="gui-markdown__preview">
<!-- Rendered HTML preview -->
</section>
</div>
<div class="gui-markdown--validation">
<div></div>
<div class="gui-markdown--counter">
<span>200</span>
<span> / 200</span>
</div>
</div>
</gui-markdown>