- Name:
markdown
- UI: Toast UI Editor (Docs)
- Data type:
markdown string
The markdown widget provides a full fledged text editor allowing users to format text with features such as headings and blockquotes. Users can change their editing view with a handy toggle button.
Please note: If you want to use your markdown editor to fill a markdown file contents after its frontmatter, you will have to name the field body
so Static CMS recognizes it and saves the file accordingly.
Widget Options
For common options, see Common widget options.
Name 17412_3405f4-be> |
Type 17412_f666a7-8a> |
Default 17412_4ad657-93> |
Description 17412_d584d2-26> |
---|---|---|---|
default 17412_d3388e-dc> |
string 17412_a872d5-9f> |
|
Optional. The default value for the field. Accepts markdown content 17412_3e1deb-b9> |
media_folder 17412_270202-32> |
string 17412_089876-cc> | 17412_9b4ec2-c0> |
Optional. Specifies the folder path where uploaded files should be saved, relative to the base of the repo 17412_cc3dda-36> |
public_folder 17412_c74f7a-2a> |
string 17412_377bc8-9f> | 17412_029222-d1> |
Optional. Specifies the folder path where the files uploaded by the media library will be accessed, relative to the base of the built site 17412_c6999b-e4> |
media_library 17412_6de33c-d3> |
Media Library Options 17412_c33cf6-7c> |
|
Optional. Media library settings to apply when the media library is opened by the current widget. See Media Library 17412_133156-1b> |
choose_url 17412_daf570-69> |
boolean 17412_dfa004-33> |
|
Optional. When set to |
toolbar_buttons 17412_dc6315-6e> |
object 17412_2f49d6-de> |
[] 17412_efc772-a0> |
Optional. Specifies which toolbar items to show for the markdown widget. See Toolbar Customization 17412_4f7663-a4> |
show_raw 17412_efb0b8-6f> |
boolean 17412_5400e1-48> |
|
Optional. Specifies if the raw markdown editor should be shown 17412_7af7b9-b5> |
Example
name: body
label: Body
widget: markdown
name: 'body',
label: 'Body',
widget: 'markdown',
This would render as:

