• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2023 The Khronos Group Inc.
2#
3# SPDX-License-Identifier: Apache-2.0
4
5# Khronos overrides for Rouge 'github' theme CSS for accessibility.
6# See (note that this code is evolving, works as of asciidoctor 2.0.12):
7# https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/syntax_highlighter/rouge.rb
8
9include ::Asciidoctor
10
11class ExtendedRougeSyntaxHighlighter < (Asciidoctor::SyntaxHighlighter.for 'rouge')
12  register_for 'rouge'
13
14  # Insert rouge stylesheet from super
15  # Then replace many 'github' theme colors for accessibility compliance
16  # It would be better to use rouge's stylesheet factory, if it has one
17  def docinfo location, doc, opts
18    overrides = %(<style>
19/* Khronos overrides for Rouge 'github' theme for accessibility */
20/* Basically everything is overridden, but it is unclear how to add a new Rouge theme */
21/* Codelike overrides */
22pre.rouge .cm, pre.rouge .cp, pre.rouge .c1, pre.rouge .cs,
23pre.rouge .c, pre.rouge .ch, pre.rouge .cd, pre.rouge .cpf,
24pre.rouge .gh, pre.rouge .bp {
25  color: #5f5f5f;
26}
27/* Numberlike overrides */
28pre.rouge .mf, pre.rouge .mh, pre.rouge .il, pre.rouge .mi,
29pre.rouge .mo, pre.rouge .m, pre.rouge .mb, pre.rouge .mx {
30  color: #007f7f;
31}
32/* Namelike overrides */
33pre.rouge .ne, pre.rouge .nf, pre.rouge .fm, pre.rouge .nl {
34  color: #5f0000;
35}
36/* Other things ANDI warns about - unsure of their purposes */
37pre.rouge .go, pre.rouge .gu {
38  color: #727272;
39}
40pre.rouge .sr {
41  color: #008512;
42}
43pre.rouge .na, pre.rouge .nb {
44  color: #007f7f;
45}
46pre.rouge .no, pre.rouge .vc, pre.rouge .vg, pre.rouge .vi,
47pre.rouge .nv, pre.rouge .vm {
48  color: #007f7f;
49}
50pre.rouge .w {
51  color: #727272;
52}
53</style>)
54
55    # super can return either <style> or <link> markup, both work
56    %(#{super}
57#{overrides})
58  end
59end
60
61