parisek/twig-typography

A Twig extension with typography filter

v1.0.3 2023-06-14 11:02 UTC

This package is auto-updated.

Last update: 2024-04-14 12:47:55 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