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

[Feature Request] Diff and Language Highlights #830

Closed
4 tasks done
jd-solanki opened this issue Jun 21, 2022 · 3 comments · Fixed by #1534
Closed
4 tasks done

[Feature Request] Diff and Language Highlights #830

jd-solanki opened this issue Jun 21, 2022 · 3 comments · Fixed by #1534
Labels
enhancement New feature or request

Comments

@jd-solanki
Copy link
Contributor

Is your feature request related to a problem? Please describe.

This is same as vuejs/vuepress#2704

That issue was for prism but VitePress uses shiki. Is it possible to achieve language highlight with diff language?

Describe the solution you'd like

na

Describe alternatives you've considered

na

Additional context

I use language highlighting for now instead of showing diff because without language highlight diff looks really bad. It takes some time for users to under what changes between two snippets but it's better highlighted.

Validations

@brc-dd
Copy link
Member

brc-dd commented Jun 21, 2022

It turns out shiki has support for this: shikijs/shiki#259. Will take some time but I think it can be integrated here. It might also simplify our highlightLines plugin.

@brc-dd brc-dd added the enhancement New feature or request label Jun 21, 2022
@jd-solanki
Copy link
Contributor Author

Glad to hear that ❤️

@brc-dd
Copy link
Member

brc-dd commented Jun 21, 2022

Okay, just tested this, gonna take back my words. That shiki support won't work for us. To support diffs with syntax highlighting, we'll need to highlight code without +, -, @@ and all that, so that syntax highlighter don't break. Then add bg to lines accordingly. This is a lot of work actually. Parsing the diff will be a challenge for sure. Also, GitHub too doesn't syntax highlights diffs. It adds the background colors though. But in our case too, we have that red/green thing, though with text color instead of background.

Consider using this for now:

```diff {2-4}
@@ -4,6 +4,5 @@
-    let foo = bar.baz([1, 2, 3]);
-    foo = foo + 1;
+    const foo = bar.baz([1, 2, 3]) + 1;
     console.log(`foo: ${foo}`);
```

It looks great even without the code being syntax highlighted:

image

I am closing this as not-planned. Might visit this later if there is enough demand. If someone from the community has a nice way of implementing this, then we may consider adding it officially.

@brc-dd brc-dd closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants