From 17a4ec1c28e0e6c3d91b78ee2f1258b026345f8a Mon Sep 17 00:00:00 2001 From: "Gerard (Gerry) Caulfield" Date: Wed, 22 Jul 2020 01:11:01 +0200 Subject: [PATCH] Add back support for other syntax highlighting We recently switched to use Rouge for syntax highlighting in the guides, but in doing so we dropped support for highlighting the following syntaxes, which are used in the guides: apache diff json markdown nginx scss xml There was also css and the "javascript" alias, but @eugeneius already addressed these two. They syntaxes were all being converted to "plaintext". This change allows all the lexers mentioned above as well as any other lexers available through Rouge. We have deliberately decided to not support passing rougue custom lexer options from the code fences. Instead any lexer options that are needed can be set by adding an entry to the lexer_language case statement. This should lead to more consistency in formatting and gives us more control over what Rogue options are allowed. --- guides/rails_guides/markdown/renderer.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index 497e8076a6..6aef23f52e 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -68,14 +68,14 @@ module RailsGuides def lexer_language(code_type) case code_type - when "css", "js", "html", "ruby", "sql", "yaml" - code_type - when "erb", "html+erb" + when "html+erb" "erb" when "bash" "console" - else + when nil "plaintext" + else + ::Rouge::Lexer.find(language) ? code_type : "plaintext" end end