diff --git a/core/client/assets/vendor/showdown/extensions/ghostdown.js b/core/client/assets/vendor/showdown/extensions/ghostdown.js index 8090e08a8d..6d8862b3ed 100644 --- a/core/client/assets/vendor/showdown/extensions/ghostdown.js +++ b/core/client/assets/vendor/showdown/extensions/ghostdown.js @@ -5,7 +5,7 @@ { type: 'lang', filter: function (source) { - return source.replace(/\n?!image\[([\d\w\s]*)\]/gi, function (match, alt, a) { + return source.replace(/\n?!(?:image)?\[([^\n\]]*)\](?:\(([^\n\)]*)\))?/gi, function (match, alt, a) { return '
' + '' + '
Add image of ' + alt + '
' + diff --git a/core/test/unit/frontend_ghostdown_spec.js b/core/test/unit/frontend_ghostdown_spec.js new file mode 100644 index 0000000000..7801fe40d5 --- /dev/null +++ b/core/test/unit/frontend_ghostdown_spec.js @@ -0,0 +1,38 @@ +/*globals describe, it */ +var gdPath = "../../client/assets/vendor/showdown/extensions/ghostdown.js", + should = require('should'), + ghostdown = require(gdPath); + +describe("Ghostdown showdown extensions", function () { + + it("should export an array of methods for processing", function () { + + ghostdown.should.be.a("function"); + ghostdown().should.be.an.instanceof(Array); + + ghostdown().forEach(function (processor) { + processor.should.be.a("object"); + processor.should.have.property("type"); + processor.should.have.property("filter"); + processor.type.should.be.a("string"); + processor.filter.should.be.a("function"); + }); + }); + + it("should accurately detect images in markdown", function () { + + [ "!image[image and another,/ image](http://dsurl stuff)", + "![image and another,/ image]", + "![]()", + "![]" ] + .forEach(function (imageMarkup) { + var processedMarkup = + ghostdown().reduce(function(prev,processor) { + return processor.filter(prev); + },imageMarkup); + + // The image is the entire markup, so the image box should be too + processedMarkup.should.match(/^\n*$/); + }); + }); +}); \ No newline at end of file