mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-23 05:15:45 -04:00
whitelist acceptable syntax highlighting classes
This commit is contained in:
parent
4bf064c3c6
commit
7a5c3bfcd8
2 changed files with 18 additions and 1 deletions
app/assets/javascripts/discourse/dialects
test/javascripts/components
|
@ -5,11 +5,25 @@
|
|||
@event register
|
||||
@namespace Discourse.Dialect
|
||||
**/
|
||||
|
||||
var acceptableCodeClasses =
|
||||
["lang-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"];
|
||||
|
||||
Discourse.Dialect.replaceBlock({
|
||||
start: /^`{3}([^\n\[\]]+)?\n?([\s\S]*)?/gm,
|
||||
stop: '```',
|
||||
emitter: function(blockContents, matches) {
|
||||
return ['p', ['pre', ['code', {'class': matches[1] || 'lang-auto'}, blockContents.join("\n") ]]];
|
||||
|
||||
var klass = 'lang-auto';
|
||||
if (matches[1] && acceptableCodeClasses.indexOf(matches[1]) !== -1) {
|
||||
klass = matches[1];
|
||||
}
|
||||
return ['p', ['pre', ['code', {'class': klass}, blockContents.join("\n") ]]];
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -300,6 +300,9 @@ test("Code Blocks", function() {
|
|||
"<p><pre><code class=\"ruby\">hello `eviltrout`</code></pre></p>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
cooked("```eviltrout\nhello\n```",
|
||||
"<p><pre><code class=\"lang-auto\">hello</code></pre></p>",
|
||||
"it doesn't not whitelist all classes");
|
||||
|
||||
cooked("```[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]```",
|
||||
"<p><pre><code class=\"lang-auto\">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]</code></pre></p>",
|
||||
|
|
Loading…
Reference in a new issue