Skip to content

Commit d6a1cbc

Browse files
committed
Restrict Rouge formatters to Rouge::Formatters namespace
ff0218a added support for specifying custom Rouge formatters with the constraint that the formatter be in theRouge::Formatters namespace, but it did not actually enforce this constraint. For example, this is valid: ```ruby Rouge::Formatters.const_get('CSV') => CSV ``` Adding the `false` parameter to `const_get` prevents this: ```ruby Rouge::Formatters.const_get('CSV', false) NameError: uninitialized constant Rouge::Formatters::CSV ```
1 parent 9cb5afc commit d6a1cbc

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

lib/kramdown/converter/syntax_highlighter/rouge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.formatter_class(opts = {})
7070
when Class
7171
formatter
7272
when /\A[[:upper:]][[:alnum:]_]*\z/
73-
::Rouge::Formatters.const_get(formatter)
73+
::Rouge::Formatters.const_get(formatter, false)
7474
else
7575
# Available in Rouge 2.0 or later
7676
::Rouge::Formatters::HTMLLegacy

test/test_files.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
end
2222

2323
# custom formatter for tests
24-
class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class
24+
module Rouge
25+
module Formatters
26+
class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class
2527

26-
tag 'rouge_html_formatters'
28+
tag 'rouge_html_formatters'
2729

28-
def stream(tokens, &b)
29-
yield %(<div class="custom-class">)
30-
super
31-
yield %(</div>)
32-
end
30+
def stream(tokens, &b)
31+
yield %(<div class="custom-class">)
32+
super
33+
yield %(</div>)
34+
end
3335

36+
end
37+
end
3438
end
3539
rescue LoadError, SyntaxError, NameError
3640
end

0 commit comments

Comments
 (0)