Page MenuHomePhabricator

Rich Diff framework
Closed, DeclinedPublic


Author: felipe.sanches

This is related to enhancement bug 8954: Visual coloured math diffs.
Here, I propose a framework for a visually rich diff engine that would treat bug
8954(enh) as a particular case.

Each extension, or code that implements parsing of a particular tag (such as
<math> in the bug 8954 particular case) should register a regular expression and
a highlighter callback. If these are not registered, then the default ones would
be used.

Currently, the default regex is '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?:
(?!< \n) [^\S\n])? /xs' and the default highlighter function would be:

function default_highlighter($element){

return '<del class="diffchange">' . htmlspecialchars ( $element ) . '</del>';


For bug 8954 the highlighter function would be:

function default_highlighter($element){

return '{\color{red}' . $element . '}';


Think a bit about extensions such as WikiTeX that would use particular regexes
and highlighters for each tag implemented. This woul provide us with visual
diffs including stuff like circuit diagrams, chemestry formulas, fluxograms,
Chess & Go boards, etc.

The reason why I propose this kind of solution is because the default regex
currently used in DifferenceEngine.php is not suitable for every kind of
content. It is satisfactory for common text. But I have noticed that it is not
necessarily suitable for syntax dependent stuff (such as LaTeX, for example)
since the highlighted code must also match the syntax. The regex must split the
input into elements that could be safely applied to the highlighter function
producing a result that is also compliant to the syntax.

Version: 1.10.x
Severity: enhancement
OS: Linux
Platform: PC



Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 9:33 PM
bzimport set Reference to bz8981.
bzimport added a subscriber: Unknown Object (MLST).

robchur wrote:

How would this work with extensions such as wikidiff and wikidiff2?

felipe.sanches wrote:

If I got it right, wikidiff is an external diff engine, right? So, here we have
2 options:

  1. when using an external diff engine you won't have visual diffs, or
  2. implement something similar on the alternative external diff engine.

different diff engines => different features, right?

ayg wrote:

Different diff engines = same algorithm rewritten in C++ for speed, at least for
wikidiff2 (diffs were very slow at one point, now they're a few ms). It would
probably be kind of difficult to hook PHP functions into that, and for that
matter I assume linking C++ functions into it would require a recompile, so
making this accessible to extensions at least would be tricky for the wikidiffs
(although they could still work with core features). The extensions are at
these URLs respectively:

Nemo_bis changed the task status from Open to Stalled.May 1 2015, 9:08 AM
Nemo_bis subscribed.
Aklapper subscribed.

WikiDiff is available. If any specific functionality for specific situations is missing please file specific bug reports / enhancement requests.