Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the text compare feature #22

Open
q2apro opened this issue Jul 9, 2018 · 9 comments
Open

Improving the text compare feature #22

q2apro opened this issue Jul 9, 2018 · 9 comments

Comments

@q2apro
Copy link

q2apro commented Jul 9, 2018

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
Copy link
Author

q2apro commented Jul 9, 2018

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
Copy link
Owner

svivian commented Jul 11, 2018

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
Copy link
Author

q2apro commented Jul 11, 2018

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
Copy link
Author

q2apro commented Jul 11, 2018

I would add a compare option:

  • HTML
  • text only
  • ... (Other modes)

@q2apro
Copy link
Author

q2apro commented Jul 12, 2018

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

@q2apro
Copy link
Author

q2apro commented Aug 2, 2018

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
Copy link
Author

q2apro commented Aug 2, 2018

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
Copy link
Author

q2apro commented Aug 2, 2018

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
Copy link
Author

q2apro commented Aug 2, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants