parisek/twig-typography

A Twig extension with typography filter

v1.1.0 2024-10-10 08:41 UTC

This package is auto-updated.

Last update: 2024-11-10 08:52:14 UTC


README

Uses PHP-Typography library and exposes it as Twig Extension. See class-settings.php for possible options.

  • Hyphenation — over 50 languages supported
  • Space control, including:
    • widow protection
    • gluing values to units
    • forced internal wrapping of long URLs & email addresses
  • Intelligent character replacement, including smart handling of:
    • quote marks (‘single’, “double”)
    • dashes ( – )
    • ellipses (…)
    • trademarks, copyright & service marks (™ ©)
    • math symbols (5×5×5=53)
    • fractions (116)
    • ordinal suffixes (1st, 2nd)
  • CSS hooks for styling:
    • ampersands,
    • uppercase words,
    • numbers,
    • initial quotes & guillemets.

Installation

Twig Typography Extension can be easily installed using composer

composer require parisek/twig-typography

Usage

$twig = new Twig_Environment($loader);
$twig->addExtension(new Parisek\Twig\TypographyExtension(__DIR__ . '/typography.yml'));

Template

{{ title|typography }}
<h1>{{ "Lorem Ipsum"|typography }}</h1>
{{ title|typography({'set_dewidow': FALSE}) }}
{% typography %}
  <h1>Lorem Ipsum</h1>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper semper nunc, a hendrerit leo auctor ultricies.
  </p>
{% endtypography %}

Inspiration