Search by

jenswittmann / kirby-jolitypo

jenswittmann

Microtypography for Kirby: JoliTypo as a field and blocks method (quotes, dashes, ellipsis, no-break spaces between numbers and units).

Package info

github.com/jenswittmann/kirby-jolitypo

Type:kirby-plugin

pkg:composer/jenswittmann/kirby-jolitypo

Statistics

Installs: 35

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-11-28 16:07 UTC

This package is auto-updated.

Last update: 2026-11-28 16:09:49 UTC


README

Beta: this plugin is at an early stage, and its options and behavior may still change.

Microtypography for Kirby CMS, built on JoliTypo. It fixes the small things editors never get right by hand, when the page is rendered. The stored content stays exactly as it was written.

Before After
Er sagte "Hallo" - und ging. Er sagte „Hallo“ – und ging.
Der “Film” läuft. (German) Der „Film“ läuft.
Kino's, 3 x 4, Und dann... Kino’s, 3 × 4, Und dann…
10-12 Uhr 10–12 Uhr
6 %, 40,00 Euro, 5 km number and unit joined by a no-break space
z.B., § 3 Abs. 1, Art. 6, 2 Mio. Euro no line break inside (German)

Typographer, Proofreader or JoliTypo?

There are already two good microtypography plugins for Kirby, and they work differently:

  • Kirby Typographer by hana+nils fixes the HTML at render time with its own rules. If you only need quotes, dashes and the like, it may be all you need.
  • Kirby Proofreader by Grommas Dietz works in the Panel and the CLI: a button (or proofreader:review / proofreader:fix) shows typographic suggestions, and applying them writes the corrected text into the content (as unpublished changes by default).
  • This plugin exists because we needed more around numbers, units and German abbreviations, wanted a maintained library underneath, and wanted the stored content to stay untouched.

The comparison is based on the READMEs, docs and source of the projects. Where Typographer and Proofreader are concerned, it is not a test result.

Kirby Typographer Kirby Proofreader Kirby JoliTypo
When it runs at render time on demand in the Panel or CLI, rewrites the stored content at render time, content stays untouched
Based on Own rules, PHP DOMDocument Own rules (ordered, switchable, custom callbacks or regex), Kirby's SmartyPants settings for quote styles JoliTypo (JoliCode), PHP's HTML5 parser
Kirby API ->typographer() on fields and blocks, plus filter(), setAttributes(), rename(), level() and other manipulations Panel button (buttons: proofreader), proofreader:review, proofreader:fix ->jolitypo() on fields, blocks and single blocks, plus Typo::fix()
Review before applying no yes, with preview and unpublished changes no, fixes are applied while rendering
Quotes, apostrophes, ellipsis, dashes yes yes yes
×, ™, ©, ® yes optional (dimensions, symbols) yes (×, ™)
Primes (41° 43′ 32.99″) yes optional (primes) no, JoliTypo leaves foot and inch marks alone
Widows (widont) yes no, but no-break spaces after one-letter words and before short last words no
Number and unit joined by a no-break space (6 %, 5 km) not in the README not in the docs (optional currencies for prices) yes (Units)
German abbreviations and references (z. B., § 3, Art. 6) detects abbreviations optional abbreviations (German list) joins them with a no-break space (Abbreviations)
Repairs “…” in German text not in the README via the quotes rule, regional styles from the language's SmartyPants settings yes (NormalizeQuotes)
ISO dates in running text (2027-04-13) not in the README not in the docs kept as they are (SafeDash)
Long words wraps them in <span class="long-word"> for CSS hyphenation no optional soft hyphens (hyphenation, hyphenationMinLength)
Languages German, English, French German, English, French quote styles and rules for many locales
Kirby README written for Kirby 3 2.x: Kirby 6, 1.x: Kirby 5 Kirby 5 and 6
PHP no requirement set 8.3+ (2.x) 8.4+

If you are on PHP 8.3 or older, or you want widow control and primes at render time, use Typographer. If editors should see and approve every change before it lands in the content, use Proofreader. If you work with numbers, units and German legal or funding texts, want the stored text left as written, or need the HTML5 parser, use this one. You can combine Proofreader (to clean up content once) with a render-time plugin, but there is no need to run both render-time plugins: Typographer and JoliTypo fix the same characters.

