How do I format code snippets?

I would like to save Swift code snippets with syntax color, but thus far haven’t seen any examples. Is it possible? I searched, and read the help section on themes, but nothing pointed me forward.

If there is an example of syntax colors out there, I would love to learn more about it. Or even just pointers on how to attack this question.


Themes are the colours used by the app, and syntaxes define a set of rules about what elements are in a particular draft such that a theme can then hook into that and change the styling (including colour) of the different elements.

What you would need to look for is a Swift syntax.

No one has created and shared such a syntax in the directory, so you would need to look at setting out all the syntax rules and building your own syntax (and perhaps a theme to support it if the options you want to exploit don’t neatly fit to an existing theme).

Here’s the syntax and theme development guide:

You might want to explore the syntax highlighting developed by others so you can piece together the syntax rules you want to use. For example:

Hope that helps.

1 Like

@sylumer is right about syntaxes, but I would say upfront Drafts is designed to be a note-taking app, not a code editor. Syntax highlighting is built around being lightweight and not designed for code. You could certainly write a basic Swift highlighting definition that knows keywords and operators, but it’s never going to be comparable to what you could get in a dedicated code editor.

1 Like

Thank you both. Extremely helpful in figuring out what I will do next. Exactly the assistance I needed. (And Drafts is invaluable to me even if it isn’t well-suited for this particular purpose.)