I won't support markdown, bbcodes & mentions. Why?
We need to store all of the old post's content in the database rather than storing changed parts (diffs) only.
Old Post:
Lorem ipsum dolor sit amet.
````
protected function getRenderer()
{
spl_autoload_register(function ($class) {
if (file_exists($file = $this->cacheDir.'/'.$class.'.php')) {
include $file;
}
});
return $this->getComponent('renderer');
}
````
New Post:
Lorem ipsum dolor sit amet.
````
protected function getRenderer()
{
spl_autoload_register(function ($class) {
if (------------------TESTING------------------) {
include $file;
}
});
return $this->getComponent('renderer');
}
````
Now let's say we set the context to 1 lines. Comparison Output will be like this:
spl_autoload_register(function ($class) {
if (<del>file_exists($file = $this->cacheDir.'/'.$class.'.php')</del><ins>------------------TESTING------------------</ins>) {
include $file;
Calculated diff doesn't know anything about the change has been made in the code block, so we don't either. Here's another one:
Old Post:
* Batman
- Bruce Wayne
+ Joker
+ Bane
+ Deadshot
New Post:
* Batman
- Bruce Wayne
+ Joker
+ Hush
+ Deadshot
Comparison Output:
+ Joker
+ <del>Bane</del><ins>Hush</ins>
+ Deadshot
Then again, we don't know anything about indentation. What could be done is to storing full contents from both versions. What will happen if you just change a character from a post which has 1k words? Is it really necessary to show the HTML output though? I think not.
----- Addition -----
Another solution could be creating post's old and new versions programmatically from line numbers. Let's say we did it so. What will happen if the user change an URL in markdown markup? or an attribute from a BBCode?
Old Post:
[Google](google.com)
Outputs: <a href="google.com">Google</a>
New Post:
[Google](duckduckgo.com)
Outputs: <a href="duckduckgo.com">Google</a>
Comparison Result:
[Google](<ins>duckduck</ins>go<del>oogle</del>.com)
Outputs: <a href="<ins>duckduck</ins>go<del>oogle</del>.com">Google</a>
These are just simple examples and there is no only one solution for them all. Unfortunately, jfcherng's php-diff library is not supporting comparison between HTML codes and even if i could fork it, i can't promise you a lifetime repository.
I'll be listening to your suggestions if you have any.