Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented GitHub Flavoured Markdown linebreaks. No double space requir... #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MarkdownDeep/MardownDeep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ public bool ExtraMode
set;
}

// Set to true to automatically have line breaks entered by the user converted into br tags without needing double spaces
public bool EasyLineBreaks
{
get;
set;
}

// When set, all html block level elements automatically support
// markdown syntax within them.
// (Similar to Pandoc's handling of markdown in html)
Expand Down
12 changes: 11 additions & 1 deletion MarkdownDeep/SpanFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void Tokenize(string str, int start, int len)
SkipForward(2);

// Don't put br's at the end of a paragraph
if (!eof)
if (!m_Markdown.EasyLineBreaks && !eof)
{
SkipEol();
token = CreateToken(TokenType.br, end_text_token, 0);
Expand All @@ -450,6 +450,16 @@ public void Tokenize(string str, int start, int len)
break;
}

case '\n':
{
if (m_Markdown.EasyLineBreaks)
{
SkipEol();
token = CreateToken(TokenType.br, end_text_token, 0);
}
break;
}

case '\\':
{
// Special handling for escaping <autolinks>
Expand Down
13 changes: 11 additions & 2 deletions MarkdownDeepJS/MarkdownDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var MarkdownDeep = new function () {
{
SafeMode: false,
ExtraMode: false,
EasyLineBreaks: false,
MarkdownInHtml: false,
AutoHeadingIDs: false,
UrlBaseLocation: null,
Expand Down Expand Up @@ -1962,11 +1963,12 @@ var MarkdownDeep = new function () {
var re = Abbreviations == null ? /[\*\_\`\[\!\<\&\ \\]/g : null;

var ExtraMode = this.m_Markdown.ExtraMode;
var EasyLineBreaks = this.m_Markdown.EasyLineBreaks;

// Scan string
var start_text_token = p.m_position;
while (!p.eof()) {
if (re != null && !p.FindRE(re))
if (!EasyLineBreaks && re != null && !p.FindRE(re))
break;

var end_text_token = p.m_position;
Expand Down Expand Up @@ -2048,7 +2050,7 @@ var MarkdownDeep = new function () {

case ' ':
// Check for double space at end of a line
if (p.CharAtOffset(1) == ' ' && is_lineend(p.CharAtOffset(2))) {
if (!EasyLineBreaks && p.CharAtOffset(1) == ' ' && is_lineend(p.CharAtOffset(2))) {
// Yes, skip it
p.SkipForward(2);

Expand All @@ -2060,6 +2062,13 @@ var MarkdownDeep = new function () {
}
break;

case '\n':
if (EasyLineBreaks) {
p.SkipEol();
token = this.CreateToken(TokenType_br, end_text_token, 0);
}
break;

case '\\':
// Check followed by an escapable character
if (is_escapable(p.CharAtOffset(1), ExtraMode)) {
Expand Down
Loading