mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 11:42:44 +08:00
FIX: Support for nested bold/italics in MD
This commit is contained in:
parent
93fbbe79b4
commit
c6b92f0ef7
|
@ -7,12 +7,14 @@
|
|||
Discourse.Dialect.inlineBetween({
|
||||
between: '***',
|
||||
wordBoundary: true,
|
||||
spaceBoundary: true,
|
||||
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
|
||||
});
|
||||
|
||||
Discourse.Dialect.inlineBetween({
|
||||
between: '___',
|
||||
wordBoundary: true,
|
||||
spaceBoundary: true,
|
||||
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
|
||||
});
|
||||
|
||||
|
@ -21,6 +23,7 @@ var replaceMarkdown = function(match, tag) {
|
|||
Discourse.Dialect.inlineBetween({
|
||||
between: match,
|
||||
wordBoundary: true,
|
||||
spaceBoundary: true,
|
||||
emitter: function(contents) { return [tag].concat(contents) }
|
||||
});
|
||||
};
|
||||
|
|
|
@ -118,7 +118,6 @@ function parseTree(tree, path, insideCounts) {
|
|||
@returns {Boolean} whether there is an invalid word boundary
|
||||
**/
|
||||
function invalidBoundary(args, prev) {
|
||||
|
||||
if (!args.wordBoundary && !args.spaceBoundary) { return false; }
|
||||
|
||||
var last = prev[prev.length - 1];
|
||||
|
@ -260,14 +259,14 @@ Discourse.Dialect = {
|
|||
inlineBetween: function(args) {
|
||||
var start = args.start || args.between,
|
||||
stop = args.stop || args.between,
|
||||
startLength = start.length;
|
||||
startLength = start.length,
|
||||
self = this;
|
||||
|
||||
this.registerInline(start, function(text, match, prev) {
|
||||
if (invalidBoundary(args, prev)) { return; }
|
||||
|
||||
var endPos = text.indexOf(stop, startLength);
|
||||
var endPos = self.findEndPos(text, stop, args, startLength);
|
||||
if (endPos === -1) { return; }
|
||||
|
||||
var between = text.slice(startLength, endPos);
|
||||
|
||||
// If rawcontents is set, don't process inline
|
||||
|
@ -282,6 +281,16 @@ Discourse.Dialect = {
|
|||
});
|
||||
},
|
||||
|
||||
findEndPos: function(text, stop, args, start) {
|
||||
var endPos = text.indexOf(stop, start);
|
||||
if (endPos === -1) { return -1; }
|
||||
var after = text.charAt(endPos + stop.length);
|
||||
if (after && after.indexOf(stop) === 0) {
|
||||
return this.findEndPos(text, stop, args, endPos + stop.length + 1);
|
||||
}
|
||||
return endPos;
|
||||
},
|
||||
|
||||
/**
|
||||
Registers a block for processing. This is more complicated than using one of
|
||||
the other helpers such as `replaceBlock` so consider using them first!
|
||||
|
|
|
@ -19,6 +19,7 @@ test("basic cooking", function() {
|
|||
cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
||||
cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("*this is italic **with some bold** inside*", "<p><em>this is italic <strong>with some bold</strong> inside</em></p>", "it handles nested bold in italics");
|
||||
cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
|
||||
cooked("word_with_underscores", "<p>word_with_underscores</p>", "it doesn't do intraword italics");
|
||||
cooked("common/_special_font_face.html.erb", "<p>common/_special_font_face.html.erb</p>", "it doesn't intraword with a slash");
|
||||
|
|
Loading…
Reference in New Issue
Block a user