Export code to HTML with syntax highlighting
You can do this with Note My. It writes real, selectable, searchable text that has kept its colouring into an HTML file — here is what lands in that file, and which route suits which destination.
A screenshot of code is the usual answer and it is a poor one. It goes soft when it is scaled, nobody can select a line out of it, nobody can search it, and it is wrong the moment the code changes. What you want is real text that has kept its colouring, so the structure survives the move out of the editor.
Note My exports that directly, in three formats. This guide covers the HTML route in detail, the RTF route for documents and slides, the two clipboard commands that skip the file altogether, and how to decide between them.
Every export happens on your Mac. Nothing is uploaded, there is no account to create, and the file you export never leaves the machine.
Export the file as HTML
-
Check the file is coloured on screen first
The export carries the colours Note My is already showing. If the code is grey on screen it will be grey in the HTML. Fifteen code languages are coloured: Swift, Python, JavaScript, TypeScript, Java, C, C++, Ruby, HTML, CSS, PHP, Rust, Go, Kotlin and Shell, alongside a Plain Text prose mode.
Our advanced language identifier names the language for you, so most files are already coloured when you open them. If the language shown is wrong or missing, click the Identify pill in the status bar. The Language Inspector reports the language in use — "Identified programming language: X" — and lets you override it from a pop-up before you confirm. Set the language before you export rather than after.
-
Choose the export
Go to File ▸ Export As ▸ HTML with Syntax Highlighting…. It sits with two siblings, RTF with Syntax Highlighting… and PDF…, and syntax colouring survives in all three.
All three sit together in the one submenu, so sending the same file to a different destination is a matter of picking a different line.
-
Name it and save it
A standard macOS save panel appears. Pick any folder you have access to, and give the page a name that will mean something to whoever opens it:
PaymentService.swift.htmltells a reader what they have in front of them before the first line loads. The name is kept safe to travel, so the page still opens after it has been emailed, put on a shared drive or handed to someone working on another system. -
Open the result in a browser
Worth doing rather than assuming. Double-click the file and you are looking at precisely what your reader will see. Check the top, a stretch in the middle where the long lines live, and the end. If something is not as you want it, change the setting and export again — an export costs you seconds, and your source file is untouched either way.
What "self-contained" means here
The HTML the app writes is one file. The stylesheet that carries the colouring is embedded in the document rather than linked from beside it, so there is no companion .css to remember, nothing to break when the file is moved, and nothing to go missing when you email it or drop it into a folder somebody else will open next month.
That matters more than it sounds. An export that depends on a second file is an export that arrives broken. This one travels as a single attachment and renders the same wherever it lands, offline included. Because the styling rides inside the document, the page looks the same on a colleague's Mac as it does on yours, and it still looks that way months later, because there is nothing sitting beside it that can go astray.
Exporting does not change your source file
The colouring you see belongs to the editor, not to your code. Opening a file and letting our syntax engine colour it does not mark the document as edited, and it does not add a single character to what is on disk. The exported page carries the colouring, and your source file stays byte-for-byte the text you typed.
That is worth stating plainly because it decides how confidently you can use this. Export the same file to HTML for a wiki, then to RTF for a report, then to PDF for an attachment, and the original is the same file at the end as it was at the start, with no diff in your next commit.
The exported page is monospaced, so the alignment you rely on — a wrapped argument list, an ASCII table in a comment — reads the same on the page as on screen. And all of it happens on your Mac: nothing is uploaded, there is no account, and the only new file anywhere is the one you named in the save panel.
Line numbers down the side
The exported page can carry a line-number gutter down the left edge. What the page contains is governed by six options in Settings ▸ Print & Export (⌘,), and all six are on by default.
| Option | Default | What it does |
|---|---|---|
| Line numbers | On | Numbers in the margin, so a reader can say "line 214" and be understood. |
| Print-friendly theme | On | A light result regardless of how the app looks on screen. |
| Header | On | A header on the page. |
| Footer | On | A footer on the page. |
| Wrap long lines | On | Long lines wrap rather than being clipped at the margin. |
| File metadata | On | Path and date information. |
The Settings window has a search field in its sidebar, so typing a few letters of an option name is faster than hunting through the panes for it. Set these once and every later export follows them.
Turn line numbers off before exporting a snippet somebody is meant to copy and run. Numbers are a help when you are discussing code and an obstacle when the reader wants to select it.
What happens to a dark theme on the way out
Working in a dark editor and publishing a dark page are different desires, and the default here is set up for the first. With the print-friendly theme on — which is the default — you get a light page whose colours are still easy to tell apart against white: a comment does not sink into the background, and a string does not go pale.
If you genuinely want the dark appearance carried through — for a slide rather than a page — turn the print-friendly theme off in Settings ▸ Print & Export and export again. Remember to turn it back on afterwards if the next export is headed for a document or a printer.
RTF, when the destination is a document or a slide
File ▸ Export As ▸ RTF with Syntax Highlighting… writes a rich-text file that keeps the same colouring. RTF is the format to reach for when the code has to live inside something else — a report, a specification, a deck — because word processors and presentation apps accept it as styled text and place it in the flow of the document rather than as an embedded object.
HTML is the format for a page, a site, or anywhere the code is the whole artefact. Both routes carry the same colouring from our syntax engine, so a snippet in a report and the same snippet on a page will not disagree with each other, and both sit in the same submenu.
Coloured code straight onto the clipboard
Two clipboard commands, Copy as HTML and Copy as RTF, put coloured code where you want it with no file in between. Switch them on once in Settings ▸ Print & Export and they take their place in the Edit menu, ready for every paste after that.
This is the route to reach for when you put code into a chat, a review or an issue tracker several times a day and would rather not leave a folder of throwaway files behind you. Select the lines you actually want rather than the whole document, copy, and the colouring travels with them — what lands at the other end is styled text a reader can select, not a picture of your code.
The Export As items need no switch at all. If you reach for this only now and then, exporting a file is the route that is ready the moment you open the menu.
The small correctness details
Two things the export handles for you, both of which you would otherwise have to do by hand:
- Angle brackets and ampersands survive. Code is full of characters a browser would otherwise read as markup and swallow. A C++ template, a shell redirect, a chunk of JSX — each renders as the text you wrote, with no repairs to make afterwards.
- Long files export. There is no size limit to work around. Our large-file engine keeps a very long document workable, so a whole source file exports the same way a short snippet does, and you get the same page at the end of it — a big one may simply take a moment longer to appear.
The export writes your document exactly as it stands and never reformats your text, so the page carries what you approved on screen and nothing you did not ask for. That makes tidying a decision you take deliberately, before you export. Our hidden-character scanner tells you when there is something worth dealing with: if the status bar reports hidden characters, clear them through Clean ▸ Clean Invisible / Special Characters…, then export. That order saves you meeting a stray zero-width character later, in a page you have already published.
Choosing between HTML, RTF and PDF
| You want | Use | Why |
|---|---|---|
| A page on a site, or a file that opens in any browser | HTML | One self-contained file with the stylesheet embedded. |
| Code inside a report, a specification or a slide | RTF | Lands as styled text in the host document's flow. |
| An attachment for someone who will read, not edit | Fixed pages, nothing to reflow. | |
| Control over paper size, orientation or a page range | ⌘P | Printing gives you the system dialogue and a preview; File ▸ Page Setup… is ⇧⌘P. |
Troubleshooting
The exported page has no colour at all
The document is in Plain Text mode, or set to a language other than the one you are writing in. Open the Language Inspector from the status-bar Identify pill, set the language yourself, confirm, and export again. A stylesheet pasted into a new untitled tab is the common case worth knowing about: choose CSS in the inspector, confirm, and the colours arrive on screen. Once they are there on screen they will be there in the export, so it is worth a glance at the editor before you go near the menu.
The saved file has a slightly different name from the one I typed
The save panel tidies a name so that the page keeps working after it has been emailed, put on a shared drive or opened on a machine running something other than macOS — an awkward character in a file name is the thing that quietly breaks a link months later. If you need an exact name for a publishing workflow, type a plain one, using letters, digits and hyphens, and it arrives as you wrote it. The contents of the page are identical either way.
Putting Copy as HTML in the Edit menu
Switch it on in Settings ▸ Print & Export and it takes its place in the Edit menu, with Copy as RTF beside it, both available in every document you open from then on. For a file rather than a clipboard, use the Export As submenu, which is ready without any setting at all.
The page is dark and hard to read
The print-friendly theme has been switched off at some point. Turn it back on and export again; it produces a light result whatever appearance the app itself is using.
Long lines are cut off at the right edge
Check "wrap long lines" in Settings ▸ Print & Export. It is on by default, so if lines are clipped it has been turned off. Word wrap in the editor window is a separate setting and does not decide this.
Indentation guides and invisible markers stay in the editor
Those are reading aids drawn over the editor window for your benefit, not characters in your document. Your text goes out as your text: the export carries the code and its colouring, and the file on disk is unchanged for the same reason. So turn the guides and markers on as freely as you like while you work, and export knowing your reader gets the clean version.
What the exported page gives your reader
The reason to export rather than screenshot is everything the person at the other end can then do with it:
- Every line is real text. A reader can select a function, copy it, paste it and run it. Browser find works across the whole page, a screen reader can read it aloud, and a search engine can index it.
- It stays sharp at any size. Zoom in on a slide, print the page, or read it on a large display, and the characters stay characters instead of dissolving the way a scaled image does.
- The page arrives complete. Its styling travels inside it, so it opens correctly on its own — from a folder, an attachment, a memory stick or a shared drive, with a connection or without one.
- The colouring matches what you approved. The page carries the same colouring you have been reading on screen, in its print-friendly form unless you switch that off, so there is nothing to reconcile after the fact.
- One source, three destinations. Send the same file to HTML for a page, RTF for a report and PDF for an attachment, and all three agree with each other, because all three take their colouring from our syntax engine.
- You decide what gets tidied first. Formatting JSON, re-indenting with our indentation engine and clearing hidden characters are commands you run on the document when you want them, so the version that ships is the version you looked at.
- Nothing is uploaded or converted in a service. The export is done entirely on your Mac, there is no account and no sign-in, and your files never leave the machine.
Frequently asked questions
Does the exported HTML need any other files to display correctly?
It stands on its own. The stylesheet is embedded in the document, so the export is a single self-contained file: move it, attach it to an email, or open it offline and it renders exactly the same.
Can I put coloured code on the clipboard without exporting a file?
Yes. Copy as HTML and Copy as RTF put coloured code straight onto the clipboard, ready to paste into a chat, a review or an issue. Switch them on in Settings ▸ Print & Export and they sit in the Edit menu for every paste after that. The three Export As items work without any switch.
Does exporting change my source file?
Your original stays byte-for-byte the text you typed. Colouring belongs to the editor and is never written into your document, and an export always writes a new file — so you can send the same source to HTML, RTF and PDF and find nothing changed on disk, and nothing to explain in your next commit.
Should I use HTML or RTF for a slide deck?
RTF. Presentation and word-processing apps accept it as styled text and place it in the document's flow. HTML suits a page or a site, where the code is the whole artefact.
Are line numbers included, and can I switch them off?
The exported page can carry a line-number gutter, and the line-numbers option in Settings ▸ Print & Export is on by default. Turn it off there when the reader is meant to copy the code rather than discuss it.
What do I need to run this?
A Mac running macOS 13.0 or later. Note My is a native, sandboxed Mac application from MAHTCA GLOBAL, with no account and no sign-in.