分享一个中文文案排版纠正器,原发于 https://laravel-china.org/articles/4532/chinese-copywriter
项目地址 https://github.com/ricoa/copywriting-correct
演示地址 https://copywriting-correct.ricoo.top
统一中文文案、排版的相关用法,降低团队成员之间的沟通成本,增强网站气质。
比较以下排版:
LeanCloud 数据存储是围绕 AVObject 进行的.每个 AVObject 都包含了与 JSON 兼容的 key-value 对应的数据。数据是 schema-free 的,你不需要在每个 AVObject 上提前指定存在哪些键,只要直接设定对应的 key-value 即可。 gitHub 是一个通过 git 进行版本控制的软件源代码托管服务,由 GitHub 公司(曾称 Logical Awesome )的开发者 Chris Wanstrath 、 PJ Hyett 和 Tom Preston-Werner 使用 Ruby on Rails 编写而成。
LeanCloud 数据存储是围绕 AVObject 进行的。每个 AVObject 都包含了与 JSON 兼容的 key-value 对应的数据。数据是 schema-free 的,你不需要在每个 AVObject 上提前指定存在哪些键,只要直接设定对应的 key-value 即可。 GitHub 是一个通过 Git 进行版本控制的软件源代码托管服务,由 GitHub 公司(曾称 Logical Awesome )的开发者 Chris Wanstrath 、 PJ Hyett 和 Tom Preston-Werner 使用 Ruby on Rails 编写而成。
很明显,第二种排版中英文有空格,标点符号也使用正确,专有名词使用正确,会让人看起来更舒服,也更专业。 本系统正是基于 中文文案排版指北(简体中文版) 进行纠正,帮助解决中英文混排的排版问题,提高文案可阅读性。
//安装开发中版本
composer require ricoa/copywriting-correct:dev-master
<?php
require_once 'vendor/autoload.php';
use Ricoa\CopyWritingCorrect\CopyWritingCorrectService;
$service=new CopyWritingCorrectService();
$text=$service->correct('在 LeanCloud 上,数据存储是围绕 AVObject 进行的。');
继承 \Ricoa\CopyWritingCorrect\Correctors\Corrector ,并实现 handle 方法。例如 ExampleCorrector.php
<?php
class ExampleCorrector extends \Ricoa\CopyWritingCorrect\Correctors\Corrector {
protected static $corrector=null;
/**
* @param string $text
*
* @return mixed
*/
public function handle($text)
{
return $text;
}
}
使用:
<?php
require_once 'vendor/autoload.php';
use Ricoa\CopyWritingCorrect\CopyWritingCorrectService;
$service=new CopyWritingCorrectService();
$service->addCorrectors([ExampleCorrector::class]);//注入纠正器
$service->resetCorrectors([ExampleCorrector::class]);//重置纠正器,也即废弃默认的纠正器
$text=$service->correct('在 LeanCloud 上,数据存储是围绕 AVObject 进行的。');
[
'0' , '1' , '2' , '3' , '4' ,
'5' , '6' , '7' , '8' , '9' ,
'A' , 'B' , 'C' , 'D' , 'E' ,
'F' , 'G' , 'H' , 'I' , 'J' ,
'K' , 'L' , 'M' , 'N' , 'O' ,
'P' , 'Q' , 'R' , 'S' , 'T' ,
'U' , 'V' , 'W' , 'X' , 'Y' ,
'Z' , 'a' , 'b' , 'c' , 'd' ,
'e' , 'f' , 'g' , 'h' , 'i' ,
'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' ,
't' , 'u' , 'v' , 'w' , 'x' ,
'y' , 'z' , '-' , ' ' , '/' ,
'%' , '#' , '@' , '&' , '<' ,
'>' , '[' , ']' , '{' , '}' ,
'\' , '|' , '+' , '=' , '_' ,
'^' , ' ̄' , '`'
];
//转
[
'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y',
'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x',
'y', 'z', '-', ' ', '/',
'%', '#', '@', '&', '<',
'>', '[', ']', '{', '}',
'\\','|', '+', '=', '_',
'^', '~', '`'
];
有什么新的想法和建议,欢迎提交 issue 或者 Pull Requests。
基于 MIT license.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.