rasteiner / kirby-hyphens
一种用于添加自动连字符到文本的 Kirby 字段方法。
1.0.0
2024-02-16 12:57 UTC
Requires
- php: >=8.1.0
- getkirby/composer-installer: ^1.2
- vanderlee/syllable: ^1.7
README
这是一个为 Kirby 3 和 4 提供文本内容自动连字符的插件。它使用 Vanderlee PHP Syllable 库 来执行连字符。
安装
下载
下载并将此存储库复制到 /site/plugins/kirby-hyphens。
Git 子模块
git submodule add https://github.com/rasteiner/kirby-hyphens.git site/plugins/kirby-hyphens
Composer
composer require rasteiner/kirby-hyphens
使用方法
插件提供了一个 hyphenate 字段方法,您可以在模板中使用它
<?php /* all the arguments are optional */ ?> <h1 class="text-4xl"> <?= $page->title()->html()->hyphenate( minWordLength: 5, html: true, language: 'en-us', hyphen: '­', ); ?> </h1>
配置
您可以在您的配置文件 site/config/config.php 中配置相同的参数以及更多参数
<?php // these are default values: return [ // Set to 0 to hyphenate all words // default: 5 'rasteiner.kirby-hyphens.minWordLength' => 5, // Should the text be treated as HTML? // default: true 'rasteiner.kirby-hyphens.html' => true, // Language to use for hyphenation, // see https://hyphenation.org/#languages for available languages. // Set to null to use the current Kirby language in multi-language setups. // for multi-language setups, see the language-map config option below. // default: null 'rasteiner.kirby-hyphens.language' => null, // For multi-language setups: // Map Kirby language codes to TeX hyphenation dictionary codes, since they don't always match. // see https://hyphenation.org/#languages for available codes. // default: [ 'en' => 'en-gb' ] 'rasteiner.kirby-hyphens.language-map' => [ 'de' => 'de-ch-1901' ], // hyphenation character to insert into the text // default is the soft hyphen character (­ in HTML) 'rasteiner.kirby-hyphens.hyphen' => '-', // enable cache for compiled hyphenation patterns // default is true 'rasteiner.kirby-hyphens.cache' => true, ];
许可证
此插件是开源软件,许可协议为 MIT 许可证。