fater / 排版
1.0.0
2023-03-20 16:50 UTC
Requires
- php: >=8.0
Requires (Dev)
- nunomaduro/phpinsights: ^2.7
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-10 19:34:38 UTC
README
"Typography" 是一款开源 PHP 软件,可以自动格式化您的文本。它可以添加空格、纠正机械错误、替换字符和括号。该软件对从事公共用途文本生产和格式化的人很有用,如网页、宣传资料、演示文稿、简历、新闻、公共帖子等。
使用 "Typography" 可以显著减少文本校对和格式化所需的时间,因为服务会自动处理所有必要的操作。此外,"Typography" 保证校对的高度准确性和质量,有助于避免标点符号错误。
这对于专业作家、记者、广告商以及其他与文本内容相关的工作人士特别有用。
目录
要求
- PHP 8.0 或更高版本
安装
使用 composer 安装
composer require fater/typography
使用示例
要使用默认格式化规则运行 "Typography",请使用以下代码示例
<?php use Fater\Typography\Typography; $formattedText = Typography::init()->apply('Your text'); echo $formattedText;
创建自己的格式化规则
如果您想创建特殊的格式化规则,可以从基础规则模板创建类
<?php use Fater\Typography\Rules\Rule; use Your\Namespace\Rules; class YourOwnRule extends Rule { public function handle(string $text): string { // Your code modification rules $text .= ' World!'; // Return formatted text return $text; } }
将您的规则添加到默认格式化规则
将您的规则添加到要使用的处理器列表中
<?php use Fater\Typography\Typography; use Fater\Typography\TypographyRules; use Your\Namespace\Rules\YourOwnRule; $rules = TypographyRules::init()->addRules([YourOwnRule::class]); // Text will be formatted with default list of rules including your rule $formattedText = Typography::init($rules) // Set rules instance with your rule ->apply('Hello');
如果您只想使用您的规则
在开始时清除所有规则列表,将您的规则添加到处理器列表中
<?php use Fater\Typography\Typography; use Fater\Typography\TypographyRules; $rules = TypographyRules::init() ->clearAll() ->addRules([YourOwnRule::class]); // Text will be formatted only with your rule $formattedText = Typography::init($rules) // Set rules instance with your rule ->apply('Hello'); echo $formattedText;
上述示例将输出
Hello World!
路线图
v. 1.x
- 空格
- 在逗号后添加空格
- 在句号后添加空格(忽略域名)TODO:电子邮件/IP
- 删除标点符号(.,:;?!)前的空格
- 删除每个段落的空格
- 删除多余的换行符
- 字符
- 替换特殊字符(c),(r),(tm),+-,... <-, ->
- 替换破折号
- 首字母大写
v. 2.x
支持格式化纯文本和 HTML 代码
变更日志
阅读 变更日志 以了解所有产品更改。
许可
许可 MIT,更多详细信息请参见 LICENSE