From e6aaf3a1c9213ed749ac6613299f1a45f607a4dc Mon Sep 17 00:00:00 2001 From: Nik Wakelin Date: Wed, 20 Jul 2016 13:38:46 -0700 Subject: [PATCH] fix(headers): Ensures that Markdown headers are preceded by a space Changes subParser for headers to require a space or tab character before a header, so that ```md # Header ``` Is a valid header, whereas: ```md #Header ``` Is **not** rendered as a header. --- src/subParsers/headers.js | 2 +- test/features/#69.header-level-start.md | 6 +++--- test/issues/#nnn.headers-require-spaces.html | 3 +++ test/issues/#nnn.headers-require-spaces.md | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 test/issues/#nnn.headers-require-spaces.html create mode 100644 test/issues/#nnn.headers-require-spaces.md diff --git a/src/subParsers/headers.js b/src/subParsers/headers.js index 5a79493..d8dfc2f 100644 --- a/src/subParsers/headers.js +++ b/src/subParsers/headers.js @@ -40,7 +40,7 @@ showdown.subParser('headers', function (text, options, globals) { // ... // ###### Header 6 // - text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) { + text = text.replace(/^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) { var span = showdown.subParser('spanGamut')(m2, options, globals), hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"', hLevel = headerLevelStart - 1 + m1.length, diff --git a/test/features/#69.header-level-start.md b/test/features/#69.header-level-start.md index e7d12c6..62a24dc 100644 --- a/test/features/#69.header-level-start.md +++ b/test/features/#69.header-level-start.md @@ -1,8 +1,8 @@ -#Given +# Given -#When +# When -#Then +# Then foo === diff --git a/test/issues/#nnn.headers-require-spaces.html b/test/issues/#nnn.headers-require-spaces.html new file mode 100644 index 0000000..990c1c3 --- /dev/null +++ b/test/issues/#nnn.headers-require-spaces.html @@ -0,0 +1,3 @@ +

I am a header

+ +

#I am not a header

diff --git a/test/issues/#nnn.headers-require-spaces.md b/test/issues/#nnn.headers-require-spaces.md new file mode 100644 index 0000000..3b51b9f --- /dev/null +++ b/test/issues/#nnn.headers-require-spaces.md @@ -0,0 +1,3 @@ +# I am a header + +#I am not a header