-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #474 from openannotation/new-markdown-plugin
New Markdown Plugin
- Loading branch information
Showing
6 changed files
with
105 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use strict"; | ||
|
||
var Util = require('../util'); | ||
|
||
var g = Util.getGlobal(), | ||
_t = Util.gettext; | ||
|
||
function createMarkdownPlugin () { | ||
var converter = null; | ||
|
||
if (g.Showdown && typeof g.Showdown.converter === 'function') { | ||
converter = new g.Showdown.converter(); | ||
} else { | ||
console.warn(_t("To use the Markdown plugin, you must" + | ||
" include Showdown into the page first.")); | ||
} | ||
|
||
// Converts provided text into markdown. | ||
// | ||
// text - A String of Markdown to render as HTML. | ||
// | ||
// Examples | ||
// | ||
// plugin.convert('This is _very_ basic [Markdown](http://daringfireball.com)') | ||
// # => Returns "This is <em>very<em> basic <a href="http://...">Markdown</a>" | ||
// | ||
// Returns HTML string. | ||
function convert (text) { | ||
text = Util.escapeHtml(text || ''); | ||
return converter ? converter.makeHtml(text) : text; | ||
} | ||
|
||
return { | ||
convert: convert | ||
}; | ||
} | ||
|
||
exports.createMarkdownPlugin = createMarkdownPlugin; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var assert = require('assertive-chai').assert; | ||
|
||
var UI = require('../../../src/ui'), | ||
Util = require('../../../src/util'); | ||
|
||
var g = Util.getGlobal(); | ||
|
||
describe('UI.markdown', function () { | ||
var plugin = null; | ||
|
||
describe("constructor", function () { | ||
it("should log warning if Showdown is not loaded", function () { | ||
sinon.stub(console, 'warn'); | ||
var showdown = g.Showdown; | ||
g.Showdown = null; | ||
plugin = UI.markdown(); | ||
assert(console.warn.calledOnce); | ||
console.warn.restore(); | ||
g.Showdown = showdown; | ||
}); | ||
}); | ||
|
||
describe("convert", function () { | ||
var showdown = null; | ||
var escapeHtml = null; | ||
var makeHtml = null; | ||
|
||
beforeEach(function () { | ||
escapeHtml = sinon.stub(Util, 'escapeHtml').returns('escaped'); | ||
makeHtml = sinon.stub().returns('converted'); | ||
|
||
var fakeShowDown = { | ||
converter: function () { | ||
return { | ||
makeHtml: makeHtml | ||
}; | ||
} | ||
}; | ||
|
||
showdown = g.Showdown; | ||
g.Showdown = fakeShowDown; | ||
}); | ||
|
||
afterEach(function () { | ||
Util.escapeHtml.restore(); | ||
g.Showdown = showdown; | ||
}); | ||
|
||
it("should escape and convert the provided text into markdown", function () { | ||
plugin = UI.markdown(); | ||
assert.equal(plugin.convert('foo'), 'converted'); | ||
assert.isTrue(escapeHtml.calledWith('foo')); | ||
assert.isTrue(makeHtml.calledWith('escaped')); | ||
}); | ||
|
||
it("should escape even if showdown is not loaded", function () { | ||
g.Showdown = null; | ||
plugin = UI.markdown(); | ||
assert.equal(plugin.convert('foo'), 'escaped'); | ||
}); | ||
}); | ||
}); |