I’ve been using Markdown Extra for formatting posts and pages for a new site I’m working on. Since I want the back-end editing to be as simple as possible, I wanted to remove the “two spaces at the end of the line” requirement when the user simply wants to insert a line break.

The change was very simple. In markdown.php I just changed line 757 from this:

$text = preg_replace('/ {2,}\n/', "<br$md_empty_element_suffix\n", $text);

To this:

$text = preg_replace('/\n/', "<br$md_empty_element_suffix\n", $text);

The original Markdown author intended the “two space” behavior so that you could be more explicit with your line breaks and make the most clean “human readable” markdown text. This is particularly nice when you want to break up some text over multiple lines for formatting like:

* This is a multi-line bullet point and I want it to be together

With my change, that has a line break after “bullet”. I expected this hack to break lots of things but so far, I haven’t noticed any negative side effects. I’d be interested to hear if anyone tries it and notices any problems.

This Post Has One Comment

  1. In version 1.1.7 of Markdown Extra, this line is now 618. The code block looks like this after my change:

        function doHardBreaks($text) {
                # Do hard breaks:
                # return preg_replace_callback('/ {2,}\n/',
                return preg_replace_callback('/\n/',     
                        array(&$this, '_doHardBreaks_callback'), $text);
        }
    

Comments are closed.

Close Menu