svivian / q2a-edit-history

A Q2A plugin to store post edits
14 stars 4 forks source link

Improving the text compare feature #22

Open q2apro opened 6 years ago

q2apro commented 6 years ago

Example of recent version:

image

The plugin also considers line breaks (not the HTML ones, but ENTER key, next line) as change. I suggest to ignore those, to get a better overview.

q2apro commented 6 years ago

Content saved in "qa_edit_history":

<p>Heute gibt es mal eine Usability-Frage.</p>
<p>Wer von euch nutzt eigentlich die Möglichkeit, mit Klick oben auf den Seitentitel "Mathelounge!" direkt auf die Startseite zu gelangen?</p>
<p>Wir haben keinen Home-Button eingebaut, da wir davon ausgegangen sind, dass dies die meisten wissen.</p>
<p>Die Startseite zeigt übrigens - ähnlich wie der <a href="https://www.mathelounge.de/liveticker">Liveticker</a> - die aktuellen Ereignisse an.</p>
<p>Schöne Grüße<br>
Kai</p>

Content in the qa_posts table:

<p>Heute gibt es mal eine Usability-Frage.</p><p>Wer von euch nutzt eigentlich die Möglichkeit, mit Klick oben auf den Seitentitel &quot;Mathelounge!&quot; direkt auf die Startseite zu gelangen?</p><p>Wir haben keinen Home-Button eingebaut, da wir davon ausgegangen sind, dass dies die meisten wissen.</p><p>Die Startseite zeigt übrigens - ähnlich wie der <a href="https://www.mathelounge.de/liveticker">Liveticker</a> - die aktuellen Ereignisse an.</p><p>Schöne Grüße<br> Kai</p>
svivian commented 6 years ago

Fair point, I'll see what i can do. Is there a reason the line breaks were changed? Is that something to do with the editor?

q2apro commented 6 years ago

Yes. As far as I could see, the sceditor formats the HTML content string. Doing indents and line breaks. See the plugin in my repo if you like to test.

q2apro commented 6 years ago

I would add a compare option:

q2apro commented 6 years ago

Stackoverflow uses 3 compare modes, example: https://meta.stackoverflow.com/posts/256092/revisions

q2apro commented 6 years ago

If you do a strip_tags on both content elements, the result looks like:

image

By the way, I found out that SCEditor is doing the HTML reformating of my old posts, when an edit happens. Then the HTML tags are (backend) moved to other positions. That's why the plugin displays those changes.

q2apro commented 6 years ago

I think a solution could be to remove all line breaks and then compare!

// q2apro - need if HTML formating changes, but text content is the same
function q2apro_remove_linebreaks($string)
{
    return preg_replace( "/\r|\n/", "", $string);
}

And then:

$rev['content'] = $this->q2apro_remove_linebreaks($rev['content']);
// ...
$revisions[0]['diff_content'] = $this->q2apro_remove_linebreaks($revisions[0]['diff_content']);

Result looks good:

image

It should be checked if the post format is html, then remove line breaks. If the post format is text, then do not. 👍

q2apro commented 6 years ago

Another solution would be to remove all tabs and spaces from the beginning of each line.

But I am not sure, what is best.

The solution above is good for small texts. If it is a longer text, all is on one long line.

Maybe a text only compare (using strip_tags) would be even sufficient? - But you would not see if images were removed or formatting like bold added etc.

q2apro commented 6 years ago

Example for comparision:

Revision with recent plugin: image

Revision with Mod "q2apro_remove_linebreaks" image

Revision with Mod "q2apro_strip_tags_with_space" image

// q2apro - need if HTML formating changes, but text content is the same
function q2apro_strip_tags_with_space($string)
{
    return strip_tags(str_replace('<', ' <', $string));
}

The last one is in my opinion the easiest to read.