Formatted Java and Python code in a document?
Copy link to clipboard
Copied
Does anybody have a good workflow for getting code from github into a printed document with InDesign? We really need to preserve:
- Syntax colors
- Tabulation
- Line numbers
I am hoping somebody has solved this problem, because my Google searches have come up empty.
E.g. This Python from github. https://github.com/jamesabela/Python-RPG-Tutorial/blob/master/Object%20Oriented%20Monsters.py Will also need to do the same for Java too.
Copy link to clipboard
Copied
It's dynamically formatted by CSS - so there is no "physical" formatting info...
You could probably use GREP Styles option in the ParaStyle definition - or apply CharStyles to specific words / characters.
Found this:
https://github.com/Microsoft/vscode/issues/3518#issuecomment-253674097
For those who want an interim solution, look at Notepad++'s NppExport plugin (Copy HTML to clipboard)
Copy link to clipboard
Copied
Thanks, I'll give this a go.
Copy link to clipboard
Copied
In addition to Robert's suggestions, you may want to try to open the code in a dedicated developer tool - Xcode, VS, GitHub Desktop etc. - and export/print to PDF, then place PDF in InDesign.
Copy link to clipboard
Copied
This is the best solution I've found so far! Thank you.
Copy link to clipboard
Copied
If you need something like live text — e.g. not a snapshot of the best display you can get, capture and crop from a code editor — it seems like one of the many code formatter/highlighters could be adapted to make their output 'stable' — that is, actually apply a color span to certain elements instead of doing it only as a realtime display highlight.
That could be a tool/asset worth developing beyond your own needs, as well.
Copy link to clipboard
Copied
A few years ago I tried to create a "Photoshop javascript formatting" in InDesign CS 5 using grepstyles, but never finished. It's quite complex, but it should be possible.
 
 

