Skip to content

Commit 7616de6

Browse files
committed
LG-12800 tabindex on code blocks
1 parent fdec3c7 commit 7616de6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ kramdown:
2828
hard_wrap: true
2929
syntax_highlighter: rouge
3030
syntax_highlighter_opts:
31-
formatter: HTMLPygmentsA11y
31+
formatter: HTMLLegacyA11y
3232

3333
sass:
3434
load_paths:

_plugins/content_code.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
require 'rouge'
2+
23
# Include tabindex for accessibility reasons
3-
class HTMLPygmentsA11y < Rouge::Formatters::HTML
4+
class Rouge::Formatters::HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments
5+
def initialize(inner, css_class='codehilite')
6+
@inner = inner
7+
@css_class = css_class
8+
end
9+
410
def stream(tokens, &b)
511
yield %(<div class="highlight"><pre class="#{@css_class}"><code tabindex="0">)
612
@inner.stream(tokens, &b)
7-
yield "</code></pre></div"
13+
yield "</code></pre></div>"
14+
end
15+
end
16+
17+
class Rouge::Formatters::HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy
18+
def initialize(opts={})
19+
@formatter = opts[:inline_theme] ? HTMLInline.new(opts[:inline_theme])
20+
: Rouge::Formatters::HTML.new
21+
22+
23+
@formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers]
24+
25+
if opts.fetch(:wrap, true)
26+
@formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite'))
27+
end
28+
end
29+
30+
# @yield the html output.
31+
def stream(tokens, &b)
32+
@formatter.stream(tokens, &b)
833
end
934
end

0 commit comments

Comments
 (0)