This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/dialects/bold_italics_dialect.js
2013-08-29 15:18:27 -04:00

42 lines
1.1 KiB
JavaScript

/**
markdown-js doesn't ensure that em/strong codes are present on word boundaries.
So we create our own handlers here.
**/
// Support for simultaneous bold and italics
Discourse.Dialect.inlineBetween({
between: '***',
wordBoundary: true,
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
});
// Builds a common markdown replacer
var replaceMarkdown = function(match, tag) {
Discourse.Dialect.inlineBetween({
between: match,
wordBoundary: true,
emitter: function(contents) { return [tag].concat(contents) }
});
};
replaceMarkdown('**', 'strong');
replaceMarkdown('__', 'strong');
replaceMarkdown('*', 'em');
replaceMarkdown('_', 'em');
// There's a weird issue with the markdown parser where it won't process simple blockquotes
// when they are prefixed with spaces. This fixes it.
Discourse.Dialect.on("register", function(event) {
var dialect = event.dialect,
MD = event.MD;
dialect.block["fix_simple_quotes"] = function(block, next) {
var m = /^ +(\>[\s\S]*)/.exec(block);
if (m && m[1] && m[1].length) {
next.unshift(MD.mk_block(m[1]));
return [];
}
};
});