jfcherng/php-diff

Make formatting behavior of HTML renderers more flexible

ilya-levin-lokalise opened this issue · 3 comments

Basically, I'm talking about this:

        if (static::AUTO_FORMAT_CHANGES) {
            $this->formatChanges($changes);
        }

Which then comes to formatStringFromLines which calls $string = $this->htmlSafe($string);.

The thing is, I needed the library to not mutate the original string and not change the symbols to HTML entities. But there's no easy way of changing this behavior. I was using Combined renderer and couldn't override this behavior because the class is final (again - why? there're certainly the cases when you would like to hive slightly different renderer that comes out of the box).

I have a couple of proposals.

  1. Changing static::AUTO_FORMAT_CHANGES to an explicit option for HTML renderers.
  2. All HTML renderers should respect this option.
  3. Make renderer classes not final? Because there're use-cases when you want to override just a part of the behavior and these use-cases are valid.

I was using Combined renderer and couldn't override this behavior because the class is final (again - why? there're certainly the cases when you would like to hive slightly different renderer that comes out of the box).

I am reluctant to introduce potential BC break. So the simplest solution on my side: make it final. You can simply copy-paste and rename it to get a new renderer.

Changing static::AUTO_FORMAT_CHANGES to an explicit option for HTML renderers.

Could you be more specific, for example, which entity conversion is causing an issue (> becomes > is an issue? then I don't think you want a HTML renderer). As it's HTML output, I don't think conversion will causes an issue and it's technically correct as the user shouldn't care about what the output HTML source code is entity-converted or not.

closing due to inactivity.