debach / typography-bundle
将 mundschenk-at/php-typography 包集成到 Symfony 应用中。
v4.0.0
2020-05-27 16:50 UTC
Requires
- mundschenk-at/php-typography: ~6.6
- twig/twig: ~2.0
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 & 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>Welcome 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 personal website. I’m glad you found it — that makes you the <span class="numbers">1</span><sup class="ordinal">st</sup> visitor. I estimate that about <sup class="numerator"><span class="numbers">6</span></sup>⁄<sub class="denominator"><span class="numbers">7</span></sub> 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. <span class="numbers">26</span> April <span class="numbers">1564</span> – <span class="numbers">23</span> April <span class="numbers">1616</span>) 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 <span class="push-double"></span><span class="pull-double">“</span>Bard of Avon” (or simply <span class="push-double"></span><span class="pull-double">“</span>the Bard”). His extant works, including collaborations, consist of some <span class="numbers">39</span> plays, <span class="numbers">154</span> 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>
当您有一个需要增强的单个字符串或 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 网站。