Warning
This post was published 111 days ago. The information described in this article may have changed.
I am working on a project using mdbook
, and I was thinking that instead of showing code examples, it would be cool to show diffs instead.
My main requirement was syntax highlighting for the code as well as for the changes.
I tinkered with different approaches:
One of them was generating diffs in terminal using tools like delta and difftastic and then converting them from ANSI to HTML. This would have involve creating an mdbook
preprocessor, but I was not fully satisfied with results.
mdbook
uses highlight.js for syntax highlighting. And I've found a small library that does exactly what I need: highlightjs-code-diff. There was some problem with language detection: something with the need to update the regex inside the highlight.js
code. It was totally doable, but I already found diff2html
and I liked its output more.
Finally, I decided to use diff2html
. And here is the result:
GitHub - romamik/mdbook-diff2html: Embed diff2html into mdbook
There are two issues I know:
But I am quite happy with the result anyway.
1 post - 1 participant
🏷️ rust_feed