Other module can wan to use diff functionality. It would be nice to have an function where we can get a nice and clean output. The function _diff_body_rows almost do it but add some stuff around (like css) and is private.

Something like diff_get_diff(&$old_node, &$new_node) than return an array.

Comments

abaddon’s picture

subscribe, i might do this when i get some time, to expand on my patch here http://drupal.org/node/188253#comment-3299972 , i want this for an inline ahah diff of 2 nodes, actually a node and a node comment :-)
another approach would be to make diff_diffs_show return 100% themable output, right now ive added a couple of drupal_alter()s to remove what i dont want

gagarine’s picture

A themable output would be very nice. But I thinks we need to splite the construction of the diff (an array or object), the themable function, and some wrapper function usable outside as an API.

I also like the way of transliteration module works.

You can call transliteration_get

if (function_exists('transliteration_get')) {
   $transliterated = transliteration_get($text, $unknown, $source_langcode);
}

and the function include the things for you...

function transliteration_get($text, $unknown = '?', $source_langcode = NULL) {
  static $loaded = FALSE;
  if (!$loaded) {
    module_load_include('inc', 'transliteration');
    $loaded = TRUE;
  }
 return transliteration_process($text, $unknown, $source_langcode);
} 
yhahn’s picture

Status: Active » Fixed

http://drupal.org/cvs?commit=405772 adds two API functions for doing your own diff goodness.

/**
 * Render a diff of two strings to a $rows array suitable for use with
 * theme('table') or theme('diff_table').
 *
 * @param string $a
 *   The source string to compare from.
 * @param string $b
 *   The target string to compare to.
 * @param boolean $show_header
 *   Display diff context headers, e.g. "Line x".
 * @return
 *   Array of rows usable with theme('table').
 */
function diff_get_rows($a, $b, $show_header = FALSE) {
  ...
}


/**
 * Render a diff of two strings into HTML markup indicating additions, changes
 * and deletions.
 *
 * @param string $a
 *   The source string to compare from.
 * @param string $b
 *   The target string to compare to.
 * @return
 *   String containing HTML markup.
 */
function diff_get_inline($a, $b) {
  ...
}
gagarine’s picture

Category: feature » support
Status: Fixed » Active

Look nice to compare string but I don't get how compare two node's revisions. Can you give a small example or the right function I should use?
Thanks

xano’s picture

I have been working on atrsimilar.module, available in ATR, which uses a diff algorithm as well (but reverses the results to calculate similarity rather than difference). There are lots of applications for diff algorithms like these, but not everybody has the knowledge to create or use one from another project. If there will be one API module with a simple diff($a, $b) function, every developer will be able to diff two pieces of text, regardless of context (node body, form input) or text format (HTML, markdown, plain text).

My question: Can we split Diff 3 into an API module and separate modules for end-user functionality?

Also, for atrsimilar.module I have implemented the LCS algorithm, which is also being used for l10n_server. A quick glance at the phpwiki diff class you are using for diff.module makes me think this algorithm works similarly, but it uses A LOT more code. Can you explain what the diff.module algorithm does exactly?

xano’s picture

Title: Expose an diff function as an API » Create a separate diff API
Version: 6.x-2.0 » 6.x-2.x-dev
Category: support » feature

Updating issue status. Can we get a 6.x-3.x-dev tag?

mitchell’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Active » Fixed

This is now fixed in the 3.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.