BBEdit on Your Mac: Trick Text Files into HTML Syntax Coloring

BBEdit, by Bare Bones Software, is an excellent text editor for the Mac. Anyone who uses it knows that pure text files do not normally have syntax coloring. But for those users who want to use BBEdit to edit HTML files, here's how to trick a .txt file into displaying HTML syntax coloring.


Here's the problem. I and several other editors here at the Mac Observer compose our articles first in BBEdit. The file extension I use is ".txt," but it could just as well be ".text" That's so when I double click one of my draft articles, it loads into BBEdit.

Just as a reminder, the way to do that is to select the file type you have in mind, and then, in the Finder, select File > Get Info and use the popup at the bottom to define which app will, by default, open that type of file.

The bottom of the Get Info Window
for a .txt file

Of course, a perhaps unsavory alternative is to map all .html files to BBEdit (in Get Info) but that has its downside: HTML files wouldn't double-click into my browser, and I prefer to avoid that scenario.

Alternatively, if I were to create my TMO articles with a ".html" extension and open them in BBEdit, they would have the desired HTML syntax coloring, but if I were to merely double-click them (which is what I want to do), they would open in my default browser (which is Firefox.) I didn't want that scenario either, and neither may you.

The Solution

I asked Rich Siegel at Bare Bones Software if there's a way to trick my BBEdit .txt files into displaying HTML syntax coloring, and he showed me how. Eureka!

1. Use BBEdit's Preferences: BBEdit > Preferences > Language

2. At the bottom box, "Custom Extension Mappings," click the "+" below it to create a new mapping.

BBEdit Preferences > Languages

3. In the Suffix field, enter the string ".txt" without the quotes, as above.

4. Under "Language," from the popup list, select "HTML." As you can see, you could have picked any language here and its associated syntax coloring protocol.

Select desired mapping from popup.

That's all you need to do. Now, every file that ends in ".txt" will have HTML syntax coloring in it, if there is any HTML. The nice thing here is that your standard text files, without any HTML code, won't be affected.

Here's what a piece of a recent Particle Debris article draft, a .txt file, looks like now.

BBEdit text file with HTML syntax coloring.

In my case, there's no downside to this trick because I end up copying and pasting the source HTML into our publishing system. Also, as I said, there's no impact on my conventional text files, so it's a win-win.