View Single Post
Old 07-25-2024, 03:08 AM   #1
banana8281982
Junior Member
banana8281982 began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jul 2024
Device: Kobo
Code syntax highlighting

So, I am writing (or trying) to write a book about C#. Nothing fancy, just checking if this is something I want to do. But...

I run into a big issue/problem/lack of knowledge. I have some text (H1, paragraphs, nothing fancy) and I want to add some C# code. Now I want to do some syntax highlighting for the distribution of PDF, but it should also look nice-ish for an ePub. And this is where I get stuck.

This is an example of what I want to write:

Code:
var query = from student in students
            where student.Age > 18
            orderby student.LastName
            select student;
I have found an example of ebooks that have very nice syntax highlighting, such as blue for the keywords, red for strings, etc. I know this can't be done my the majority of eReaders, but the fact you can also export the book to PDF is a great plus for me.

But what I do, I can't seem to get the highlighting going. Most websites I find tell me to export the text to markdown and then... Magic? Wait for it to turn into a princess? It does somewhat work, but the code is just one line; it misses indents and new lines.
Others suggest to use Prism(.js), which does somewhat work. The text is somewhat shown as I want, but the code that is too long doesn't fall onto the next line, making the reader miss the code.

Can anyone point me in the right direction?
banana8281982 is offline   Reply With Quote