Requirements

  • Kirby 5 or 6
  • PHP 8.4+ (JoliTypo 2 uses PHP's HTML5 parser, which keeps Alpine attributes like @click and SVG attributes like viewBox intact. JoliTypo 1 uses the older DOM parser and does not.)
  • PHP extensions dom and mbstring

Installation

composer require jenswittmann/kirby-jolitypo

Usage

// A field that holds HTML (writer, textarea with kirbytext, markdown)
<?= $page->text()->kirbytext()->jolitypo() ?>
<?= $page->intro()->jolitypo() ?>

// Blocks and single blocks: renders them, then fixes the HTML
<?= $page->builder()->toBlocks()->jolitypo() ?>
<?= $block->jolitypo() ?>

// Anywhere else
<?= jolitypo($html) ?>
<?= jolitypo($html, 'en') ?>

The locale comes from the current Kirby language (de becomes de_DE, en becomes en_GB, …). Pass a language code or locale to override it: ->jolitypo('fr').

The input is HTML, and so is the result. A plain-text field such as $page->title()->jolitypo() works too, but & and < come back escaped (&amp;, &lt;), so do not escape the result a second time.

Put it in one place. Call it once on the output you want fixed (a block snippet, a text field), not on a field that you pass through again.

Options

// site/config/config.php
return [
    'jenswittmann.kirby-jolitypo' => [
        'hyphenation'    => false,
        'hyphenationMinLength' => null,
        'strictUnits'    => true,
        'units'          => [],
        'locales'        => [],
        'fallbackLocale' => 'en_GB',
        'protectedTags'  => null,
        'rules'          => null,
    ],
];
Option Default
rules null JoliTypo's recommended rules for the locale (see below). A list applies to every language. A map keyed by language or locale ('de' => [...], '*' => [...]) picks per language. Entries are JoliTypo fixer names, class names or FixerInterface instances.
strictUnits true Bind a number only to a known unit. false uses JoliTypo's own Unit fixer, which binds a number to any following word.
units [] Extra units for the strict list, e.g. ['Std.', 'Tage'].
hyphenation false Adds JoliTypo's Hyphen fixer (soft hyphens).
hyphenationMinLength null Only words with at least this many characters get soft hyphens (JoliTypo's own default is 6). Set it to e.g. 18 to hyphenate only very long words.
locales [] Language code → locale, merged over the built-in map (de, en, fr, es, it, nl, pl, pt).
fallbackLocale en_GB Used for unknown languages and for single-language sites.
protectedTags null Tags that are never touched. null keeps JoliTypo's head, link, pre, code, script, style.

Default rules

JoliTypo's recommended rules for the locale, with these changes:

  • Hyphen is left out (see hyphenation).
  • Dash is replaced by SafeDash.
  • Unit is replaced by Units (see strictUnits).
  • NormalizeQuotes runs before SmartQuotes.
  • Abbreviations runs last.

The four own fixers live in JensWittmann\JoliTypo\Fixer:

  • SafeDash wraps JoliTypo's Dash. The stock fixer turns every hyphen between digits into an en dash, which would break ISO dates in running text (2027-04-13). SafeDash hides them. It also treats a hyphen between no-break spaces as a dash.
  • Units binds %, currency, km, kg, Uhr, Mio. and similar to the number before them, and nothing else.
  • NormalizeQuotes turns complete “…” pairs into „…“ for de_DE and de_AT. Straight quotes are left to SmartQuotes. A lone quote is left alone.
  • Abbreviations is German only. z.B. and z. B. become z.<nbsp>B., and §, Art., Abs., Nr., S., ca., Satz, Ziffer keep their number on the same line.

Things to know

  • Hyphens between numbers always become en dashes (10-12). That is right for ranges and wrong for phone numbers like 030-123456. ISO dates are safe.
  • JoliTypo needs complete pairs. A quote that is never closed stays as it is.
  • Output uses &nbsp; for no-break spaces and real characters for everything else.
  • Cost: every call parses the HTML once. Kirby's page cache makes this a one-time cost per page and language. Do not call it on content you cannot cache.
  • The stored content is not changed. If you also need the text itself fixed (search index, exports), run the same fixers over it yourself with Typo::fix().

Development

composer install
vendor/bin/phpunit

Thanks

Thanks to hana+nils for Kirby Typographer. It showed how microtypography fits into Kirby, and the field and blocks methods of this plugin follow its example. And thanks to JoliCode for JoliTypo, which does the actual work.

License

MIT. JoliTypo is © JoliCode, also MIT.