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-10-16 10:28:42 -04:00

34 lines
850 B
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)]; }
});
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');