Jump to content
Davide.Barranca

[Feat. Request] Syntax Highlighting for Code Text Frames

Recommended Posts

Hi,

technical authors – myself included – may need to design books that include programming code (C++, JavaScript, Python, you name it) with proper syntax highlighting. As discussed at length in this thread, copy & paste from the code editor (e.g. Visual Studio Code, Sublime Text, Atom, etc.) to a Text Frame doesn't work. Besides, it seems that Edit > Paste Special is a Win only feature of Publisher.

The one workaround available involves an intermediate step:

  1. Copy from the code editor.
  2. Paste to an application such as Word, Apple Pages, LibreOffice.
  3. Copy from Word/Pages/etc. and paste to Publisher text frame.

This way, as far as I get, the proper Rich Text information is preserved. Although the process works, the extra step is not only tedious, but doesn't scale up when the book contains a good deal of code samples that must be maintained in an easier, faster fashion.

It would be much handier to have the option to either select a portion of text in a Text Frame and assign the Language (programming language) that automatically triggers the appropriate syntax highlighting. Or have a Code Text Frame as a separate tool altogether, with properties, options and such.

Thank you!

Davide Barranca

Share this post


Link to post
Share on other sites
1 hour ago, Davide.Barranca said:

This way, as far as I get, the proper Rich Text information is preserved.

This depends on whether the code editor supports RTF format when copying code onto the Clipboard. If it does, the syntax coloring will be pasted in Affinity Publisher. I just tested this with Xcode 10, and it works just fine. On Windows platform Visual Studio supports RTF format with Clipboard, as does Delphi XE (via a free plug-in, from XE3 up to XE10.1).

Many code editors (like Visual Studio Code) might support only HMTL or Markdown, and it would be nice of course to have direct support for these formats, as well.

Share this post


Link to post
Share on other sites
3 hours ago, Davide.Barranca said:

As far as I understand, in this case things are easier on the Windows side of the world – on Mac, not so much :-)

I think the situation is pretty much identical, Xcode is free (as is Visual Studio on Windows platform). But it of course depends on which language you use and whether syntax highlighting is supported in that language in those IDEs. On both platforms you have Visual Studio Code, which allows copying syntax highlighting using HTML, but you typically need an intermedialy app like Word, Pages, or LibreOffice to transfer the code in RTF to InDesign or Affinity Publisher.

Share this post


Link to post
Share on other sites

I can see how this could be very useful for a small segment of users, but it may well be too much effort for Serif to implement (and for how many languages?) for a relatively small market. That's just a guess, of course.

My hunch is that this would be an case for a third-party plugin were such a thing possible. It would be nice to have some kind of plugin or extension architecture.

Share this post


Link to post
Share on other sites

Sure enough, it'd be nice to have an environment/API that would allow such third-party plugins. I can't wait!
I do acknowledge that it isn't the first feat. request that may cheer the average user, but this doesn't mean one shouldn't log a request anyway :-)

As for the user segmentation, as a technical author I am evaluating myself whether to go with Affinity or stick to the MarkDown -> LaTeX -> PDF workflow (either Pandoc, LeanPub or SoftCover). Both choices have their pros and cons...

Davide

Share this post


Link to post
Share on other sites

If a sufficiently flexible conditional formatting feature (such as the misnamed "grep formats" or whatever they are calling them these days) were to be implemented, there are probably a few languages which could be handled by those, though it wouldn't cover all of them without some form of hierarchical context between the styles, which would make development of syntax highlighting using conditional formats a possibility.

A hierarchical context between such formats does not seem like an unreasonable extension to Publisher, and conditional formats in general are wanted by many and should definitely be added, so I'm not so sure that this is too marginal to be considered as part of the main program.  I wouldn't expect them to provide the actual syntax parsing, but the facilities to create the styles ourselves seem fair enough?

As to the copy/paste from a text editor, if doing so with another program works and maintains the highlighting, then that is a VERY reasonable request for the Affinity apps - to recognize the additional clipboard format(s) involved and retain the formatting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

These are the Terms of Use you will be asked to agree to if you join the forum. | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.