diff --git a/core/server/apps/default-cards/cards/markdown.js b/core/server/apps/default-cards/cards/markdown.js index 95a30c0be1..ac204b4c04 100644 --- a/core/server/apps/default-cards/cards/markdown.js +++ b/core/server/apps/default-cards/cards/markdown.js @@ -1,7 +1,6 @@ var SimpleDom = require('simple-dom'), tokenizer = require('simple-html-tokenizer').tokenize, - Showdown = require('showdown-ghost'), - converter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}), + markdownConverter = require('../../../utils/markdown-converter'), parser; module.exports = { @@ -9,6 +8,10 @@ module.exports = { type: 'dom', render(opts) { parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap); - return parser.parse('
~~foo_bar~~<\/p>$/},
- processedMarkup = converter.makeHtml(testPhrase.input);
-
- // The image is the entire markup, so the image box should be too
- processedMarkup.should.match(testPhrase.output);
- });
-
- it('should not touch single underscores inside words', function () {
- var testPhrase = {input: 'foo_bar', output: /^ foo_bar<\/p>$/},
- processedMarkup = converter.makeHtml(testPhrase.input);
-
- 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: /^ foo_bar test<\/strong><\/p>$/}
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should not treat pre blocks with pre-text differently', function () {
- var testPhrases = [
- {
- input: ' hmm<\/p>\n\n foo_bar_baz<\/p>$/},
- {input: 'foo_bar_baz_bat', output: /^ foo_bar_baz_bat<\/p>$/},
- {input: 'foo_bar_baz_bat_boo', output: /^ foo_bar_baz_bat_boo<\/p>$/},
- {input: 'FOO_BAR', output: /^ FOO_BAR<\/p>$/},
- {input: 'FOO_BAR_BAZ', output: /^ FOO_BAR_BAZ<\/p>$/},
- {input: 'FOO_bar_BAZ_bat', output: /^ FOO_bar_BAZ_bat<\/p>$/},
- {input: 'FOO_bar_BAZ_bat_BOO', output: /^ FOO_bar_BAZ_bat_BOO<\/p>$/},
- {input: 'foo_BAR_baz_BAT_boo', output: /^ foo_BAR_baz_BAT_boo<\/p>$/}
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should turn newlines into br tags in simple cases', function () {
- var testPhrases = [
- {input: 'fizz\nbuzz', output: /^ fizz Hello world \'first \'first ruby Hello world ruby Hello world http:\/\/google.co.uk<\/a><\/p>$/
- },
- {
- input: 'https://atest.com/fizz/buzz?baz=fizzbuzz',
- output: /^ https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a><\/p>$/
- },
- {
- input: 'Some [ text (http://www.google.co.uk) some other text',
- output: /^ Some \[ text \(http:\/\/www.google.co.uk<\/a>\) some other text<\/p>$/
- },
- {
- input: '>http://google.co.uk',
- output: /^ http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
- },
- {
- input: '> http://google.co.uk',
- output: /^ http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
- },
- {
- input: '<>>> http://google.co.uk',
- output: /^ <>>> http:\/\/google.co.uk<\/a><\/p>$/
- },
- {
- input: 'http://google.co.uk',
- output: /^ http:\/\/google.co.uk<\/a><\/p>$/
- },
- {
- input: '# http://google.co.uk',
- output: /^ Google<\/a><\/p>$/
- },
- {
- input: '[Google][1]\n\n[1]: http://google.co.uk \"some text\"',
- output: /^foo_bar<\/del><\/p>$/},
- processedMarkup = converter.makeHtml(testPhrase.input);
-
- // The image is the entire markup, so the image box should be too
- processedMarkup.should.match(testPhrase.output);
- });
-
- it('should honour escaped tildes', function () {
- var testPhrase = {input: '\\~\\~foo_bar\\~\\~', output: /^
\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: /^foo_bar_baz\n<\/code><\/pre>$/},
- processedMarkup = converter.makeHtml(testPhrase.input);
-
- processedMarkup.should.match(testPhrase.output);
- });
-
- it('should not touch underscores in pre blocks', function () {
- var testPhrases = [
- {input: '
\nfoo_bar_baz\n
', output: /^\nfoo_bar_baz\n<\/pre>$/},
- {input: '
foo_bar_baz
', output: /^foo_bar_baz<\/pre>$/}
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should not escape double underscores at the beginning of a line', function () {
- var testPhrases = [
- {input: '\n__test__\n', output: /^
\nthis is `a\\_test` and this\\_too and finally_this_is\n
',
- output: /^\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
- },
- {
- input: 'hmm
\nthis is `a\\_test` and this\\_too and finally_this_is\n
',
- output: /^\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
- }
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should escape two or more underscores inside words', function () {
- var testPhrases = [
- {input: 'foo_bar_baz', output: /^
\nbuzz<\/p>$/},
- {input: 'Hello world\nIt is a fine day', output: /^
\nIt is a fine day<\/p>$/},
- {input: '\'first\nsecond', output: /^
\nsecond<\/p>$/},
- {input: '\'first\nsecond', output: /^
\nsecond<\/p>$/}
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should convert newlines in all groups', function () {
- var testPhrases = [
- {
- input: 'ruby\npython\nerlang',
- output: /^
\npython
\nerlang<\/p>$/
- },
- {
- input: 'Hello world\nIt is a fine day\nout',
- output: /^
\nIt is a fine day
\nout<\/p>$/
- }
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should convert newlines in even long groups', function () {
- var testPhrases = [
- {
- input: 'ruby\npython\nerlang\ngo',
- output: /^
\npython
\nerlang
\ngo<\/p>$/
- },
- {
- input: 'Hello world\nIt is a fine day\noutside\nthe window',
- output: /^
\nIt is a fine day
\noutside
\nthe window<\/p>$/
- }
- ],
- processedMarkup;
-
- testPhrases.forEach(function (testPhrase) {
- processedMarkup = converter.makeHtml(testPhrase.input);
- processedMarkup.should.match(testPhrase.output);
- });
- });
-
- it('should not convert newlines in lists', function () {
- var testPhrases = [
- {
- input: '#fizz\n# buzz\n### baz',
- output: /^fizz<\/h1>\n\n
buzz<\/h1>\n\n
baz<\/h3>$/
- },
- {
- input: '* foo\n* bar',
- output: /^
\n
\n
\n
http:\/\/google.co.uk<\/a><\/h1>$/
- },
- {
- input: '* http://google.co.uk',
- output: /^
\n