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

Diff syntax highlighting HTML spilling into content #12235

Closed
silverwind opened this issue Jul 13, 2020 · 1 comment · Fixed by #12238
Closed

Diff syntax highlighting HTML spilling into content #12235

silverwind opened this issue Jul 13, 2020 · 1 comment · Fixed by #12238

Comments

@silverwind
Copy link
Member

silverwind commented Jul 13, 2020

https://try.gitea.io/silverwind/updates/commit/9f342114d7a6bb087ff777a983d0e03b41873b07
silverwind/updates@9f34211

On Line 88 of test.js the parts nx"> and k"> related to syntax highlighting markup should not be visible. Source HTML:

<span class="<span class=" removed-code"="">nx"&gt;resultValue</span>
<span class="<span class=" added-code"="">k"&gt;typeof</span>

cc: @mrsdizzie

mrsdizzie added a commit to mrsdizzie/gitea that referenced this issue Jul 13, 2020
For diffs we first syntax highlight the before and after line then use a 3rd party diff library to find the difference in them and create a substring based on that, which we then highlight a 2nd time to show the specific difference within a line that has changed. In a specific case if the diffrence also changes the chroma class it will split in the middle of the attr and cause broken HTML:

```
<span class="nx">oldtext<span>
<span class="k">var newtext<span>
```

Will then split on

```
<span class="
```

Where the difference starts, and produce something broken like:

```
<span class="<span class="removed-code">nx"oldtext</span></span

```

Fix that by detecting when it happens and putting the HTML back together properly before highlighting the added/deleted code.

Fixes go-gitea#12235
@mrsdizzie
Copy link
Member

Good catch, this is side effect from #12205

Made a PR that should fix this if you could please test

lafriks added a commit that referenced this issue Jul 16, 2020
* Fix Syntax highlight for token change in added/deleted code

For diffs we first syntax highlight the before and after line then use a 3rd party diff library to find the difference in them and create a substring based on that, which we then highlight a 2nd time to show the specific difference within a line that has changed. In a specific case if the diffrence also changes the chroma class it will split in the middle of the attr and cause broken HTML:

```
<span class="nx">oldtext<span>
<span class="k">var newtext<span>
```

Will then split on

```
<span class="
```

Where the difference starts, and produce something broken like:

```
<span class="<span class="removed-code">nx"oldtext</span></span

```

Fix that by detecting when it happens and putting the HTML back together properly before highlighting the added/deleted code.

Fixes #12235

* fix lint

* apply fix to all diff sections. Also handle case where insert/remove starts with a closing span

* Add a test for this new code

* remove comment

Co-authored-by: Lauris BH <lauris@nix.lv>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants