the-turk / flarum-diff

View post edit histories in your Flarum forum.
https://discuss.flarum.org/d/22779-diff-for-flarum
MIT License
8 stars 6 forks source link

Markdown, bbcodes & mentions support #4

Closed the-turk closed 4 years ago

the-turk commented 4 years ago

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.

the-turk commented 4 years ago

We're started to store revisions as a whole instead of diffs-only as of 0.1.0-beta.7 (after a long discussion in discuss). But there are still couple of concerns about this manner. 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.

the-turk commented 4 years ago

1.0.0's "preview for all revisions" feature is kind of covering this enhancement.