Skip to content

Commit

Permalink
Update showdown extensions
Browse files Browse the repository at this point in the history
closes TryGhost#5039, TryGhost#5028, TryGhost#4659, TryGhost#4627, TryGhost#4592, TryGhost#1501

This PR pulls in the new version of showdown + adds and updates some tests to show what has changed

- Lots of additional whitespaces caused by a bad implementation of GFM newlines have been removed
- One fix with newlines + pre tags is now undone, but is now closer to all other markdown handlers
  • Loading branch information
ErisDS committed Apr 20, 2015
1 parent d439306 commit 230f088
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 21 deletions.
137 changes: 117 additions & 20 deletions core/test/unit/showdown_client_integrated_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,41 @@ describe('Showdown client side converter', function () {
// The image is the entire markup, so the image box should be too
processedMarkup.should.match(testPhrase.output);
});
});

it('should honour `/```/pre/code/script etc', function () {
// From Ghost issue #5039
var testPhrases = [
{input: '`~~not strike~~`', output: /^<p><code>~~not strike~~<\/code><\/p>$/},
{input: '`\\~\\~not strike\\~\\~`', output: /^<p><code>~~not strike~~<\/code><\/p>$/},
{input: '```\n~~not strike~~\n```', output: /^<pre><code>~~not strike~~\n<\/code><\/pre>$/},
{
input: '```html\n~~not strike~~\n```',
output: /^<pre><code class="language-html">~~not strike~~\n<\/code><\/pre>$/
},
{input: '<pre>~~not strike~~</pre>', output: /^<pre>~~not strike~~<\/pre>$/},
{input: '<code>~~not strike~~</code>', output: /^<p><code>~~not strike~~<\/code><\/p>$/},
{
input: '<pre><code class="language-html">~~not strike~~</code></pre>',
output: /^<pre><code class="language-html">~~not strike~~<\/code><\/pre>$/
},
{
input: '<pre class="lang-html"><code class="language-html">~~not strike~~</code></pre>',
output: /^<pre class="lang-html"><code class="language-html">~~not strike~~<\/code><\/pre>$/
},
{
input: '<script>\nvar strike = "~~not strike~~";\n</script>',
output: /^<script>\nvar strike = "~~not strike~~";\n<\/script>$/
}

],
processedMarkup;

testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
});
});
});

