aldaflux / fine-diff-bundle
FineDiff Symfony5 Bundle 实现
v2.2.1
2022-04-20 09:08 UTC
README
原始 fine diff 库
- https://github.com/webtown-php/fine-diff-bundle
- https://github.com/gorhill/PHP-FineDiff
- http://www.raymondhill.net/finediff/viewdiff-ex.php
安装
添加到 composer
在命令行中运行
$ composer require AlDaFlux/fine-diff-bundle
或者手动添加到 composer.json 中
"require": { "AlDaFlux/fine-diff-bundle": "~1.10" }
注册包
添加应用
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new AlDaFlux\FineDiffBundle\AlDaFluxPHPFineDiffBundle(), ); }
配置
可选。您可以根据需要更改默认的粒度。
# app/config/config.yml AlDaFlux_fine_diff: default_granularity: character # This is the default granularity. Alternatives: 'word', 'sentence' and 'paragraph'
使用方法
有两个 twig 函数
renderDiff()
:比较两个字符串renderHtmlTextDiff()
:比较包含 HTML 标签的两个字符串。在比较字符串之前,使用strip_tags
移除标签
{{ renderDiff(oldValue, newValue) }} {{ renderDiff(oldValue, newValue, 'word') }} {{ renderHtmlTextDiff(oldValue, newValue) }} {{ renderHtmlTextDiff(oldValue, newValue, 'sentence') }}