feat(requireSpaceBeforeHeadingText): option to make space between # and header text mandatory

Credit: @nikz [Nik Wakelin](https://github.com/nikz)

Closes #277
This commit is contained in:
Estevao Soares dos Santos 2016-12-17 06:01:15 +00:00
parent 143f324e4e
commit 5d19877590
11 changed files with 19 additions and 2 deletions

View File

@ -288,6 +288,8 @@ var defaultOptions = showdown.getDefaultOptions();
wrapped in two</p>
```
* **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory (since v1.5.3)
## Flavors
You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -90,6 +90,11 @@ function getDefaultOpts(simple) {
defaultValue: false,
description: 'Parses simple line breaks as <br> (GFM Style)',
type: 'boolean'
},
requireSpaceBeforeHeadingText: {
defaultValue: false,
description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
type: 'boolean'
}
};
if (simple === false) {

View File

@ -20,7 +20,8 @@ var showdown = {},
ghCodeBlocks: true,
tasklists: true,
disableForced4SpacesIndentedSublists: true,
simpleLineBreaks: true
simpleLineBreaks: true,
requireSpaceBeforeHeadingText: true
},
vanilla: getDefaultOpts(true)
};

View File

@ -40,7 +40,9 @@ showdown.subParser('headers', function (text, options, globals) {
// ...
// ###### Header 6
//
text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
var atxStyle = (options.requireSpaceBeforeHeadingText) ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;
text = text.replace(atxStyle, 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,2 @@
<h1 id="header">header</h1>
<p>#header</p>

View File

@ -0,0 +1,3 @@
# header
#header

View File

@ -39,6 +39,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({simpleLineBreaks: true});
} else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
} else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {
converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
} else {
converter = new showdown.Converter();
}