bitandblack / typorules
为专业易读文本提供排版改进。
Requires
- php: >=8.1
- bitandblack/composer-helper: ^1.0
- bitandblack/helpers: ^1.0 || ^2.0
Requires (Dev)
- nette/robot-loader: ^4.0
- org_heigl/hyphenator: ^3.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
- symfony/console: ^7.0
- symplify/easy-coding-standard: ^12.0
Suggests
- bitandblack/indesign-characters: If you want to uses spaces for Adobe InDesign.
README
Bit&Black TypoRules
为PHP编写的专业易读文本排版改进。
目录
安装
此库可与Composer一起使用。通过运行$ composer require bitandblack/typorules
将其添加到您的项目中。
使用
Bit&Black TypoRules库附带大量规则,有助于实现更好的排版。此外,还有提供多个规则的规则集。
使用单条规则
单条规则可以这样使用
<?php use BitAndBlack\TypoRules\Rule\RemoveDuplicatedWhitespaceRule; $content = 'This is my sentence.'; $removeDuplicatedWhitespaceRule = new RemoveDuplicatedWhitespaceRule(); /** * This will return a list of all violations, that have been found. * You can use this for more control or an interactive process. */ $violations = $removeDuplicatedWhitespaceRule->getViolations($content); /** * This method will return the fixed content. In our example: * `This is my sentence.` */ $contentFixed = $removeDuplicatedWhitespaceRule->getContentFixed($content);
您可以在/examples/1-single-rule.php
下找到类似的示例。
使用规则集
使用规则集可能如下所示
<?php use BitAndBlack\TypoRules\RuleSet\EnglishRuleSet; $content = 'This is my - terribly - formatted sentence!!!!!'; $englishRuleSet = new EnglishRuleSet(); /** * This will return a list of all violations, that have been found. * You can use this for more control or an interactive process. */ $violations = $englishRuleSet->getViolations($content); /** * This method will return the fixed content. In our example: * `This is my — terribly — formatted sentence!!` */ $contentFixed = $englishRuleSet->getContentFixed($content);
您可以在/examples/2-rule-set.php
下找到类似的示例。
现有规则
有关现有规则的更多信息,请参阅/docs/rules.md。
您可以通过实现RuleInterface
来添加自定义规则。
现有规则集
有关现有规则集的更多信息,请参阅/docs/rulesets.md。
您可以通过实现RuleSetInterface
来使用自定义规则集。
自定义
您可以使用withRule
或withoutRule
方法自定义规则集并添加或删除规则。
如果您想完全自己设置规则集,可以使用CustomRuleSet
类。
显示和检查更改
每个规则返回一个违规列表,每个违规都可能说明发现的违规的确切位置。
但是,在某些情况下,您可能希望创建一个精确的diff视图。这可以通过使用CharacterDiff
类来完成。这可能看起来像这里
<?php use BitAndBlack\TypoRules\Diff\CharacterDiff; $content = 'Content before'; $contentFixed = 'Content, that has been fixed'; $diff = CharacterDiff::create()->getDiff($content, $contentFixed);
CharacterDiff
类可以用CliOutput
或HtmlOutput
类初始化,如果您没有设置其中之一,它将自行决定输出格式。
感谢
我们对JoliTypo的贡献者表示感谢,他们的贡献启发了我们开发这个库。
帮助
如果您有任何问题,请随时通过hello@bitandblack.com
联系我们。
有关Bit&Black的更多信息,请访问www.bitandblack.com。