Skip to content

Commit 0bc7bd1

Browse files
committed
Merge branch 'develop'
2 parents 2f6b49a + 51e4693 commit 0bc7bd1

16 files changed

+102
-25
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var defaultOptions = showdown.getDefaultOptions();
198198
199199
* **noHeaderId**: (boolean) [default false] Disable the automatic generation of header ids. Setting to true overrides **prefixHeaderId**
200200
201-
* **customizedHeaderId**: (boolean) [default false] Use text in curly braces as header id.
201+
* **customizedHeaderId**: (boolean) [default false] Use text in curly braces as header id. (since v1.7.0)
202202
Example:
203203
```
204204
## Sample header {real-id} will use real-id as id
@@ -328,7 +328,9 @@ var defaultOptions = showdown.getDefaultOptions();
328328
329329
NOTE: Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding.
330330
331-
* **openLinksInNewWindow**: (boolean) [default false] Open all links in new windows (by adding the attribute `target="_blank"` to `<a>` tags)
331+
* **openLinksInNewWindow**: (boolean) [default false] Open all links in new windows (by adding the attribute `target="_blank"` to `<a>` tags) (since v1.7.0)
332+
333+
* **backslashEscapesHTMLTags**: (boolean) [default false] Support for HTML Tag escaping. ex: `\<div>foo\</div>` (since v1.7.2)
332334
333335
**NOTE**: Please note that until version 1.6.0, all of these options are ***DISABLED*** by default in the cli tool.
334336

dist/showdown.js

+32-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.js

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ function getDefaultOpts (simple) {
125125
defaultValue: false,
126126
description: 'Open all links in new windows',
127127
type: 'boolean'
128+
},
129+
backslashEscapesHTMLTags: {
130+
defaultValue: false,
131+
description: 'Support for HTML Tag escaping. ex: \<div>foo\</div>',
132+
type: 'boolean'
128133
}
129134
};
130135
if (simple === false) {

src/subParsers/anchors.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ showdown.subParser('anchors', function (text, options, globals) {
8282
if (!showdown.helper.isString(options.ghMentionsLink)) {
8383
throw new Error('ghMentionsLink option must be a string');
8484
}
85-
var lnk = options.ghMentionsLink.replace(/\{u}/g, username);
86-
return st + '<a href="' + lnk + '">' + mentions + '</a>';
85+
var lnk = options.ghMentionsLink.replace(/\{u}/g, username),
86+
target = '';
87+
if (options.openLinksInNewWindow) {
88+
target = ' target="¨E95Eblank"';
89+
}
90+
return st + '<a href="' + lnk + '"' + target + '>' + mentions + '</a>';
8791
});
8892
}
8993

src/subParsers/hashHTMLBlocks.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,26 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
4848
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
4949
};
5050

51+
if (options.backslashEscapesHTMLTags) {
52+
// encode backslash escaped HTML tags
53+
text = text.replace(/\\<(\/?[^>]+?)>/g, function (wm, inside) {
54+
return '&lt;' + inside + '&gt;';
55+
});
56+
}
57+
58+
// hash HTML Blocks
5159
for (var i = 0; i < blockTags.length; ++i) {
5260

5361
var opTagPos,
54-
rgx1 = new RegExp('^ {0,3}<' + blockTags[i] + '\\b[^>]*>', 'im'),
62+
rgx1 = new RegExp('^ {0,3}(<' + blockTags[i] + '\\b[^>]*>)', 'im'),
5563
patLeft = '<' + blockTags[i] + '\\b[^>]*>',
5664
patRight = '</' + blockTags[i] + '>';
5765
// 1. Look for the first position of the first opening HTML tag in the text
5866
while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) {
67+
68+
// if the HTML tag is \ escaped, we need to escape it and break
69+
70+
5971
//2. Split the text in that position
6072
var subTexts = showdown.helper.splitAtIndex(text, opTagPos),
6173
//3. Match recursively

src/subParsers/lists.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,14 @@ showdown.subParser('lists', function (text, options, globals) {
9393
item = showdown.subParser('lists')(item, options, globals);
9494
item = item.replace(/\n$/, ''); // chomp(item)
9595
item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
96+
9697
// Colapse double linebreaks
9798
item = item.replace(/\n\n+/g, '\n\n');
98-
// replace double linebreaks with a placeholder
99-
item = item.replace(/\n\n/g, '¨B');
10099
if (isParagraphed) {
101100
item = showdown.subParser('paragraphs')(item, options, globals);
102101
} else {
103102
item = showdown.subParser('spanGamut')(item, options, globals);
104103
}
105-
item = item.replace(/¨B/g, '\n\n');
106104
}
107105

108106
// now we need to remove the marker (¨A)

src/subParsers/spanGamut.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
3232
// Do hard breaks
3333
if (options.simpleLineBreaks) {
3434
// GFM style hard breaks
35-
text = text.replace(/\n/g, '<br />\n');
35+
// only add line breaks if the text does not contain a block (special case for lists)
36+
if (!/\n\n¨K/.test(text)) {
37+
text = text.replace(/\n+/g, '<br />\n');
38+
}
3639
} else {
3740
// Vanilla hard breaks
3841
text = text.replace(/ +\n/g, '<br />\n');

src/subParsers/tables.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ showdown.subParser('tables', function (text, options, globals) {
2222
function parseHeaders (header, style) {
2323
var id = '';
2424
header = header.trim();
25-
if (options.tableHeaderId) {
25+
// support both tablesHeaderId and tableHeaderId due to error in documention so we don't break backwards compatibility
26+
if (options.tablesHeaderId || options.tableHeaderId) {
2627
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
2728
}
2829
header = showdown.subParser('spanGamut')(header, options, globals);
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>&lt;div&gt;foo&lt;/div&gt;</p>
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\<div>foo\</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ul>
2+
<li><p><strong>Customer</strong> – Opens the Customer List. Refer to the document “Customer Management”.</p>
3+
<ul>
4+
<li>Customer List</li>
5+
<li>New Customer</li>
6+
<li>Customer Prices</li>
7+
<li>Appointments</li></ul></li>
8+
<li><p><strong>Designer</strong> - Opens the Designer List. Refer to the document “Designer Commissions”.</p>
9+
<ul>
10+
<li>Designer List</li>
11+
<li>New Designer</li>
12+
<li>Designer Payment List</li>
13+
<li>New Designer Payment</li></ul></li>
14+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- **Customer** – Opens the Customer List. Refer to the document “Customer Management”.
2+
- Customer List
3+
- New Customer
4+
- Customer Prices
5+
- Appointments
6+
7+
- **Designer** - Opens the Designer List. Refer to the document “Designer Commissions”.
8+
- Designer List
9+
- New Designer
10+
- Designer Payment List
11+
- New Designer Payment

test/node/testsuite.features.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ describe('makeHtml() features testsuite', function () {
8080
converter = new showdown.Converter({customizedHeaderId: true});
8181
} else if (testsuite[i].name === '#378.simplifiedAutoLinks-with-excludeTrailingPunctuationFromURLs') {
8282
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
83+
} else if (testsuite[i].name === '#374.escape-html-tags') {
84+
converter = new showdown.Converter({backslashEscapesHTMLTags: true});
8385
} else if (testsuite[i].name === '#379.openLinksInNewWindow-breaks-em-markdup') {
8486
converter = new showdown.Converter({openLinksInNewWindow: true});
8587
} else {
@@ -95,7 +97,7 @@ describe('makeHtml() features testsuite', function () {
9597
suite = tableSuite;
9698
for (var i = 0; i < suite.length; ++i) {
9799
if (suite[i].name === 'basic-with-header-ids') {
98-
converter = new showdown.Converter({tables: true, tableHeaderId: true});
100+
converter = new showdown.Converter({tables: true, tablesHeaderId: true});
99101
} else if (suite[i].name === '#179.parse-md-in-table-ths') {
100102
converter = new showdown.Converter({tables: true, strikethrough: true});
101103
} else {

0 commit comments

Comments
 (0)