mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
143f324e4e
commit
5d19877590
|
@ -288,6 +288,8 @@ var defaultOptions = showdown.getDefaultOptions();
|
||||||
wrapped in two</p>
|
wrapped in two</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory (since v1.5.3)
|
||||||
|
|
||||||
## Flavors
|
## Flavors
|
||||||
|
|
||||||
You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown 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
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -90,6 +90,11 @@ function getDefaultOpts(simple) {
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
description: 'Parses simple line breaks as <br> (GFM Style)',
|
description: 'Parses simple line breaks as <br> (GFM Style)',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
requireSpaceBeforeHeadingText: {
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (simple === false) {
|
if (simple === false) {
|
||||||
|
|
|
@ -20,7 +20,8 @@ var showdown = {},
|
||||||
ghCodeBlocks: true,
|
ghCodeBlocks: true,
|
||||||
tasklists: true,
|
tasklists: true,
|
||||||
disableForced4SpacesIndentedSublists: true,
|
disableForced4SpacesIndentedSublists: true,
|
||||||
simpleLineBreaks: true
|
simpleLineBreaks: true,
|
||||||
|
requireSpaceBeforeHeadingText: true
|
||||||
},
|
},
|
||||||
vanilla: getDefaultOpts(true)
|
vanilla: getDefaultOpts(true)
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,7 +40,9 @@ showdown.subParser('headers', function (text, options, globals) {
|
||||||
// ...
|
// ...
|
||||||
// ###### Header 6
|
// ###### 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),
|
var span = showdown.subParser('spanGamut')(m2, options, globals),
|
||||||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
|
||||||
hLevel = headerLevelStart - 1 + m1.length,
|
hLevel = headerLevelStart - 1 + m1.length,
|
||||||
|
|
2
test/features/requireSpaceBeforeHeadingText.html
Normal file
2
test/features/requireSpaceBeforeHeadingText.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1 id="header">header</h1>
|
||||||
|
<p>#header</p>
|
3
test/features/requireSpaceBeforeHeadingText.md
Normal file
3
test/features/requireSpaceBeforeHeadingText.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# header
|
||||||
|
|
||||||
|
#header
|
|
@ -39,6 +39,8 @@ describe('makeHtml() features testsuite', function () {
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
} else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
|
} else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
|
||||||
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
|
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
|
||||||
|
} else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {
|
||||||
|
converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
|
||||||
} else {
|
} else {
|
||||||
converter = new showdown.Converter();
|
converter = new showdown.Converter();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user