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:
riking 2014-10-05 11:55:57 -07:00 committed by Kane York
parent 22a4ceceee
commit 32cc31319f
3 changed files with 11 additions and 15 deletions

View File

@ -3,12 +3,12 @@
**/ **/
var acceptableCodeClasses = 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", "clojure", "cmake", "coffeescript", "cpp", "cs", "css", "d", "delphi", "diff", "xml", "django", "dos",
"erlang-repl", "erlang", "glsl", "go", "handlebars", "haskell", "http", "ini", "java", "javascript", "erlang-repl", "erlang", "glsl", "go", "handlebars", "haskell", "http", "ini", "java", "javascript",
"json", "lisp", "lua", "markdown", "matlab", "mel", "nginx", "objectivec", "parser3", "perl", "php", "json", "lisp", "lua", "markdown", "matlab", "mel", "nginx", "nohighlight", "objectivec", "parser3",
"profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql", "tex", "text", "perl", "php", "profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql",
"vala", "vbscript", "vhdl"]; "tex", "text", "vala", "vbscript", "vhdl"];
var textCodeClasses = ["text", "pre"]; var textCodeClasses = ["text", "pre"];
@ -32,9 +32,9 @@ Discourse.Dialect.replaceBlock({
} }
if (textCodeClasses.indexOf(matches[1]) !== -1) { if (textCodeClasses.indexOf(matches[1]) !== -1) {
return ['p', ['pre', ['code', flattenBlocks(blockContents) ]]]; return ['p', ['pre', ['code', {'class': 'lang-nohighlight'}, flattenBlocks(blockContents) ]]];
} else { } 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)]]; return ['p', ['pre', flattenBlocks(blockContents)]];
} }
}); });
// Whitelist the language classes
var regexpSource = "^lang-(" + acceptableCodeClasses.join('|') + ")$";
Discourse.Markdown.whiteListTag('code', 'class', new RegExp(regexpSource, "i"));

View File

@ -301,14 +301,6 @@ Discourse.Markdown.whiteListTag('img', 'src', /^data:image.*$/i);
Discourse.Markdown.whiteListTag('div', 'class', 'title'); Discourse.Markdown.whiteListTag('div', 'class', 'title');
Discourse.Markdown.whiteListTag('div', 'class', 'quote-controls'); 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', 'mention');
Discourse.Markdown.whiteListTag('span', 'class', 'spoiler'); Discourse.Markdown.whiteListTag('span', 'class', 'spoiler');
Discourse.Markdown.whiteListTag('div', 'class', 'spoiler'); Discourse.Markdown.whiteListTag('div', 'class', 'spoiler');

View File

@ -374,7 +374,7 @@ posting:
default: 10000 default: 10000
default_code_lang: default_code_lang:
client: true client: true
default: "lang-auto" default: "auto"
warn_reviving_old_topic_age: 180 warn_reviving_old_topic_age: 180
autohighlight_all_code: autohighlight_all_code:
client: true client: true