DEV Community

Discussion on: I Spent the Last Year Writing a Book About Software: Here's How I Did It (and What I Learned Along the Way)

undavide profile image
Davide Barranca • Edited on

Hi, got there because of syntax highlighting. I've been self-publishing 3 books in the past (see here) first using Leanpub then going full LaTeX (crazy me).

After having pulled almost all my hair I was moderately satisfied, then for the next book I need React.js syntax highlighting and hell is breaking loose. I'm currently working with minted (I was a listings user before), and tcolorbox as well. "Working" means that I mostly have a disappointed stare and I mumble Italian curses.

For the love of god, there's no simple way out here: I'm trying to add zebra lines and it looks like I'm re-programming the Hubble telescope. Anyway... Could you please share the better-jsx-lexer you've tweaked? I guess I'm using the one you've taken as a start point.


mandiwise profile image
Mandi Wise Author

Hi Davide,

Big disclaimer: this does not work 100% yet (there are some instances where the highlighting falls apart, particularly when things get deeply nested). But this is what I managed to adapt from the fcurella/jsx-lexer:

It's on my long-term to-do list to completely rewrite this lexer from the ground-up, but I don't have the bandwidth for it at the moment.

undavide profile image
Davide Barranca

Hi Mandi,
so nice of you to share this. I've touched it just ever slightly to allow the use of dashes in the component name (e.g. <sp-button>), I've forked your gist here:
Thanks again!