I’ve taken to writing documentation in Markdown as of late. It gives me the flexibility to compile the text into any format I need. I use Sublime Text as my editor for this, but today that brought up a problem.

The Spacing Problem

I was writing up a doc, and noticed that markdown was not recognizing my line breaks. I went over to the documentation, and discovered, as I usually do when going the the Daring Fireball site, a nice tidbit of info:

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Great! I went back into Sublime and added my spaces. All well and good.

Or not.

Sublime text likes to trim any additional unneeded white space upon saving files, which I normally find to be a nice feature. This very feature was stopping me in my tracks, however.

Syntax Specific Settings

In order to fix this, I needed settings for Markdown files only. I didn’t want to lose my precious whitespace trimming in other filetypes. In order to do so, make sure you have a markdown file open and go here:

Preferences > Settings – More > Syntax Specific – User

This should open a file called Markdown.sublime-settings. Add the following code:

{
    // Which file extensions go with this file type?
    "extensions":
    [
        "md",
        "mdown",
        "mdwn",
        "mmd",
        "txt"
    ],

    // Set to true to removing trailing white space on save
    "trim_trailing_white_space_on_save": false
}

Save the file, and that’s that. Now, any trailing whitespace for the above file types will live on.