FIX: pre-hoist code blocks & spans
This commit is contained in:
@@ -10,7 +10,7 @@ var acceptableCodeClasses =
|
||||
"perl", "php", "profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql",
|
||||
"tex", "text", "vala", "vbscript", "vhdl"];
|
||||
|
||||
var textCodeClasses = ["text", "pre"];
|
||||
var textCodeClasses = ["text", "pre", "plain"];
|
||||
|
||||
function flattenBlocks(blocks) {
|
||||
var result = "";
|
||||
@@ -39,6 +39,17 @@ Discourse.Dialect.replaceBlock({
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.Dialect.replaceBlock({
|
||||
start: /(<pre[^\>]*\>)([\s\S]*)/igm,
|
||||
stop: /<\/pre>/igm,
|
||||
rawContents: true,
|
||||
skipIfTradtionalLinebreaks: true,
|
||||
|
||||
emitter: function(blockContents) {
|
||||
return ['p', ['pre', flattenBlocks(blockContents)]];
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure that content in a code block is fully escaped. This way it's not white listed
|
||||
// and we can use HTML and Javascript examples.
|
||||
Discourse.Dialect.on('parseNode', function (event) {
|
||||
@@ -51,7 +62,6 @@ Discourse.Dialect.on('parseNode', function (event) {
|
||||
|
||||
if (path && path[path.length-1] && path[path.length-1][0] && path[path.length-1][0] === "pre") {
|
||||
regexp = / +$/g;
|
||||
|
||||
} else {
|
||||
regexp = /^ +| +$/g;
|
||||
}
|
||||
@@ -59,17 +69,6 @@ Discourse.Dialect.on('parseNode', function (event) {
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.Dialect.replaceBlock({
|
||||
start: /(<pre[^\>]*\>)([\s\S]*)/igm,
|
||||
stop: /<\/pre>/igm,
|
||||
rawContents: true,
|
||||
skipIfTradtionalLinebreaks: true,
|
||||
|
||||
emitter: function(blockContents) {
|
||||
return ['p', ['pre', flattenBlocks(blockContents)]];
|
||||
}
|
||||
});
|
||||
|
||||
// Whitelist the language classes
|
||||
var regexpSource = "^lang-(" + acceptableCodeClasses.join('|') + ")$";
|
||||
Discourse.Markdown.whiteListTag('code', 'class', new RegExp(regexpSource, "i"));
|
||||
|
||||
Reference in New Issue
Block a user