diff --git a/Gruntfile.js b/Gruntfile.js index 10f0729..1a69f73 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -89,7 +89,7 @@ module.exports = function (grunt) { options: { globals: ['should'], timeout: 3000, - ignoreLeaks: false, + ignoreLeaks: true, reporter: 'spec' } }, diff --git a/dist/showdown.js b/dist/showdown.js index c5ac6da..b31b2b2 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 2554dfa..87161c3 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 3ff6774..f33c91d 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index f17eed5..4172a5f 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/subParsers/codeSpans.js b/src/subParsers/codeSpans.js index 639ffa8..b0ec1dd 100644 --- a/src/subParsers/codeSpans.js +++ b/src/subParsers/codeSpans.js @@ -26,6 +26,14 @@ showdown.subParser('codeSpans', function (text) { 'use strict'; + //special case -> literal html code tag + text = text.replace(/(<]*?>)([^]*?)<\/code>/g, function (wholeMatch, tag, c) { + c = c.replace(/^([ \t]*)/g, ''); // leading whitespace + c = c.replace(/[ \t]*$/g, ''); // trailing whitespace + c = showdown.subParser('encodeCode')(c); + return tag + c + ''; + }); + /* text = text.replace(/ (^|[^\\]) // Character before opening ` can't be a backslash @@ -38,15 +46,15 @@ showdown.subParser('codeSpans', function (text) { (?!`) /gm, function(){...}); */ - - text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, function (wholeMatch, m1, m2, m3) { - var c = m3; - c = c.replace(/^([ \t]*)/g, ''); // leading whitespace - c = c.replace(/[ \t]*$/g, ''); // trailing whitespace - c = showdown.subParser('encodeCode')(c); - return m1 + '' + c + ''; - }); + text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, + function (wholeMatch, m1, m2, m3) { + var c = m3; + c = c.replace(/^([ \t]*)/g, ''); // leading whitespace + c = c.replace(/[ \t]*$/g, ''); // trailing whitespace + c = showdown.subParser('encodeCode')(c); + return m1 + '' + c + ''; + } + ); return text; - }); diff --git a/src/subParsers/images.js b/src/subParsers/images.js index 0dc6b04..8dde87b 100644 --- a/src/subParsers/images.js +++ b/src/subParsers/images.js @@ -41,6 +41,7 @@ showdown.subParser('images', function (text, options, globals) { } altText = altText.replace(/"/g, '"'); + altText = showdown.helper.escapeCharacters(altText, '*_', false); url = showdown.helper.escapeCharacters(url, '*_', false); var result = '' + altText + '$2'); - text = text.replace(/(^|\s)_(?=\S)([^]+?)_(?=\s|$)/gm, '$1$2'); + text = text.replace(/(^|\s|>|\b)__(?=\S)([^]+?)__(?=\b|<|\s|$)/gm, '$1$2'); + text = text.replace(/(^|\s|>|\b)_(?=\S)([^]+?)_(?=\b|<|\s|$)/gm, '$1$2'); //asterisks text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '$1'); text = text.replace(/\*(?=\S)([^]+?)\*/g, '$1'); diff --git a/test/bootstrap.js b/test/bootstrap.js index a969f71..fc9b11d 100644 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -82,8 +82,8 @@ testCase.actual = beautify(testCase.actual, beauOptions); // Normalize line returns - testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, os.EOL); - testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, os.EOL); + testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n'); + testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n'); return testCase; } diff --git a/test/features/autolink_and_disallow_underscores.html b/test/features/autolink_and_disallow_underscores.html new file mode 100644 index 0000000..69efe76 --- /dev/null +++ b/test/features/autolink_and_disallow_underscores.html @@ -0,0 +1 @@ +

http://en.wikipedia.org/wiki/Tourism_in_Germany

\ No newline at end of file diff --git a/test/features/autolink_and_disallow_underscores.md b/test/features/autolink_and_disallow_underscores.md new file mode 100644 index 0000000..799cdcf --- /dev/null +++ b/test/features/autolink_and_disallow_underscores.md @@ -0,0 +1 @@ +http://en.wikipedia.org/wiki/Tourism_in_Germany \ No newline at end of file diff --git a/test/ghost/markdown-magic.html b/test/ghost/markdown-magic.html new file mode 100644 index 0000000..d7e74e5 --- /dev/null +++ b/test/ghost/markdown-magic.html @@ -0,0 +1,40 @@ + + +
https://ghost.org
+
+ +

https://ghost.org

+ +

Markdown Footnotes

+ +
The quick brown fox[^1] jumped over the lazy dog[^2].
+
+    [^1]: Foxes are red
+    [^2]: Dogs are usually not red
+
+ +

The quick brown fox[^1] jumped over the lazy dog[^2].

+ +

Syntax Highlighting

+ +
```language-javascript
+    [...]
+    ```
+
+ +

Combined with Prism.js in the Ghost theme:

+ +
// # Notifications API
+// RESTful API for creating notifications
+var Promise            = require('bluebird'),
+_                  = require('lodash'),
+canThis            = require('../permissions').canThis,
+errors             = require('../errors'),
+utils              = require('./utils'),
+
+// Holds the persistent notifications
+notificationsStore = [],
+// Holds the last used id
+notificationCounter = 0,
+notifications;
+
\ No newline at end of file diff --git a/test/ghost/markdown-magic.md b/test/ghost/markdown-magic.md new file mode 100644 index 0000000..59153db --- /dev/null +++ b/test/ghost/markdown-magic.md @@ -0,0 +1,43 @@ +### Automatic Links + +``` +https://ghost.org +``` + +https://ghost.org + +### Markdown Footnotes + +``` +The quick brown fox[^1] jumped over the lazy dog[^2]. + +[^1]: Foxes are red +[^2]: Dogs are usually not red +``` + +The quick brown fox[^1] jumped over the lazy dog[^2]. + + +### Syntax Highlighting + + ```language-javascript + [...] + ``` + +Combined with [Prism.js](http://prismjs.com/) in the Ghost theme: + +```language-javascript +// # Notifications API +// RESTful API for creating notifications +var Promise = require('bluebird'), + _ = require('lodash'), + canThis = require('../permissions').canThis, + errors = require('../errors'), + utils = require('./utils'), + + // Holds the persistent notifications + notificationsStore = [], + // Holds the last used id + notificationCounter = 0, + notifications; +``` \ No newline at end of file diff --git a/test/ghost/underscore.html b/test/ghost/underscore.html new file mode 100644 index 0000000..8520667 --- /dev/null +++ b/test/ghost/underscore.html @@ -0,0 +1,78 @@ +

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+ +

baz_bar_foo

+ +

baz_bar_foo

+ +

baz_bar_foo

+ +

baz bar foo baz_bar_foo foo bar baz and foo

+ +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ + + +

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+ +
    +
  1. foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo
  2. +
  3. foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo
  4. +
+ +
+

foo_bar_baz foo_bar_baz_bar_foo foo_bar baz_bar baz_foo

+
+ + + +
+ +

http://en.wikipedia.org/wiki/Tourism_in_Germany

+ +

an example

+ +

Another example of a link

+ +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ + + +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ +

http://myurl.com/foo_bar_baz_bar_foo

+ +

http://myurl.com/foo_bar_baz_bar_foo

+ +

italics.

+ +

italics .

diff --git a/test/ghost/underscore.md b/test/ghost/underscore.md new file mode 100644 index 0000000..8f5de54 --- /dev/null +++ b/test/ghost/underscore.md @@ -0,0 +1,76 @@ +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +_baz_bar_foo_ + +__baz_bar_foo__ + +___baz_bar_foo___ + +baz bar foo _baz_bar_foo foo bar baz_ and foo + +foo\_bar\_baz foo\_bar\_baz\_bar\_foo \_foo\_bar baz\_bar\_ baz\_foo + +`foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo` + + + foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + + +```html +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo +``` + +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ +
foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo
+ + + +[foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo](http://myurl.com/foo_bar_baz_bar_foo) + +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo +----- + +### foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +1. foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo +2. foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +> foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +* foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo +* foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +------- + +http://en.wikipedia.org/wiki/Tourism_in_Germany + +[an example] [wiki] + +Another [example][wiki] of a link + +[wiki]: http://en.wikipedia.org/wiki/Tourism_in_Germany + +

foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo

+ + +foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo + +![foo_bar_baz foo_bar_baz_bar_foo _foo_bar baz_bar_ baz_foo](http://myurl.com/foo_bar_baz_bar_foo) + +http://myurl.com/foo_bar_baz_bar_foo + + + +_italics_. + +_italics_ . diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index 948fbf5..d575c69 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -25,6 +25,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({ghCodeBlocks: false}); } else if (testsuite[i].name === '#164.4.tasklists') { converter = new showdown.Converter({tasklists: true}); + } else if (testsuite[i].name === 'autolink_and_disallow_underscores') { + converter = new showdown.Converter({literalMidWordUnderscores: true, simplifiedAutoLink: true}); } else { converter = new showdown.Converter(); } diff --git a/test/node/testsuite.ghost.js b/test/node/testsuite.ghost.js new file mode 100644 index 0000000..d720ef6 --- /dev/null +++ b/test/node/testsuite.ghost.js @@ -0,0 +1,22 @@ +/** + * Created by Estevao on 14-07-2015. + */ +var bootstrap = require('../bootstrap.js'), + converter = new bootstrap.showdown.Converter({ + strikethrough: true, + literalMidWordUnderscores: true, + simplifiedAutoLink: true, + tables: true, + parseImgDimensions: true, //extra + tasklists: true //extra + }), + assertion = bootstrap.assertion, + testsuite = bootstrap.getTestSuite('test/ghost/'); + +//MD-Testsuite (borrowed from karlcow/markdown-testsuite) +describe('makeHtml() ghost testsuite', function () { + 'use strict'; + for (var i = 0; i < testsuite.length; ++i) { + it(testsuite[i].name, assertion(testsuite[i], converter)); + } +});