studio-variable / kirby-typography
French typography for Kirby: automatic non-breaking spaces on output and a visible non-breaking space button in the writer
Package info
forge.studio-variable.com/studio-variable/kirby-typography.git
Type:kirby-plugin
pkg:composer/studio-variable/kirby-typography
Requires
- php: >=8.2
- getkirby/composer-installer: ^1.2
Requires (Dev)
- getkirby/cms: ^5.0 || ^6.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
French typography for Kirby: non-breaking spaces added automatically on output, and a non-breaking space button in the writer that keeps them visible in the Panel.
Requirements • Installation • Usage • Rules • Panel • Configuration • Credits • License
Requirements
- Kirby 5 or 6
- PHP 8.2+
Installation
Composer (recommended)
composer require studio-variable/kirby-typography
Manual installation
Download the repository and copy it to site/plugins/typography.
Usage
Call typography() on the HTML you output:
<?= $page->text()->kirbytext()->typography() ?>
<?= $page->text()->toBlocks()->typography() ?>
<?= $page->title()->esc()->typography() ?>
The field method returns a field, so it chains with other field methods. The blocks method returns the rendered HTML. StudioVariable\Typography\Typography::apply($html) works on any string.
Only text is changed: tags, attributes, comments and the content of script, style, pre, code, kbd, samp and textarea are left untouched. The stored content never changes, and applying the rules twice gives the same result.
Rules
| Rule | Effect |
|---|---|
punctuation | Narrow non-breaking space before ; ! ?, non-breaking space before : and inside « » |
numbers | Narrow non-breaking space as thousands separator (12 000), non-breaking space between a number and what follows (35 %, 3 ateliers) |
articles | Binds un, une, le, la, les, du, des, au, aux to the next word |
determiners | Binds ce, cette, mon, ma, ses, notre, leurs… to the next word |
pronouns | Binds je, tu, il, elle, on, nous, vous, ils, elles to the next word |
conjunctions | Binds mais, ou, où, et, donc, or, ni, car, que to the next word |
shortPrepositions | Binds à, y, en, de, sur, par to the next word |
prepositions | Binds après, avant, avec, chez, dans, pour, sans, sous, vers… to the next word |
shortWords | Binds any word of one or two letters to the next word |
emphasis | Keeps an em, strong, b or i of up to three words on one line |
dashes | Binds an en or em dash to the next word |
widows | Binds the last two words of a paragraph, heading, list item or cell, when they are short enough |
Spaces and already next to each other are merged into one non-breaking space.
Panel
The text block gets a non-breaking space button, also available with Cmd/Ctrl + Shift + Space. To add it to a writer field, list nbsp in its marks:
text:
type: writer
marks:
- bold
- italic
- link
- nbsp
Non-breaking spaces (and narrow ones) are shown with a light grey background in writer, textarea and text fields. The background comes from a small font limited to these two characters, so the content itself is not changed. A project's own site/blueprints/blocks/text.yml replaces the plugin's one: add nbsp to its marks to keep the button.
The font is built by tools/build-font.py (requires fonttools and brotli), which writes index.css from tools/index.css.
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
studio-variable.typography.rules | array | every rule true | Rules to apply, see Rules: set one to false to turn it off |
studio-variable.typography.exceptions | array | [] | Words never bound to the next one, case-insensitive |
return [
'studio-variable.typography.rules' => [
'shortWords' => false,
'widows' => false,
],
'studio-variable.typography.exceptions' => ['or'],
];
Translations
The button label is translated in English and French.
Credits
The word rules are inspired by ragadjust by Nathan Ford and its French adaptation ragadjustfr by Yann Trividic and Nicolas Taffin.
License
MIT License © 2026 Studio Variable