diff --git a/app/assets/javascripts/discourse/dialects/code_dialect.js b/app/assets/javascripts/discourse/dialects/code_dialect.js index 8ef0545296b..0eb5c738a0d 100644 --- a/app/assets/javascripts/discourse/dialects/code_dialect.js +++ b/app/assets/javascripts/discourse/dialects/code_dialect.js @@ -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")); diff --git a/app/assets/javascripts/discourse/lib/markdown.js b/app/assets/javascripts/discourse/lib/markdown.js index f00ad7d696f..040cb3a87f2 100644 --- a/app/assets/javascripts/discourse/lib/markdown.js +++ b/app/assets/javascripts/discourse/lib/markdown.js @@ -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'); diff --git a/config/site_settings.yml b/config/site_settings.yml index 24c190cc241..5fc756b3320 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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