This is a port of wp-Typography for Kirby CMS. Based on the
PHP_Typography class, this plugin enhances the typography of you kirby-powered website. Think of it a more advanced alternative to the built-in
Table of Contents
- 1 Key Features
- 2 Download and Installation
- 3 Usage
- 4 Configuration
- 5 Recommended Settings for Different Languages
- 6 License
- 7 Credits
1 Key Features
- Hyphenation: Hyphenate text, very handy for justified text or languages with very long words, but also for English. Supports a large number of languages and offers fine-grained control over hyphenation.
- Smart Replacements: Includes Smart quotes (i.e. „Curly Quotes“, «Guillemets», »Chevrons« or German „Gänsefüßchen“) and smart ordinal suffixes.
- CSS Hooks: Add
<span class="[…]">tags around characters like ampersands, CAPITALIZED WORDS etc.
- Hanging Punctuation: Add the twinkle of the print-era to your site.
- Wraps URLs: Prevents long URLs from overflowing their container element on small screens.
- Smart Math: Converts mathematical symbols into their correct counterpart. E.g.
- Caching: Processing text like this plugin does is a very performance-hungry task. So the results are always cached, even if Kirby’s cache option is turned off. Cache will automatically be updated, if you change your content or update the plugin. It also comes with a Dashboard Widget, so you can flush the cache from your panel.
… and basically every other feature of wp-Typography :-)
2 Download and Installation
- PHP 5.4.0+ with multibyte extension (mbstring)
- Kirby 2.3.0+
2.2 Kirby CLI
If you’re using the Kirby CLI, you need to
cd to the root directory of your Kirby installation and run the following command:
kirby plugin:install fabianmichael/kirby-typography
This will download and copy Kirby-Typography into
2.3 Git Submodule
To install this plugin as a git submodule, execute the following command from the root of your kirby project:
$ git submodule add https://github.com/fabianmichael/kirby-typography.git site/plugins/typography
2.4 Copy and Paste
- Download the contents of this repository as ZIP-file.
- Rename the extracted folder to
typographyand copy it into the
site/plugins/directory in your Kirby project.
The plugin is enabled by default and replaces the SmartyPants parser of your Kirby installation. That means, typographic enhancements are applied to Kirbytext by default.
I tried to setup sane defaults, but you might have different requirements for your site. You can change any of the plugin’s settings in your
CSS: Not all features of the plugin need extra CSS rules, but for stuff like hanging punctuation, and character styling to work properly, it is recommended or even necessary to add the plugin’s CSS file to your site.
<?= css('assets/plugins/typography/css/typography.css') ?> to your template or – even better – copy the rules to your own stylesheet. Note, that some features like hanging punctuation should be tuned in accordance to the font you have chosen.
<?= js('assets/plugins/typography/js/dist/copyfix.min.js') ?> into to your template.
You can find a description of all available configuration options below. Customization works just like with any other configuration of Kirby. Your can read more about configuration in the Kirby docs. The default settings of this plugin were chosen for United States (US) English.
4.1 Localization for Multilingual Sites
If your Kirby installation is configured for multiple languages, you might want to use different settings for every language. In this case, you can define a common baseline of settings – shared by all languages – in your config file. Use the language files in
site/languages/ to define localized versions of your settings. Note, that in the language files, settings need to be configured with
l::set(), because those localizations are treated as language variables:
# site/config/config.php c::set('typography.class.ampersand', 'ch-amp'); // CSS classes are most likely shared across languages
# site/languages/fr.php l::set('typography.quotes.primary', 'doubleGuillemetsFrench'); // Quote styles are language-specific … l::set('typography.quotes.secondary', 'doubleCurled'); l::set('typography.hyphenation.language', 'fr'); // … and so are hyphenation rules # site/languages/de.php l::set('typography.quotes.primary', 'doubleLow9Reversed'); l::set('typography.quotes.secondary', 'singleLow9Reversed'); l::set('typography.hyphenation.language', 'de');
At the end of this document, you can find a list of recommended settings for different languages, you can use as a starting point for your own configuration.
4.2 General Options
||Defines elements to be ignored by their tag name.|
||Defines elements to be ignored by their class.|
||Defines elements to be ignored by their ID.|
4.3 Smart Quotes
||Transform straight quotes [ ' " ] to typographically correct characters.|
||Primary quotes style.|
||Secondary quotes style (for nested quotations).|
Available Styles for Smart Quotes:
||« foo »|
4.4 Smart Character Replacements
||Transform minus-hyphens [ - -- ] to contextually appropriate dashes, minus signs, and hyphens [ – — − ‐ ].|
||Sets the style of smart dashes. Alternative value:
||Force thin spaces between em & en dashes and adjoining words.|
||Force diacritics where appropriate (i.e. creme brulee becomes crème brûlée).|
||Language for diacritic replacements. Language definitions will purposefully not process words that have alternate meaning without diacritics like resume & résumé, divorce & divorcé, and expose & exposé. Currently available options are only
||Custom diacritic word replacements: Takes an associative array with the searches as keys and the replacements as values. Note, that this is case-sensitive.|
||Transform three periods [ ... ] to ellipses [ … ].|
||Transform registration marks [ (c) (r) (tm) (sm) (p) ] to proper characters [ © ® ™ ℠ ℗ ].|
||Transform ordinal suffixes [ 1st ] to pretty ordinals [ 1st ].|
||Transforms math symbols [ (2x6)/3=4 ] to correct symbols [ (2×6)÷3=4 ].|
||Transform fractions [ 1/2 ] to pretty fractions [ 1⁄2 ].|
||Transform exponents [ 3^2 ] to pretty exponents [ 32 ].|
1) In the US, the em dash — with no or very little spacing — is used for parenthetical expressions, while internationally, the en dash – with spaces – is more prevalent.
2) Some fonts support smart fractions via an OpenType feature called “frac”, but is has to be enabled manually by declaring the
font-feature-settings property in CSS. As of 2016, this is not supported by all major browsers. If you need this to work in everywhere, you should not rely on the OpenType feature and leave this setting turned on. The only exception where you really should disable this feature are monospaced fonts, because using smaller digits will break the fixed-width grid, your letters are sitting on. Details on browser support for the
frac feature can be found at The State of Web Type and Can I use.
4.5 Smart Spacing
||Enable forcing single character words to next line with the insertion of
||Inserts a no-break space into fractions to prevent wrapping [ 5 1⁄2 ].|
||Enable extra whitespace before certain punctuation marks, as is the French custom.|
||Keep values and units together [ 12 cm ].|
||Additional units to match (Kirby-Typography already recognizes a with a large amount of different units).|
||Only protect widows with
||Pull at most
||Enable wrapping after hard hyphens. Adds zero-width spaces after hard hyphens (like in “zero-width”).|
||Enable wrapping of long URLs. Adds zero-width spaces throughout the URL.|
||Enable wrapping of long emails. Adds zero-width spaces throughout the email.|
||Keep at least the last
||The parser looks for domains in your content, based on a list of all valid Top-Level-Domains (updated and cached automatically once a week). Use this option to define additional domains, the parser should look for.|
||Remove superfluous whitespace from your content.|
||Enable to use true no-break narrow space (U+202F) instead of regular no-break space (
4.6 Character Styling and Hanging Punctuation
The following options add
<span> tags around certain parts of your content to create CSS hooks, allowing you to style specific parts of your text.
||Wrap ampersands [ & ] with a
||Wrap words in ALL CAPS with a
||Wrap numbers with a
||Enable hanging punctuation. Also see the included stylesheet to see how this works.|
||Wrap initial quotes with a
||Only style initial quotes within these tags.|
||Sets the language for hyphenation rules.3|
||Do not hyphenate words with less than
||Number of letters to keep before hyphenation.|
||Number of letters to keep after hyphenation.|
||Disabling this option will disallow hyphenation of headings, even if allowed in the general scope.|
||Hyphenate words in ALL CAPS.|
||Allow hyphenation of words that begin with a capital letter. Disable to avoid hyphenation of proper nouns.|
||Allow hyphenation of the components of hyphenated compound words. Disable to disallow the hyphenation of the words making up a hyphenated compound (e.g. editor-in-chief).|
||Exception List (array): Mark allowed hyphenations with "-" (e.g. typo-graphy).|
3) Hyphenation rules are available for the following languages:
4.8 CSS Classes
Some of the options above add
<span> tags around single characters or sequences of characters, so you hook into their presentation via good ol’ CSS. If you don’t like the rather long class names I have chosen as default, feel free to change ’em to whatever you like by settings the options below:
5 Recommended Settings for Different Languages
The following recommendations are based on common typographic conventions of those languages. That does not mean, that you have to stick to them, but their make a good starting point for your own settings. Is your language missing in this list? Feel free to create an issue or pull request and I will add settings for your language to the list.
Important: If your site is multilingual, you need to define those settings in
site/languages/[language code].php, using
l::set() instead of
c::set, if you want to use different settings per language.
c::set([ 'typography.punctuation.spacing.french' => true, 'typography.dashes.style' => 'em', // cadratin ('en' for demi-cadratin) 'typography.quotes.primary' => 'doubleGuillemetsFrench', 'typography.quotes.secondary' => 'doubleCurled', 'typography.hyphenation.language' => 'fr', ]);
c::set([ 'typography.dashes.style' => 'en', 'typography.quotes.primary' => 'doubleLow9Reversed', 'typography.quotes.secondary' => 'singleLow9Reversed', 'typography.hyphenation.language' => 'de', ]);
Note: In books, sometimes Chevrons [ »foo« ] are used as quotation marks instead. Use
singleGuillemetsReversed if you prefer that style.
Kirby-Typography is released under the GNU General Public License 3.0 or later. See
LICENSE file for details (FYI: This is mandatory, because wp-Typography is also released under GPL. I would have preferred the MIT license.).
Kirby-Typography is developed and maintained by Fabian Michael.
The plugin includes or is based on the following third-party libraries:
- PHP-Typography: Copyright 2014-2016 Peter Putzer; 2012-2013 Marie Hogebrandt; 2009-2011 KINGdesk, LLC. Released under the GPL 2.0 or later. Large parts of this documentation have also been copied and/or adapted from the original WordPress plugin.
- HTML5-PHP: Released under the HTML5Lib License (see
vendors/masterminds/HTML5/LICENSEfor details and contributors)
- A List of all Top-Level-Domains, maintained by the Internet Assigned Numbers Authority (IANA) (automatically updated once a week)