![]() |
#1 |
Junior Member
![]() 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; 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? |
![]() |
![]() |
![]() |
#2 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Jul 2024
Device: Kobo
|
Since I can't seem to edit the original post, here a small update:
I found out that I can use pandoc to convert a markdown file to HTML, even with styles. It doesn't look how I want it, but it's a start. When I load the HTML (with the CSS) in a page it looks much better! But... When I convert it to EPUB and load the EPUB on my ereader, the page is blank!!! When I open the EPUB in a random reader on my pc (WIndows) it looks fine. So, what am I doing wrong now? |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,281
Karma: 6700678
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#4 |
the rook, bossing Never.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,235
Karma: 89531599
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
Do a version from a wordprocessor for ebook (extra save as docx if not editing on docx, which you shouldn't for LO Writer), then when proofed change the styles, index, footers, headers, page numbers, foot & end notes and syntax highlight (via character styles) for direct export as PDF. Automatic epub to pdf is only a convenience feature.
But I was last writing C++ docs in 1987 and C++ has changed a bit since then and also better authoring/format tools. Don't use markdown or pandoc. Markdown is for very basic input for a draft version using a plane text editor. I abandoned it years ago. Also zero direct formatting (glass typewriter syndrome), use styles for everything. Last edited by Quoth; 07-25-2024 at 10:52 AM. |
![]() |
![]() |
![]() |
Tags |
code, help calibre, writing |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can't highlight text that contains code syntax | clairvoyant | Kobo Reader | 4 | 02-04-2024 04:51 PM |
Where in the code is word highlighting for text-to-speech handled? | okabekudo | Development | 4 | 09-25-2022 10:04 AM |
dictionary/thesaurus design examples syntax code | venturacottage | ePub | 4 | 02-26-2015 01:31 PM |
Syntax Highlighting extra feature | jackie_w | Editor | 4 | 12-23-2013 03:33 AM |
How do I change the syntax colouring and increase the font size in the Code View? | nicciglen | Sigil | 5 | 02-08-2012 09:34 AM |