describe('GFM underscore handling - _and_things_', function () {
it('should not touch single underscores inside words', function () {
Expand All @@ -45,13 +78,12 @@ describe('Showdown client side converter', function () {
processedMarkup.should.match(testPhrase.output);
});

// Currently failing - fixing this causes other issues
// it('should not create italic words between lines', function () {
// var testPhrase = {input: 'foo_bar\nbar_foo', output: /^<p>foo_bar <br \/>\nbar_foo<\/p>$/},
// processedMarkup = converter.makeHtml(testPhrase.input);
//
// processedMarkup.should.match(testPhrase.output);
// });
it('should not create italic words between lines', function () {
var testPhrase = {input: 'foo_bar\nbar_foo', output: /^<p>foo_bar <br \/>\nbar_foo<\/p>$/},
processedMarkup = converter.makeHtml(testPhrase.input);

processedMarkup.should.match(testPhrase.output);
});

it('should not touch underscores in code blocks', function () {
var testPhrase = {input: ' foo_bar_baz', output: /^<pre><code>foo_bar_baz\n<\/code><\/pre>$/},
Expand Down Expand Up @@ -89,18 +121,24 @@ describe('Showdown client side converter', function () {
var testPhrases = [
{
input: '<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>',
output: /^<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
output: '<pre>\nthis is `a_test` and this_too and finally_this_is\n<\/pre>'
},
// Changes to extensions mean this 'fix' no longer present, however the current behaviour as
// shown by the test below is correct compared to most major markdown parsers via babelmark
//{
// input: 'hmm<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>',
// output: '<p>hmm<\/p>\n\n<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>'
//}
{
input: 'hmm<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>',
output: /^<p>hmm<\/p>\n\n<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
output: '<p>hmm<pre>\nthis is <code>a_test<\/code> and this_too and finally_this_is\n<\/pre><\/p>'
}
],
processedMarkup;

testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
processedMarkup.should.equal(testPhrase.output);
});
});

Expand All @@ -126,7 +164,7 @@ describe('Showdown client side converter', function () {
it('should NOT escape underscore inside of code/pre blocks', function () {
var testPhrase = {
input: '```\n_____\n```',
output: /^<pre><code>_____ \n<\/code><\/pre>$/
output: /^<pre><code>_____\n<\/code><\/pre>$/
},
processedMarkup;

Expand All @@ -141,7 +179,7 @@ describe('Showdown client side converter', function () {
var testPhrases = [
{input: 'fizz\nbuzz', output: /^<p>fizz <br \/>\nbuzz<\/p>$/},
{input: 'Hello world\nIt is a fine day', output: /^<p>Hello world <br \/>\nIt is a fine day<\/p>$/},
{input: '\'first\nsecond', output: /^<p>\'first <br \/>\nsecond<\/p>$/},
{input: '\"first\nsecond', output: /^<p>\"first <br \/>\nsecond<\/p>$/},
{input: '\'first\nsecond', output: /^<p>\'first <br \/>\nsecond<\/p>$/}
],
processedMarkup;
Expand Down Expand Up @@ -342,7 +380,7 @@ describe('Showdown client side converter', function () {
var testPhrases = [
{
input: '```\nurl: http://google.co.uk\n```',
output: /^<pre><code>url: http:\/\/google.co.uk \n<\/code><\/pre>$/
output: /^<pre><code>url: http:\/\/google.co.uk\n<\/code><\/pre>$/
},
{
input: '`url: http://google.co.uk`',
Expand Down Expand Up @@ -522,7 +560,7 @@ describe('Showdown client side converter', function () {
});
});

describe('Highlight', function () {
describe('Highlight - <mark>', function () {
it('should replace showdown highlight with html', function () {
var testPhrases = [
{
Expand Down Expand Up @@ -611,28 +649,87 @@ describe('Showdown client side converter', function () {
processedMarkup.should.match(testPhrase.output);
});
});

it('should honour `/```/pre/code/script etc', function () {
// From Ghost issue #5039
var testPhrases = [
{input: '`==not highlight==`', output: /^<p><code>==not highlight==<\/code><\/p>$/},
{input: '`\=\=not highlight\=\=`', output: /^<p><code>==not highlight==<\/code><\/p>$/},
{input: '```\n==not highlight==\n```', output: /^<pre><code>==not highlight==\n<\/code><\/pre>$/},
{
input: '```html\n==not highlight==\n```',
output: /^<pre><code class="language-html">==not highlight==\n<\/code><\/pre>$/
},
{input: '<pre>==not highlight==</pre>', output: /^<pre>==not highlight==<\/pre>$/},
{input: '<code>==not highlight==</code>', output: /^<p><code>==not highlight==<\/code><\/p>$/},
{
input: '<pre><code class="language-html">==not highlight==</code></pre>',
output: /^<pre><code class="language-html">==not highlight==<\/code><\/pre>$/
},
{
input: '<pre class="lang-html"><code class="language-html">==not highlight==</code></pre>',
output: /^<pre class="lang-html"><code class="language-html">==not highlight==<\/code><\/pre>$/
},
{
input: '<script>\nvar highlight = "==not highlight==";\n</script>',
output: /^<script>\nvar highlight = "==not highlight==";\n<\/script>$/
},
// From Ghost issue #4627
{
input: '![](http://xxx.com/==20131118/2)\n$$\\x_s$$\nfdsaf\n![](http://xxx.com/==20131119/2)',
output: /(?!\<mark\>)/
}
],
processedMarkup;

testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
});
});
});

describe('Block HTML', function () {
describe('Showdown features', function () {
it('should output block HTML untouched', function () {
var testPhrases = [
{
input: '<table class=\"test\">\n <tr>\n <td>Foo</td>\n </tr>\n <tr>\n <td>Bar</td>\n </tr>\n</table>',
output: /^<table class=\"test\"> \n <tr>\n <td>Foo<\/td>\n <\/tr>\n <tr>\n <td>Bar<\/td>\n <\/tr>\n<\/table>$/
output: '<table class=\"test\">\n <tr>\n <td>Foo<\/td>\n <\/tr>\n <tr>\n <td>Bar<\/td>\n <\/tr>\n<\/table>'
},
{
input: '<hr />',
output: /^<hr \/>$/
output: '<hr \/>'
},
{ // audio isn't counted as a block tag by showdown so gets wrapped in <p></p>
input: '<audio class=\"podcastplayer\" controls>\n <source src=\"foobar.mp3\" type=\"audio/mp3\" preload=\"none\"></source>\n <source src=\"foobar.off\" type=\"audio/ogg\" preload=\"none\"></source>\n</audio>',
output: /^<audio class=\"podcastplayer\" controls> \n <source src=\"foobar.mp3\" type=\"audio\/mp3\" preload=\"none\"><\/source>\n <source src=\"foobar.off\" type=\"audio\/ogg\" preload=\"none\"><\/source>\n<\/audio>$/
output: '<audio class=\"podcastplayer\" controls>\n <source src=\"foobar.mp3\" type=\"audio\/mp3\" preload=\"none\"><\/source>\n <source src=\"foobar.off\" type=\"audio\/ogg\" preload=\"none\"><\/source>\n<\/audio>'
}
];

testPhrases.forEach(function (testPhrase) {
var processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
processedMarkup.should.equal(testPhrase.output);
});
});

it('should handle fenced code blocks', function () {
var testPhrases = [
{
// From Ghost issue #4659
input: '```\nsudo apt-get install \\\n```',
output: '<pre><code>sudo apt-get install \\\n<\/code><\/pre>'
},
{

// From Ghost issue #5039
input: 'A \`\n\n```\n1\n```\n\n`B`\n\n```\n2\n```',
output: '<p>A `<\/p>\n\n<pre><code>1\n<\/code><\/pre>\n\n<p><code>B<\/code><\/p>\n\n<pre><code>2\n<\/code><\/pre>'
}
];

testPhrases.forEach(function (testPhrase) {
var processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.equal(testPhrase.output);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"request": "2.51.0",
"rss": "1.1.1",
"semver": "4.3.3",
"showdown-ghost": "0.3.6",
"showdown-ghost": "git://github.com/ErisDS/showdown#ext-imprv",
"sqlite3": "3.0.5",
"unidecode": "0.1.3",
"validator": "3.28.0",
Expand Down

0 comments on commit 230f088

Please sign in to comment.