aldaflux/fine-diff-bundle

FineDiff Symfony5 Bundle 实现

安装次数: 5,383

依赖项: 0

建议者: 0

安全性: 0

星星数: 0

关注者: 1

分支数: 2

类型:symfony-bundle

v2.2.1 2022-04-20 09:08 UTC

This package is auto-updated.

Last update: 2024-09-20 14:45:49 UTC


README

原始 fine diff 库

安装

添加到 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') }}