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.
This commit is contained in:
Nik Wakelin 2016-07-20 13:38:46 -07:00
parent be2ffc1845
commit e6aaf3a1c9
4 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -0,0 +1,3 @@
<h1 id="iamaheader">I am a header</h1>
<p>#I am not a header</p>

View File

@ -0,0 +1,3 @@
# I am a header
#I am not a header