CloudCannon supports embedding rich Snippets in Markdown content when using the CloudCannon Content Editor. Once configured, Snippets in your content will be presented as blocks in rich text views, with the ability to add them as Snippets via the toolbar:
To start configuring Snippets in your Markdown content, a Snippet configuration must be imported using the _snippets_imports
key in your CloudCannon global configuration file.
Your SSG and theme may not enable the full set of Python Markdown extensions so we recommend using the include
option to import only the Snippets you're using.
Enabling snippets in the toolbar#
By default, CloudCannon will show the snippet
toolbar action in the content editor if snippets are available.
If you have already customized which options are available via _editables
in your CloudCannon config, you will need to include snippet: true
for Snippets to be available. See the Editables options documentation for more details.
Supported extensions#
Abbreviations#
The Abbreviation snippet allows you to add standard Python Markdown abbreviations to your content.
Example Config
Admonitions#
The Admonition snippet allows you to add standard Python Markdown admonitions to your content. In addition, collapsible admonitions from the Details extension are supported with the Collapsible Admonition snippet:
Example Config
Code Blocks#
CloudCannon supports both fenced codeblocks with the Code Block snippet, and inline code highlighting from the InlineHilite extension with the Inline Code snippet:
Example Config
Content Tabs#
The Tabs snippet supports creating tabbed content using the Tabbed extension.
Example Config
Footnotes#
Footnote support consists of two snippets, a footnote snippet and a footnote marker snippet. The footnote snippets lets you define the content of a footnote, and then the marker snippet allows you to reference a footnote in text.
Example Config
Icons#
The Icon snippet adds support for adding graphics with the Emoji extension.
Example Config
Arithmatex#
The Arithmatex snippets allow you to insert LaTeX style math equations which work with the Arithmatex extension.
Example Config
Reference links#
The first part of reference-style links support is the reference snippet, which allows you to create a named reference and set its URL.
You can then use that reference in links in your page using the reference link snippet, or the reference template snippet if your link title is the same as the reference name. If you're using reference links you must also include the regular link snippet.
You can also use references in images with the reference image snippet, or the reference template image snippet if image text is the same as the reference name. If you're using reference images you must also include the regular image snippet.
Custom Snippets#
Some Python extensions don't work out of the box and require additional configuration. These are the Snippet extension and the Markdown in HTML extension. By default any instance of these extensions will be escaped into either an HTML element or an Unknown Snippet, this allows an editor to move and delete these Snippets, but prevents editing of their arguments or content:
To enable editing and provide the custom snippet in the toolbar, your custom snippet must be configured using the _snippets
object in your CloudCannon global config file. CloudCannon Snippets can be built from scratch to support nearly any syntax or SSG, but importing a Snippet configuration provides a set of snippet templates for common use cases in Python Markdown.
To help illustrate configuring custom Snippets, we will first cover a few examples. First, let's look a custom glossary snippet that includes a set of abbreviations for our site:
The first thing we need to do is decide which Snippet template to use. Looking at the list of snippet templates
further down this page, we see that Python Markdown has two templates python_markdown_snippet
and python_markdown_markdown_in_html
.
Our glossary is using the Snippet extension so we should configure this snippet using the python_markdown_snippet
template. A full example configuration for this Snippet thus might look like the following:
Each snippet definition lives under a top level key, glossary
in this example. This is the unique name that CloudCannon uses to identify this snippet, but is otherwise unused in the snippet configuration itself.
We specify the template that this snippet should inherit from, and also specify that it is not an inline
snippet, so it can only be used on a line on its own.
In the preview
object we configure how this snippet is displayed while editing, using the CloudCannon card preview options.
In definitions
we need to specify some values that are required for the template we picked. For the python_markdown_snippet
template, we need to specify:
- The
snippet_name
— in this case we're configuring a snippet for theglossary.html
file.
Finally, we can specify any other keys from the CloudCannon configuration cascade here. In this example, we configure the inputs for the keys that this snippet will generate. With that in place, we can now add and edit our glossary snippet anywhere on our site.
Next, let's quickly look at a snippet using Markdown in HTML:
This time, we have an HTML figure with a class attribute of diagram and we want to be able to edit its contents in Markdown. This syntax matches the python_markdown_markdown_in_html
template.
In CloudCannon, we could configure this snippet using the following global configuration:
In this example, we want to ensure that our block has a class of diagram
but we don't want the class to be editable in CloudCannon. By using source_key
with no editor_key
we prevent
the class from being editable in CloudCannon, then the default
and allowed_values
settings ensure that all instances of this snippet have class diagram
.
Snippet options#
The following options are available for custom snippets:
The template that this snippet should inherit, out of the available Python Markdown Templates.
The variables required for the selected template.
Whether this snippet can appear inline (within a sentence). Defaults to false
, which will treat this snippet as a block-level element in the content editor.
A preview definition for displaying this snippet in the CloudCannon editor. See the preview options documentation.
Input configurations for the keys contained in this snippet. See the input configuration documentation.
Python Markdown Templates#
The first step to configure your custom snippet is to identify which snippet template to use, as each snippet template requires a set of definitions
keys to be configured. The following snippet templates are available:
Snippets#
Example config
Definitions
The file name of the snippet that you want to include.
Markdown in HTML#
Example config
Definitions
The HTML tag name of your element.
The key to use in the data panel for editing the inner contents of the element.
A list of the HTML attributes to include on your element.
Argument options#
The following options are available for named argument option objects:
Determines the key that will be used for this argument in the CloudCannon data panel.
Determines the key of the key-value pair as it appears in the shortcode.
Will default to the editor_key
if unset.
The default value that should be used for this argument when creating a new snippet in the CloudCannon editor.
Restrict this argument to parse as the specified type. Useful to ensure booleans get parsed as the boolean value, rather than a string such as "true".
One of:
- string
- boolean
- number
- array
Whether this argument is required for the shortcode. If false
, shortcodes in your templates missing this argument will not match this snippet definition.
Defaults to false
.
Whether this argument should be omitted from the output shortcode if the value is empty.
Defaults to false
.
A list of values that this argument must be in order to match this snippet definition. Allows you to match different usages of the same shortcode to separate snippet definitions based on the value of an argument.