Reputation: 1357
I'm using markdown editor with Pagedown and MarkdownSharp.
There is an option "AutoNewlines" in MarkdownSharp.
I wonder how to do this in Pagedown (http://code.google.com/p/pagedown/).
Thank you!
Upvotes: 4
Views: 799
Reputation: 1406
This is now possible through the postSpanGamut
hook provided by the Markdown Converter in Pagedown. This is the code I am using:
function nl2br(text) {
// Replace new lines with <br/> tags to preserve formatting for users that are
// not used to markdown swallowing single line breaks.
return text.replace(/\n/g, " <br>\n");
}
var converter = new Converter();
converter.hooks.chain("postSpanGamut", nl2br);
It is important to use the postSpanGamut hook rather than a more general preConversion
hook as the postSpanGamut only runs on the contents of text blocks and there doesn't not mess up list formatting and other aspects of markdown.
More information in the docs.
Upvotes: 2
Reputation: 3844
the first revision of this answer included a rather naive approach which didn't work in most cases.
i ported the AutoNewLines option from MarkDownSharp to PageDown you can download it here http://code.google.com/r/marcdrexel-pagedown/
it should behave exactly as in MarkDownSharp
usage sample:
var converter = Markdown.getSanitizingConverter();
converter.autoNewLine = true;
var editor = new Markdown.Editor(converter);
editor.run();
Upvotes: 5