Please note: The markdown widget outputs a raw markdown string. Your static site generator may or may not render the markdown to HTML automatically. Consult with your static site generator’s documentation for more information about rendering markdown.
Toolbar Customization
Name 17412_898094-d7> |
Type 17412_30f592-c6> |
Default 17412_15a00a-cd> |
Description 17412_d34ce9-d3> |
---|---|---|---|
main 17412_17f927-cf> |
object 17412_02cd74-3d> |
See Main Toolbar 17412_8a025f-c6> |
Optional. A list of buttons and menus for the top level toolbar 17412_fb17c1-6b> |
empty 17412_3a083a-9d> |
object 17412_9668d7-00> |
See Empty Toolbar 17412_a93d9a-51> |
Optional. A list of buttons and menus for the popup toolbar when in an empty paragraph 17412_d0a5e6-95> |
selection 17412_10541d-dc> |
object 17412_8d7998-d8> | 17412_8c5304-55> |
Optional. A list of buttons and menus for the popup toolbar when selecting text outside of a table cell 17412_bd4677-68> |
table_empty 17412_6daeab-86> |
object 17412_5e64a9-4f> | 17412_3a8f9a-d5> |
Optional. A list of buttons and menus for the popup toolbar when in an empty table cell 17412_5568ca-47> |
table_selection 17412_de6000-8a> |
object 17412_7e6f6f-ad> | 17412_58a254-d6> |
Optional. A list of buttons and menus for the popup toolbar when selecting text in a table cell 17412_9a36a8-55> |
Options
All toolbars can be customized with a list consisting of buttons and dropdown menus.
Buttons
Buttons can be configured simply with their name. The following options are available:
blockquote
bold
code
code-block
decrease-indent
delete-column
delete-row
delete-table
file-link
font
image
increase-indent
insert-column
insert-row
insert-table
italic
ordered-list
shortcode
strikethrough
unordered-list
Menus
The following options are available for menus:
Name 17412_5d97a3-09> |
Type 17412_d76d5e-b8> |
Description 17412_9800a3-aa> |
---|---|---|
label 17412_761bb3-30> |
string 17412_5c8e57-39> |
The name and tooltip label for the menu 17412_e3fc54-a3> |
icon 17412_39601e-2d> |
string 17412_f31a77-4f> |
Optional. The icon to use for the menu. If not supplied a default add icon will be used 17412_680e32-dd> |
groups 17412_f65174-ee> |
list of groups 17412_a58ade-c7> |
A list groups of menu items. Each group is separated by a divider 17412_c8caac-d8> |
Menu Groups
The following options are available for menu groups:
Name 17412_561ae9-72> |
Type 17412_114397-11> |
Description 17412_a4d911-ee> |
---|---|---|
items 17412_ed5450-bf> |
list of strings 17412_92b903-50> |
The name of the toolbar buttons in the group. All buttons are available in menus except |
Default Values
Below are the default values for the various toolbars:
Main Toolbar
main:
- bold
- italic
- strikethrough
- code
- font
- unordered-list
- ordered-list
- decrease-indent
- increase-indent
- shortcode
- label: Insert
groups:
- items:
- blockquote
- code-block
- items:
- insert-table
- items:
- image
- file-link
main: [
'bold',
'italic',
'strikethrough',
'code',
'font',
'unordered-list',
'ordered-list',
'decrease-indent',
'increase-indent',
'shortcode',
{
label: 'Insert',
groups: [
{
items: ['blockquote', 'code-block'],
},
{
items: ['insert-table'],
},
{
items: ['image', 'file-link'],
},
],
},
];
Empty Toolbar
empty: []
empty: [];
Selection Toolbar
selection:
- bold
- italic
- strikethrough
- code
- font
- file-link
selection: ['bold', 'italic', 'strikethrough', 'code', 'font', 'file-link'];
Empty Table Cell Toolbar
table_empty:
- bold
- italic
- strikethrough
- code
- insert-row
- delete-row
- insert-column
- delete-column
- delete-table
- file-link
- image
- shortcode
table_empty: [
'bold',
'italic',
'strikethrough',
'code',
'insert-row',
'delete-row',
'insert-column',
'delete-column',
'delete-table',
'file-link',
'image',
'shortcode',
];
Table Selection Toolbar
table_selection:
- bold
- italic
- strikethrough
- code
- insert-row
- delete-row
- insert-column
- delete-column
- delete-table
- file-link
table_selection: [
'bold',
'italic',
'strikethrough',
'code',
'insert-row',
'delete-row',
'insert-column',
'delete-column',
'delete-table',
'file-link',
];
Shortcodes
Shortcodes can be added to customize the Markdown editor via registerShortcode
.
Usage
[youtube|p6h-rYSVX90]
CMS.registerShortcode('youtube', {
label: 'YouTube',
openTag: '[',
closeTag: ']',
separator: '|',
toProps: args => {
if (args.length > 0) {
return { src: args[0] };
}
return { src: '' };
},
toArgs: ({ src }) => {
return [src];
},
control: ({ src, onChange }) => {
return h('span', {}, [
h('input', {
key: 'control-input',
value: src,
onChange: event => {
onChange({ src: event.target.value });
},
}),
h(
'iframe',
{
key: 'control-preview',
width: '420',
height: '315',
src: `https://www.youtube.com/embed/${src}`,
},
'',
),
]);
},
preview: ({ src }) => {
return h(
'span',
{},
h(
'iframe',
{
width: '420',
height: '315',
src: `https://www.youtube.com/embed/${src}`,
},
'',
),
);
},
});
import CMS from '@staticcms/core';
CMS.registerShortcode('youtube', {
label: 'YouTube',
openTag: '[',
closeTag: ']',
separator: '|',
toProps: args => {
if (args.length > 0) {
return { src: args[0] };
}
return { src: '' };
},
toArgs: ({ src }) => {
return [src];
},
control: ({ src, onChange }) => {
return (
<span>
<input
key="control-input"
value={src}
onChange={event => {
onChange({ src: event.target.value });
}}
/>
<iframe
key="control-preview"
width="420"
height="315"
src={`https://web.archive.org/web/20240224001642/https://www.youtube.com/embed/${src}`}
/>
</span>
);
},
preview: ({ src }) => {
return (
<span>
<iframe width="420" height="315" src={`https://web.archive.org/web/20240224001642/https://www.youtube.com/embed/${src}`} />
</span>
);
},
});
import CMS from '@staticcms/core';
interface YouTubeShortcodeProps {
src: string;
}
CMS.registerShortcode<YouTubeShortcodeProps>('youtube', {
label: 'YouTube',
openTag: '[',
closeTag: ']',
separator: '|',
toProps: args => {
if (args.length > 0) {
return { src: args[0] };
}
return { src: '' };
},
toArgs: ({ src }) => {
return [src];
},
control: ({ src, onChange }) => {
return (
<span>
<input
key="control-input"
value={src}
onChange={event => {
onChange({ src: event.target.value });
}}
/>
<iframe
key="control-preview"
width="420"
height="315"
src={`https://web.archive.org/web/20240224001642/https://www.youtube.com/embed/${src}`}
/>
</span>
);
},
preview: ({ src }) => {
return (
<span>
<iframe width="420" height="315" src={`https://web.archive.org/web/20240224001642/https://www.youtube.com/embed/${src}`} />
</span>
);
},
});
Interacting With The Media Library
If you want to use the media library in your shortcode you will need to use the useMediaInsert
and useMediaAsset
hooks.
useMediaInsert
– Takes the current url to your media, details about your field and a callback method for when new media is uploaded. If you want to select folders instead of files, set theforFolder
variable in options.useMediaAsset
– Transforms your stored url into a usable url for displaying as a preview.
const ImageControl = ({ src, onChange, controlProps }) => {
const { collection, field, entry } = controlProps;
const handleChange = ({ path }) => {
onChange({ src: path });
};
const handleOpenMediaLibrary = useMediaInsert(
src,
{ collection: collection, field },
handleChange,
);
const assetSource = useMediaAsset(src, collection, field, entry);
return [
h('button', { type: 'button', onClick: handleOpenMediaLibrary }, 'Upload'),
h('img', { role: 'presentation', src: assetSource }),
];
};
import useMediaAsset from '@staticcms/core/lib/hooks/useMediaAsset';
import useMediaInsert from '@staticcms/core/lib/hooks/useMediaInsert';
const ImageControl = ({ src, onChange, controlProps }) => {
const { collection, field, entry } = controlProps;
const handleChange = ({ path }) => {
onChange({ src: path });
};
const handleOpenMediaLibrary = useMediaInsert(
src,
{ collection: collection, field },
handleChange,
);
const assetSource = useMediaAsset(src, collection, field, entry);
return (
<>
<button type="button" onClick={handleOpenMediaLibrary}>
Upload
</button>
<img role="presentation" src={assetSource} />
</>
);
};
import useMediaAsset from '@staticcms/core/lib/hooks/useMediaAsset';
import useMediaInsert from '@staticcms/core/lib/hooks/useMediaInsert';
import type { WidgetControlProps, MediaPath } from '@staticcms/core/interface';
import type { FC } from 'react';
const FileControl: FC<WidgetControlProps<string, MyField>> = ({ src, onChange, controlProps }) => {
const { collection, field, entry } = controlProps;
const handleChange = ({ path }: MediaPath) => {
onChange({ src: path });
};
const handleOpenMediaLibrary = useMediaInsert(src, { collection, field }, handleChange);
const assetSource = useMediaAsset(value, collection, field, entry);
return (
<>
<button type="button" onClick={handleOpenMediaLibrary}>
Upload
</button>
<img role="presentation" src={assetSource} />
</>
);
};