Support for ***bold and italics***

This commit is contained in:
Robin Ward 2013-08-24 13:06:07 -04:00
parent e9663e5338
commit 093ead7855
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,32 @@
/**
Markdown.js doesn't seem to do bold and italics at the same time if you surround code with
three asterisks. This adds that support.
@event register
@namespace Discourse.Dialect
**/
Discourse.Dialect.on("register", function(event) {
var dialect = event.dialect,
MD = event.MD;
/**
Handles simultaneous bold and italics
@method parseMentions
@param {String} text the text match
@param {Array} match the match found
@param {Array} prev the previous jsonML
@return {Array} an array containing how many chars we've replaced and the jsonML content for it.
@namespace Discourse.Dialect
**/
dialect.inline['***'] = function boldItalics(text, match, prev) {
var regExp = /^\*{3}([^\*]+)\*{3}/,
m = regExp.exec(text);
if (m) {
return [m[0].length, ['strong', ['em'].concat(this.processInline(m[1]))]];
}
};
});

View File

@ -17,6 +17,7 @@ var cookedOptions = function(input, opts, expected, text) {
test("basic cooking", function() {
cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
});
test("Line Breaks", function() {