mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FIX: Use lang- prefixes for HLJS; add nohighlight for ...
text; use a proper whiteListTag() call. Old posts are not affected - no global rebake is necessary.
This commit is contained in:
parent
22a4ceceee
commit
32cc31319f
@ -3,12 +3,12 @@
|
||||
**/
|
||||
|
||||
var acceptableCodeClasses =
|
||||
["lang-auto", "1c", "actionscript", "apache", "applescript", "avrasm", "axapta", "bash", "brainfuck",
|
||||
["auto", "1c", "actionscript", "apache", "applescript", "avrasm", "axapta", "bash", "brainfuck",
|
||||
"clojure", "cmake", "coffeescript", "cpp", "cs", "css", "d", "delphi", "diff", "xml", "django", "dos",
|
||||
"erlang-repl", "erlang", "glsl", "go", "handlebars", "haskell", "http", "ini", "java", "javascript",
|
||||
"json", "lisp", "lua", "markdown", "matlab", "mel", "nginx", "objectivec", "parser3", "perl", "php",
|
||||
"profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql", "tex", "text",
|
||||
"vala", "vbscript", "vhdl"];
|
||||
"json", "lisp", "lua", "markdown", "matlab", "mel", "nginx", "nohighlight", "objectivec", "parser3",
|
||||
"perl", "php", "profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql",
|
||||
"tex", "text", "vala", "vbscript", "vhdl"];
|
||||
|
||||
var textCodeClasses = ["text", "pre"];
|
||||
|
||||
@ -32,9 +32,9 @@ Discourse.Dialect.replaceBlock({
|
||||
}
|
||||
|
||||
if (textCodeClasses.indexOf(matches[1]) !== -1) {
|
||||
return ['p', ['pre', ['code', flattenBlocks(blockContents) ]]];
|
||||
return ['p', ['pre', ['code', {'class': 'lang-nohighlight'}, flattenBlocks(blockContents) ]]];
|
||||
} else {
|
||||
return ['p', ['pre', ['code', {'class': klass}, flattenBlocks(blockContents) ]]];
|
||||
return ['p', ['pre', ['code', {'class': 'lang-' + klass}, flattenBlocks(blockContents) ]]];
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -69,3 +69,7 @@ Discourse.Dialect.replaceBlock({
|
||||
return ['p', ['pre', flattenBlocks(blockContents)]];
|
||||
}
|
||||
});
|
||||
|
||||
// Whitelist the language classes
|
||||
var regexpSource = "^lang-(" + acceptableCodeClasses.join('|') + ")$";
|
||||
Discourse.Markdown.whiteListTag('code', 'class', new RegExp(regexpSource, "i"));
|
||||
|
@ -301,14 +301,6 @@ Discourse.Markdown.whiteListTag('img', 'src', /^data:image.*$/i);
|
||||
Discourse.Markdown.whiteListTag('div', 'class', 'title');
|
||||
Discourse.Markdown.whiteListTag('div', 'class', 'quote-controls');
|
||||
|
||||
// explicitly whitelist classes we need allowed through for
|
||||
// syntax highlighting, grabbed from highlight.js
|
||||
hljs.listLanguages().forEach(function (language) {
|
||||
Discourse.Markdown.whiteListTag('code', 'class', language);
|
||||
});
|
||||
Discourse.Markdown.whiteListTag('code', 'class', 'text');
|
||||
Discourse.Markdown.whiteListTag('code', 'class', 'lang-auto');
|
||||
|
||||
Discourse.Markdown.whiteListTag('span', 'class', 'mention');
|
||||
Discourse.Markdown.whiteListTag('span', 'class', 'spoiler');
|
||||
Discourse.Markdown.whiteListTag('div', 'class', 'spoiler');
|
||||
|
@ -374,7 +374,7 @@ posting:
|
||||
default: 10000
|
||||
default_code_lang:
|
||||
client: true
|
||||
default: "lang-auto"
|
||||
default: "auto"
|
||||
warn_reviving_old_topic_age: 180
|
||||
autohighlight_all_code:
|
||||
client: true
|
||||
|
Loading…
Reference in New Issue
Block a user