From bfa68f08dd6116070015a95971b5201f20c360a6 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Sat, 19 Feb 2022 19:49:09 -0800 Subject: [PATCH] Transform rouge options keys into symbols. --- CHANGELOG.md | 4 ++++ lib/kitabu/extensions/rouge.rb | 2 ++ spec/kitabu/markdown_spec.rb | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28740af..866fe7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fix Rouge options keys; symbols are required. + ## v3.0.2 - Fix `styles` directory copying. diff --git a/lib/kitabu/extensions/rouge.rb b/lib/kitabu/extensions/rouge.rb index 1848caa..1fad81b 100644 --- a/lib/kitabu/extensions/rouge.rb +++ b/lib/kitabu/extensions/rouge.rb @@ -5,6 +5,8 @@ module Plugins module Redcarpet def rouge_formatter(lexer) options = lexer.respond_to?(:options) ? lexer.options : {} + options = options.keys.map(&:to_sym).zip(options.values).to_h + options[:start_line] = options.fetch(:start_line, 1).to_i Formatters::HTMLLegacy.new( {css_class: "highlight #{lexer.tag}"}.merge(options) diff --git a/spec/kitabu/markdown_spec.rb b/spec/kitabu/markdown_spec.rb index 65cf537..8a69b0a 100644 --- a/spec/kitabu/markdown_spec.rb +++ b/spec/kitabu/markdown_spec.rb @@ -24,6 +24,17 @@ class User expect(html).to include('echo') end + it "enables line numbers" do + html = Kitabu::Markdown.render <<-TEXT.strip_heredoc + ```ruby?line_numbers=true + class User + end + ``` + TEXT + + expect(html).to include(%[]) + end + it "does not raise with unknown lexers" do expect do Kitabu::Markdown.render <<-TEXT.strip_heredoc