From 5d1987759078e3eb4d89031ac452550e9af6ecd6 Mon Sep 17 00:00:00 2001
From: Estevao Soares dos Santos
fjwHj%?6gt-|!p8+3@yoo(;B%15alO_3a!LPODc=4-y`~) #header
(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) {
diff --git a/src/showdown.js b/src/showdown.js
index ed64ee8..46724c1 100644
--- a/src/showdown.js
+++ b/src/showdown.js
@@ -20,7 +20,8 @@ var showdown = {},
ghCodeBlocks: true,
tasklists: true,
disableForced4SpacesIndentedSublists: true,
- simpleLineBreaks: true
+ simpleLineBreaks: true,
+ requireSpaceBeforeHeadingText: true
},
vanilla: getDefaultOpts(true)
};
diff --git a/src/subParsers/headers.js b/src/subParsers/headers.js
index 5a79493..a6018f5 100644
--- a/src/subParsers/headers.js
+++ b/src/subParsers/headers.js
@@ -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,
diff --git a/test/features/requireSpaceBeforeHeadingText.html b/test/features/requireSpaceBeforeHeadingText.html
new file mode 100644
index 0000000..2610924
--- /dev/null
+++ b/test/features/requireSpaceBeforeHeadingText.html
@@ -0,0 +1,2 @@
+header
+