parisek/twig-typography
Composer 安装命令:
composer require parisek/twig-typography
包简介
A Twig extension with typography filter
关键字:
README 文档
README
Twig adapter for PHP-Typography — smart quotes, dashes, ellipses, hyphenation, widow protection, fraction glyphs, ordinal suffixes, math symbols, CSS hooks for styling.
Requirements
- PHP 8.3+
- Twig 3 or 4
- Symfony YAML 6, 7, or 8 (always installed as a hard dependency; only invoked at runtime when the constructor receives a
.ymlfile path)
Installation
composer require parisek/twig-typography
Usage
Register on a Twig environment
use Parisek\Twig\TypographyExtension; use Twig\Environment; use Twig\Loader\FilesystemLoader; $twig = new Environment(new FilesystemLoader('/path/to/templates')); // Library defaults — sane English settings. $twig->addExtension(new TypographyExtension()); // — or — load settings from a YAML file: $twig->addExtension(new TypographyExtension(__DIR__ . '/typography.yml')); // — or — pass settings as a PHP array (no filesystem): $twig->addExtension(new TypographyExtension([ 'set_smart_quotes' => true, 'set_smart_dashes' => true, ]));
In templates
{{ title|typography }}
{{ "Lorem ipsum"|typography }}
{# Override constructor defaults for one call: #}
{{ title|typography({ set_smart_dashes: false }) }}
The filter is is_safe: html — its output may contain <sup>, <span class="…">,
and similar markup, and is emitted unescaped.
Configuration
Every key in your YAML or array becomes a method call on
PHP-Typography's Settings class.
The library's full Settings(true) defaults are applied first; your
values override them.
Example: Czech (cs-CZ) settings
# typography.yml — Czech smart typography set_diacritic_language: "cs" # Smart quotes — Czech style „double" and ‚single' set_smart_quotes: TRUE set_smart_quotes_primary: "doubleLow9" # „ … " set_smart_quotes_secondary: "singleLow9" # ‚ … ' # Smart dashes — Czech/EU: en-dash with spaces (not US em-dash) set_smart_dashes: TRUE set_smart_dashes_style: "international" # Smart spacing set_single_character_word_spacing: TRUE # k/s/v/z/o/u/i/a + nbsp — required in CZ set_unit_spacing: TRUE # "5 kg" → "5 kg" set_dewidow: FALSE # last-line widow protection — bad for responsive layouts # Wrapping helpers set_hyphenation: FALSE # leave to CSS `hyphens: auto` + `lang="cs"` set_url_wrap: FALSE set_email_wrap: FALSE
What's not included
This extension exposes PHP-Typography as one Twig filter, |typography.
There's no {% typography %} block tag (despite earlier versions of this
README claiming one — the tag was never implemented in code). To apply
typography to a block of HTML, wrap it in an element and apply the filter
to the rendered string, or define a Twig macro
that encapsulates the pattern you want.
License
GPL-2.0-or-later, see LICENSE.txt.
Inspiration
parisek/twig-typography 适用场景与选型建议
parisek/twig-typography 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.15k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「typography」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 parisek/twig-typography 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 parisek/twig-typography 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 parisek/twig-typography 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
PHP SVG font parser
Add a typography test page to your silverstripe website / application.
统计信息
- 总下载量: 4.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2021-03-03