debach/typography-bundle
Composer 安装命令:
composer require debach/typography-bundle
包简介
Integrates the mundschenk-at/php-typography package into Symfony applications.
README 文档
README
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).
How to use the TypographyBundle
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.
{# 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:
<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>
When you have a single string or Twig variable that you want to enhance, use the filter instead:
<h2>{{ "About... Me" | typography }}</h2>
<p>{{ twig_variable | typography }}</p>
What the TypographyBundle does
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.
| 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.
Configuration
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:
# 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.
debach/typography-bundle 适用场景与选型建议
debach/typography-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 113 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 debach/typography-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 debach/typography-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 113
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-26