FIX: Missing formatting for oneboxes in preview
This commit is contained in:
parent
a64b954fca
commit
7ab98bb0e7
|
@ -1,3 +1,4 @@
|
||||||
|
/*global md5:true */
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Discourse uses the Markdown.js as its main parser. `Discourse.Dialect` is the framework
|
Discourse uses the Markdown.js as its main parser. `Discourse.Dialect` is the framework
|
||||||
|
@ -9,7 +10,8 @@ var parser = window.BetterMarkdown,
|
||||||
DialectHelpers = parser.DialectHelpers,
|
DialectHelpers = parser.DialectHelpers,
|
||||||
dialect = MD.dialects.Discourse = DialectHelpers.subclassDialect( MD.dialects.Gruber ),
|
dialect = MD.dialects.Discourse = DialectHelpers.subclassDialect( MD.dialects.Gruber ),
|
||||||
initialized = false,
|
initialized = false,
|
||||||
emitters = [];
|
emitters = [],
|
||||||
|
hoisted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize our dialects for processing.
|
Initialize our dialects for processing.
|
||||||
|
@ -35,19 +37,18 @@ function processTextNodes(node, event, emitter) {
|
||||||
if (node.length < 2) { return; }
|
if (node.length < 2) { return; }
|
||||||
|
|
||||||
if (node[0] === '__RAW') {
|
if (node[0] === '__RAW') {
|
||||||
|
var hash = md5(node[1]);
|
||||||
|
hoisted[hash] = node[1];
|
||||||
|
node[1] = hash;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var skipSanitize = [];
|
|
||||||
for (var j=1; j<node.length; j++) {
|
for (var j=1; j<node.length; j++) {
|
||||||
var textContent = node[j];
|
var textContent = node[j];
|
||||||
if (typeof textContent === "string") {
|
if (typeof textContent === "string") {
|
||||||
var result = emitter(textContent, event);
|
var result = emitter(textContent, event);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result instanceof Array) {
|
if (result instanceof Array) {
|
||||||
for (var i=0; i<result.length; i++) {
|
|
||||||
skipSanitize[result[i]] = true;
|
|
||||||
}
|
|
||||||
node.splice.apply(node, [j, 1].concat(result));
|
node.splice.apply(node, [j, 1].concat(result));
|
||||||
} else {
|
} else {
|
||||||
node[j] = result;
|
node[j] = result;
|
||||||
|
@ -143,6 +144,7 @@ Discourse.Dialect = {
|
||||||
**/
|
**/
|
||||||
cook: function(text, opts) {
|
cook: function(text, opts) {
|
||||||
if (!initialized) { initializeDialects(); }
|
if (!initialized) { initializeDialects(); }
|
||||||
|
hoisted = {};
|
||||||
dialect.options = opts;
|
dialect.options = opts;
|
||||||
var tree = parser.toHTMLTree(text, 'Discourse'),
|
var tree = parser.toHTMLTree(text, 'Discourse'),
|
||||||
result = parser.renderJsonML(parseTree(tree));
|
result = parser.renderJsonML(parseTree(tree));
|
||||||
|
@ -156,6 +158,15 @@ Discourse.Dialect = {
|
||||||
result = opts.sanitizerFunction(result);
|
result = opts.sanitizerFunction(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we hoisted out anything, put it back
|
||||||
|
var keys = Object.keys(hoisted);
|
||||||
|
if (keys.length) {
|
||||||
|
keys.forEach(function(k) {
|
||||||
|
result = result.replace(k, hoisted[k]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
hoisted = {};
|
||||||
return result.trim();
|
return result.trim();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ function hoistingSanitizer(result) {
|
||||||
hoisted = [];
|
hoisted = [];
|
||||||
for (var i=0; i<m.length; i++) {
|
for (var i=0; i<m.length; i++) {
|
||||||
var c = m[i],
|
var c = m[i],
|
||||||
id = "discourse:hoisted-comment:" + i;
|
id = md5("discourse:hoisted-comment:" + i);
|
||||||
result = result.replace(c, id);
|
result = result.replace(c, id);
|
||||||
hoisted.push([c, id]);
|
hoisted.push([c, id]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue