Wednesday, March 18, 2015

Syntax highlighting in InDesign with presets for HTML, CSS and Javascript?


I want to use code in an inDesign document, and for that to be easily readable and pretty, I am looking for a way to get a syntax highlighting as in texteditors like notepad++, Sublime Text and Atom.


Since I need real syntax highlighting (so that, for example, different data types are depicted with different colors), it is not sufficient to assign colors to certain characters (like the brackets). Also it would be nice if I could manually change in which color certain elements are depicted, but that's not absolutely necessary. Since I want to use different code types (mostly HTML, CSS and Javascript), it would be too much work to manually assign parameters on when to highlight what, so I need something that has presets for at least the three languages mentioned above.


Of course, I could use screenshots, but I don't want that since the code should be copyable (is this even a word? LOL) ...


So, is there a way to either get the syntax highlighting from the texteditors mentioned above into inDesign or achieve a similar effect in inDesign itself?



Answer



I think the closest you could get with having something automated inside InDesign would be using Paragraph Styles with Character Styles nested inside them. However, this will be pretty limited since it expects a consistent linear form such as A B C, and depending on your code, you may often have A C C B.


To my knowledge, InDesign has no means of accomplishing the more granular syntax highlighting that would be required for this. If I absolutely had to do this natively in InDesign, I would probably assign shortcut keys to some Para/Chara Styles, and do it manually.


If you are good with code, you could probably write something to generate an IDML file for each block of code, which you could then File > Place in to your document and the appropriate syntax highlighting would come in with it (if you'd figured out a way to generate the IDML properly).



No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...