Custom Elements allow you to wrap selected text in the editor with the HTML tag and CSS class (optionally) of your choice <element>like this</element>
. These wrappers can be given custom names and grouped in subfolders.
A huge thanks to @b0fh for guidance on this in the forum and GH discussion.
Go to [Publii sites directory] > [site folder] > input > [theme or theme-override] > config.json
Look for "customElements" (usually near the end of the file, and used for Custom Formats). If it's there, cut and paste that snippet out of the file and save it elsewhere for later. Once that done (or if you don't see it), create a new item at the end of the config.json
(likely after the "files" item):
"customElementsMode": "advanced",
"customElements": []
Place all of your custom toolbar items inside of "customElements". Here's an example:
"customElementsMode": "advanced",
"customElements":
[
{ "title": "🗨️ Messages", "items": [
{ "title": "Info", "selector": "p", "classes": "msg msg--info" },
{ "title": "Highlight", "selector": "p", "classes": "msg msg--highlight" },
{ "title": "Success", "selector": "p", "classes": "msg msg--success" },
{ "title": "Warning", "selector": "p", "classes": "msg msg--warning" }
]},
{ "title": "📦 Containers", "items": [
{
"title": "Article",
"block": "article",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Aside",
"block": "aside",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Div",
"block": "div",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Details",
"block": "details",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Details - Summary",
"inline": "summary",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Section",
"block": "section",
"wrapper": true,
"merge_siblings": true
},
{
"title": "Span",
"inline": "span",
"classes": "",
"merge_siblings": false
}
]},
{
"title": "⌨️ Keyboard Key",
"inline": "kbd",
"wrapper": true,
"merge_siblings": false
},
{
"title": "✍ Highlight",
"inline": "mark",
"wrapper": true,
"merge_siblings": true
},
{
"title": "🇦 Drop cap",
"selector": "p",
"classes": "dropcap"
},
{
"title": "Superscript¹",
"selector": "sup"
},
{
"title": "Subscript₁",
"selector": "sub"
}
]
Save this file and restart your Publii app, OR switch to another project and come back again.
https://www.tiny.cloud/docs/configure/content-formatting/#formattype
<details>
and <summary>
are a bit iffy... When you select <details>
, it will hide the text you selected. To reveal it again, save and close your post. When you re-open it, you'll be able to edit the contents of your <details>
normally.
Unfortunately, clicking on <summary>
doesn't currently work, so you'll need to edit it manually using the Source Code editor.
OR see technique number 2 below.
<span>
requires a CSS class to work. That said, I assume anyone wanting a <span>
toolbar button would have a CSS class in mind for it already anyway...
Found these tips helpful? Consider supporting my work so that I can keep going. 😊