|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require 'rouge' |
2 | 4 |
|
3 | 5 | # Include tabindex for accessibility reasons |
4 | 6 | # See: https://github.com/rouge-ruby/rouge?tab=readme-ov-file#formatters |
5 | | -class Rouge::Formatters::HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments |
6 | | - def stream(tokens, &b) |
7 | | - yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>) |
8 | | - @inner.stream(tokens, &b) |
9 | | - yield "</code></pre></div>" |
| 7 | +module Rouge |
| 8 | + module Formatters |
| 9 | + class HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments |
| 10 | + def stream(tokens, &) |
| 11 | + yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>) |
| 12 | + @inner.stream(tokens, &) |
| 13 | + yield '</code></pre></div>' |
| 14 | + end |
| 15 | + end |
10 | 16 | end |
11 | 17 | end |
12 | 18 |
|
13 | | -class Rouge::Formatters::HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy |
14 | | - def initialize(opts={}) |
15 | | - @formatter = opts[:inline_theme] ? Rouge::Formatters::HTMLInline.new(opts[:inline_theme]) |
16 | | - : Rouge::Formatters::HTML.new |
| 19 | +module Rouge |
| 20 | + module Formatters |
| 21 | + class HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy |
| 22 | + def initialize(opts = {}) # rubocop:disable Lint/MissingSuper |
| 23 | + @formatter = if opts[:inline_theme] |
| 24 | + Rouge::Formatters::HTMLInline.new(opts[:inline_theme]) |
| 25 | + else |
| 26 | + Rouge::Formatters::HTML.new |
| 27 | + end |
17 | 28 |
|
| 29 | + @formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers] |
18 | 30 |
|
19 | | - @formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers] |
| 31 | + return unless opts.fetch(:wrap, true) |
20 | 32 |
|
21 | | - if opts.fetch(:wrap, true) |
22 | | - @formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite')) |
| 33 | + @formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite')) |
| 34 | + end |
23 | 35 | end |
24 | 36 | end |
25 | 37 | end |
0 commit comments