Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 07-25-2024, 04: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
Old 07-25-2024, 05:17 AM   #2
banana8281982
Junior Member
banana8281982 began at the beginning.
 
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?
banana8281982 is offline   Reply With Quote
Old 07-25-2024, 06:40 AM   #3
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,353
Karma: 6794938
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by banana8281982 View Post
So, what am I doing wrong now?
We would really need to see the book, so we can check the code. It's hard to diagnose anything without it.
Karellen is offline   Reply With Quote
Old 07-25-2024, 11:48 AM   #4
Quoth
the rook, bossing Never.
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 12,341
Karma: 92073397
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 11:52 AM.
Quoth is offline   Reply With Quote
Reply

Tags
code, help calibre, writing


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't highlight text that contains code syntax clairvoyant Kobo Reader 4 02-04-2024 05:51 PM
Where in the code is word highlighting for text-to-speech handled? okabekudo Development 4 09-25-2022 11:04 AM
dictionary/thesaurus design examples syntax code venturacottage ePub 4 02-26-2015 02:31 PM
Syntax Highlighting extra feature jackie_w Editor 4 12-23-2013 04:33 AM
How do I change the syntax colouring and increase the font size in the Code View? nicciglen Sigil 5 02-08-2012 10:34 AM


All times are GMT -4. The time now is 12:40 PM.


MobileRead.com is a privately owned, operated and funded community.