Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Formatted Java and Python code in a document?

Community Beginner ,
Apr 18, 2024 Apr 18, 2024

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.

TOPICS
Import and export
470
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2024 Apr 18, 2024

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)

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 20, 2024 Apr 20, 2024

Thanks, I'll give this a go.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2024 Apr 20, 2024

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 20, 2024 Apr 20, 2024

This is the best solution I've found so far! Thank you. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2024 Apr 21, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2024 Apr 21, 2024
LATEST

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.

 

code_Formatting_1.pngexpand image

 

code_Formatting_2.pngexpand image

 

code_Formatting_3.pngexpand image

 

code_Formatting_4.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines