debach/typography-bundle

将 mundschenk-at/php-typography 包集成到 Symfony 应用中。

v4.0.0 2020-05-27 16:50 UTC

This package is auto-updated.

Last update: 2024-09-28 02:40:08 UTC


README

TypographyBundle 提供了为 Symfony 应用程序轻松访问 PHP-Typography 库的功能。PHP-Typography 是 KINGTON PHP Typography 的一个活跃维护的分支,该分支已经停止维护(似乎自 2020 年以来不再可用)。

如何使用 TypographyBundle

为了增强 Twig 模板中 HTML 的排版,您可以使用过滤器 {{ someText | typography }} 和标签 {% typography %},例如:

{# template.html.twig #}
{% typography %}
    <h1>Welcome to "The 'one &amp; 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 %}

库不会修改 HTML 标签,只处理标签之间的纯文本。上述 Twig 片段的输出将是 - 注意软连字符是不可见的,但会导致长单词被分词

<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">&amp;</span>&nbsp;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&nbsp;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&nbsp;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>

当您有一个需要增强的单个字符串或 Twig 变量时,请使用过滤器

<h2>{{ "About... Me" | typography }}</h2>
<p>{{ twig_variable | typography }}</p>

TypographyBundle 做了什么

TypographyBundle 增强了 Twig 模板中文本的排版。以下表格显示了一些 HTML 文本在处理前后的示例。

对于更多示例,我过去曾引用前 项目主页,但现在似乎已经不存在了。在 新仓库 中有一些示例。

配置

您可以通过覆盖 debach_typography.php_typography_settings 的服务定义来配置此捆绑包中 PHP_Typography\Settings 的实例,由 PHP_Typography\PHP_Typography 使用。只需使用 calls 列表来配置它。

# 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%"]]

上述配置是捆绑包中使用的 PhpTypography 实例的默认配置。有关可用配置设置的文档,请参阅 KINGdesk 网站