dev-master
9999999-devIntegrates the debach/php-typography package into Symfony applications.
MIT
The Requires
Integrates the debach/php-typography package into Symfony applications.
The TypographyBundle provides easy access to the PHP-Typography library for Symfony applications. PHP-Typography is n actively maintained fork of the discontinued KINGdesk PHP Typography (seems to be no longer reachable as of 2020)., (*1)
To enhance the typography of your HTML inside a Twig template, you can use the the filter {{ someText | typography }}
and the tag {% typography %}
, i.e., (*2)
{# template.html.twig #} {% typography %} <h1>Welcome to "The 'one & only' Blog"</h1> <p> This is my personal website. I'm glad you found it - that makes you the 1st visitor. I estimate that about 6/7 of the future visitors will be typography-lovers... </p> <h2>Wikipedia about William Shakespeare</h2> <p>The following paragraph might look better with hyphenation.</p> <p> William Shakespeare (bapt. 26 April 1564 â 23 April 1616) was an English poet, playwright, and actor, widely regarded as the greatest writer in the English language and the world's greatest dramatist. He is often called England's national poet and the "Bard of Avon" (or simply "the Bard"). His extant works, including collaborations, consist of some 39 plays, 154 sonnets, two long narrative poems, and a few other verses, some of uncertain authorship. His plays have been translated into every major living language and are performed more often than those of any other playwright. </p> {% endtypography %}
The library wonât touch HTML tags and will process only plain text between tags. The output of the above Twig snippet would be â beware the soft hyphens are invisible, but will cause long words to be hyphenated:, (*3)
<h1>WelÂcome to <span class="push-double"></span>â<span class="pull-double">â</span>The <span class="push-single"></span>â<span class="pull-single">â</span>one <span class="amp">&</span> onlyâ Blogâ</h1> <p>This is my perÂsonÂal webÂsite. Iâm glad you found itâââthat makes you the <span class="numbers">1</span><sup class="ordinal">st</sup> visÂiÂtor. I estiÂmate that about <sup class="numerator"><span class="numbers">6</span></sup>â<sub class="denominator"><span class="numbers">7</span></sub> of the future visÂiÂtors will be typography-loversâŠ</p> <h2>Wikipedia about William Shakespeare</h2> <p>The folÂlowÂing paraÂgraph might look betÂter with hyphenation.</p> <p>William ShakeÂspeare (bapt. <span class="numbers">26</span> April <span class="numbers">1564</span> â <span class="numbers">23</span> April <span class="numbers">1616</span>) was an EngÂlish poet, playÂwright, and actor, wideÂly regardÂed as the greatÂest writer in the EngÂlish lanÂguage and the worldâs greatÂest dramaÂtist. He is often called EngÂlandâs nationÂal poet and the <span class="push-double"></span>â<span class="pull-double">â</span>Bard of Avonâ (or simÂply <span class="push-double"></span>â<span class="pull-double">â</span>the Bardâ). His extant works, includÂing colÂlabÂoÂraÂtions, conÂsist of some <span class="numbers">39</span> plays, <span class="numbers">154</span> sonÂnets, two long narÂraÂtive poems, and a few othÂer versÂes, some of uncerÂtain authorÂship. His plays have been transÂlatÂed into every major livÂing lanÂguage and are perÂformed more often than those of any othÂer playwright.</p>
When you have a single string or Twig variable that you want to enhance, use the filter instead:, (*4)
<h2>{{ "About... Me" | typography }}</h2> <p>{{ twig_variable | typography }}</p>
The TypographyBundle enhances the typography of the text in your Twig templates. The following table shows some examples of HTML texts before and after processing., (*5)
Before | After | Explanation |
---|---|---|
explanation | ex­pla­na­tion | Robust hyphenation with soft hyphens ­ . The browser will hyphenate words automatically based on the current line width. |
I'm waiting for "Peter" | Iâm waiting for âPeterâ | Use correct quotes and apostrophes |
... | ⊠| Use the ellipses symbol |
A flock of sparrows - some of them juveniles - alighted and sang. | A flock of sparrows â some of them juveniles â alighted and sang. | Use an em-dash instead of a hypen |
14-20 men | 14â20 men | Use an en-dash instead of a hypen in ranges |
For more examples, I used to refer to the former project homepage, but that doesnât seem to exist any longer. There are a couple of examples over at the new repository., (*6)
You can configure which instance of PHP_Typography\Settings
is used by PHP_Typography\PHP_Typography
in this bundle. Just overwrite the service definition of debach_typography.php_typography_settings
and use the calls
list to configure it:, (*7)
# Acme/DemoBundle/Resources/config/service.yml debach_typography.php_typography_settings: class: PHP_Typography\Settings calls: - [set_smart_diacritics, [false]] - [set_style_initial_quotes, [false]] - [set_hyphenation, [true]] - [set_hyphenation_language, ["%locale%"]]
The configuration given above is the default configuration for the PhpTypography
instance used by the bundle. See the KINGdesk site for a documentation of the available configuration setters., (*8)
Integrates the debach/php-typography package into Symfony applications.
MIT