views:

131

answers:

2

Hello World,

I need custom Markdown library for PHP which converts new lines to <br/> without the need to put double space on the end of the line, kinda like here on SO. I've been looking on the web but without success. I know I could just amend standard library but my regex skills are none.

Does anybody know about such library in existence or know how to change default behaviour easily?

Many thanks

EDIT: Dumb me, SO does not work this way, it appears to be standard Markdown behaviour. However such functionality is being used on github.com.

+1  A: 

http://php.net/manual/en/function.nl2br.php

olle
That was first solution I've checked, unfortunately it doesn't work as expected, it results in `<br/>` tags between `<li></li>` elements for example. Basically it makes every new line double. I can't downvote but this is not correct answer.
Resistante
What's wrong with `<br />` inside `<li>`? If a line feed break a paragraph, I'd expect the same behavior everywhere.
ntd
@ntd: I meant `<li>text</li> <br/> <li>text</li> <br/> <li>text</li>` Sorry if I didn't make myself clear. Furthermore string `"# Header \n new line"` will output `<h1>header</h1><br/><br/><p>new line</p>`. Hope you understand now.
Resistante
@unknown (google): yes, now I see your point.
ntd
A: 

One way is to use Text_Wiki, enabling the newline rule. I suspect other wiki parsers have this feature, maybe just not enabled by default.

ntd