Skip to content

Commit

Permalink
feat(requireSpaceBeforeHeadingText): option to make space between #
Browse files Browse the repository at this point in the history
… and header text mandatory

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

Closes #277
  • Loading branch information
tivie committed Dec 17, 2016
1 parent 143f324 commit 5d19877
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var showdown = {},
ghCodeBlocks: true,
tasklists: true,
disableForced4SpacesIndentedSublists: true,
simpleLineBreaks: true
simpleLineBreaks: true,
requireSpaceBeforeHeadingText: true
},
vanilla: getDefaultOpts(true)
};
Expand Down
4 changes: 3 additions & 1 deletion src/subParsers/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/features/requireSpaceBeforeHeadingText.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1 id="header">header</h1>
<p>#header</p>
3 changes: 3 additions & 0 deletions test/features/requireSpaceBeforeHeadingText.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# header

#header
2 changes: 2 additions & 0 deletions test/node/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 5d19877

Please sign in to comment.