mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:53:42 +08:00
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
|
||||
|
@ -9,7 +10,8 @@ var parser = window.BetterMarkdown,
|
|||
DialectHelpers = parser.DialectHelpers,
|
||||
dialect = MD.dialects.Discourse = DialectHelpers.subclassDialect( MD.dialects.Gruber ),
|
||||
initialized = false,
|
||||
emitters = [];
|
||||
emitters = [],
|
||||
hoisted;
|
||||
|
||||
/**
|
||||
Initialize our dialects for processing.
|
||||
|
@ -35,19 +37,18 @@ function processTextNodes(node, event, emitter) {
|
|||
if (node.length < 2) { return; }
|
||||
|
||||
if (node[0] === '__RAW') {
|
||||
var hash = md5(node[1]);
|
||||
hoisted[hash] = node[1];
|
||||
node[1] = hash;
|
||||
return;
|
||||
}
|
||||
|
||||
var skipSanitize = [];
|
||||
for (var j=1; j<node.length; j++) {
|
||||
var textContent = node[j];
|
||||
if (typeof textContent === "string") {
|
||||
var result = emitter(textContent, event);
|
||||
if (result) {
|
||||
if (result instanceof Array) {
|
||||
for (var i=0; i<result.length; i++) {
|
||||
skipSanitize[result[i]] = true;
|
||||
}
|
||||
node.splice.apply(node, [j, 1].concat(result));
|
||||
} else {
|
||||
node[j] = result;
|
||||
|
@ -143,6 +144,7 @@ Discourse.Dialect = {
|
|||
**/
|
||||
cook: function(text, opts) {
|
||||
if (!initialized) { initializeDialects(); }
|
||||
hoisted = {};
|
||||
dialect.options = opts;
|
||||
var tree = parser.toHTMLTree(text, 'Discourse'),
|
||||
result = parser.renderJsonML(parseTree(tree));
|
||||
|
@ -156,6 +158,15 @@ Discourse.Dialect = {
|
|||
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();
|
||||
},
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ function hoistingSanitizer(result) {
|
|||
hoisted = [];
|
||||
for (var i=0; i<m.length; i++) {
|
||||
var c = m[i],
|
||||
id = "discourse:hoisted-comment:" + i;
|
||||
id = md5("discourse:hoisted-comment:" + i);
|
||||
result = result.replace(c, id);
|
||||
hoisted.push([c, id]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user