Currently, Markdown inserts a single line break only if a line is followed by two or more spaces. Otherwise, the two lines are joined.

I think this can be very useful when pasting content from another source. However, when writing content in the editor window, it is not intuitive. Even I as a web administrator forget it all the time :-)

It would be useful having an option to change this behaviour, if possible at all.

It could either be in the filter settings, in the user account settings, or, ideally, on the node edit form. Or a combination...

CommentFileSizeAuthor
#16 double_space.diff555 bytesbetz

Comments

betamos’s picture

Subscribing! And it should be in the filter settings.

(For some reason the built-in "convert line breaks..." seems to break Markdown, even though I tried different ordering.)

LarsKramer’s picture

At GitHub they have changed some of Markdown's defaults, including the handling of single line breaks:
http://github.github.com/github-flavored-markdown/

kika’s picture

this is very much needed, subsribing

danepowell’s picture

Yeah this is pretty unintuitive for new users, and like you mentioned even advanced users can get bit by it too.

justin2pin’s picture

Component: User interface » Change to library
Status: Active » Postponed

I completely agree that the usage for this is unintuitive, but this is upstream functionality and a part of the Markdown library itself. I've marked as postponed until the upstream code is addressed.

danepowell’s picture

Well since the upstream library appears to be pretty much unmaintained (I don't think the original library has been updated in 7 years!), maybe we should consider switching to the Github-maintained version, as mentioned in #2.

bartl’s picture

I just found this thread after a Google search because my colleague was complaining about the same thing...

I don't think this is easy to implement in the module, but the relevant snippet in the Github Flavored Markdown is this:

text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
  x =~ /\n{2}/ ? x : (x.strip!; x << "  \n")
end

All it does is, for "simple lines" (whatever that means), replace single newlines with 2 spaces followed by a newline each, before passing it on to Markdown. Well, I can do that...

$y = preg_replace('/^[\w\<].*\n(\n*)/me', '"\1" ? "\0" : rtrim("\0") . "  \n"', $x);

According to my tests, it does what it should do.

bartl’s picture

After I've implemented and used this on my own markdown rendering system, I noticed a bug: it puts a backslash in front of every apostrophe. Dynamic regexp replacements in PHP are tricky!

Changing the quote type in the replacement string (for eval) would appear to fix it (though I'm not sure it won't introduce yet another bug):

$y = preg_replace('/^[\w\<].*\n(\n*)/me', '\'\1\' ? \'\0\' : rtrim(\'\0\') . "  \n"', $x);
bartl’s picture

Grr, still not right! Now I get a backslash in front of the double quote.

The cause of my problem is that PHP inserts a backlash in front of single and of double quotes, before evaluating the code, but both "\"\'" and '\"\'' still contain a backslash, where the original string is "'. In other words: it's a result of a crappy design of preg_replace with //e, in PHP.

Instead of trying to work around it, eventually I figured that using preg_replace_callback, which doesn't have this problem, might be the best approach.

So, this is the code I ended up with:

$cooked = preg_replace_callback('/^[\w\<].*\n(\n*)/m', '_markdown_patch_single_line', $value);

function _markdown_patch_single_line($m) {
    if(!empty($m[1])) return $m[0];
    return rtrim($m[0]) . "  \n";
}
frjo’s picture

Status: Postponed » Closed (won't fix)

No new development on the D6 branch.

js’s picture

Has the idea of fixing markdown been abandoned?

Just recently I have been using the online project management service at teamworkpm.net. They support markdown, which was great to see, but they enhanced markdown. I asked their support where the difference came from, and was told:

The worst thing about Markdown is the default handling of paragraphs and line breaks. According to Markdown spec, a blank line constitutes a paragraph and 2 spaces after a line is a line break. While this is good for people who know Markdown, it's completely and utterly un-intuitive so we extended our flavour of Markdown to respect linebreaks and paragraphs in a more natural sense. The aim of implementing Markdown on Teamwork was to make it seamless to the end user. We noticed that most people actually write their messages similar to Markdown without even knowing about it such as lists and emphasis. There are a couple more "improvements" we've made to basic Markdown too such as auto-linking URL's etc

I would like to see the same functionality for Drupal -- somehow, and would be pleased to contribute a bit to help it happen.

Thanks, Jerry

js’s picture

Please reopen this thread.

This:
http://meta.stackoverflow.com/questions/26011/should-the-markdown-render...

links to this:
http://daringfireball.net/linked/2009/10/23/github-flavored-markdown

which is a better version, but it inserts two
where one works better on teamworkpm.net.

frjo’s picture

Title: handling of single line breaks » Add option for handling of single line breaks
Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (won't fix) » Postponed

If someone can contribute a clean looking patch for this I will take a look.

A solution like in #9 would work I think. I will not start hacking the library.

barraponto’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

I guess our current code can work with a patched library, as long as you install it to sites/all/libraries. All you have to do is fork the official PHP Markdown repo. If there's anything that should be exposed from our side (such as the settings), patches welcome.

barraponto’s picture

Status: Postponed » Closed (works as designed)

BTW, Markdown is far from dead: last commit was today, 1.3 is closing to a release. http://michelf.ca/projects/php-markdown/

Instead of making the change in this module, please try contributing upstream.

betz’s picture

StatusFileSize
new555 bytes

quick fix, but works.
Better would be to have a setting in the filter settings.
I post this as a reference.