Allow different casings to be specified for syntax highlighting (#6354)

This commit is contained in:
rhymes 2020-02-28 18:36:27 +01:00 committed by GitHub
parent 6795be006d
commit 2b31a9b9ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -5,6 +5,13 @@ module Redcarpet
class HTMLRouge < HTML
include Rouge::Plugins::Redcarpet
# Rouge requires the hint language to be lower case, by overriding this
# method we can allow the hint language to be specified with other casings
# eg. `Ada` instead of `ada`
def block_code(code, language)
super(code, language.to_s.downcase)
end
def link(link, _title, content)
# Probably not the best fix but it does it's job of preventing
# a nested links.

View file

@ -314,4 +314,21 @@ RSpec.describe MarkdownParser, type: :labor do
expect(generate_and_parse_markdown(code_block)).to include("word_<em>italic</em>_")
end
end
context "when adding syntax highlighting" do
it "defaults to plaintext" do
code_block = "```\ntext\n````"
expect(generate_and_parse_markdown(code_block)).to include("highlight plaintext")
end
it "adds correct syntax highlighting to codeblocks when the hint is not lowercase" do
code_block = "```Ada\nwith Ada.Directories;\n````"
expect(generate_and_parse_markdown(code_block)).to include("highlight ada")
end
it "adds correct syntax highlighting to codeblocks when the hint is lowercase" do
code_block = "```ada\nwith Ada.Directories;\n````"
expect(generate_and_parse_markdown(code_block)).to include("highlight ada")
end
end
end