Class: Abqari::SyntaxHighlighter::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/abqari/syntax_highlighter.rb

Overview

Writes a syntax stylesheet (Rouge theme) to _site/assets/css/syntax.css. Not fingerprinted — the head partial includes it at a stable URL.

Constant Summary collapse

DARK_MEDIA_SCOPE =

The two dark-mode contexts every theme's token file uses (see docs/theming.md "Dark mode"). The syntax layer mirrors them so code blocks follow the same light/dark resolution as the rest of the page: OS preference unless the visitor chose light, or the explicit toggle.

':root:not([data-theme="light"]) .highlight'
DARK_TOGGLE_SCOPE =
'[data-theme="dark"] .highlight'

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Stylesheet

Returns a new instance of Stylesheet.



61
62
63
# File 'lib/abqari/syntax_highlighter.rb', line 61

def initialize(site)
  @site = site
end

Instance Method Details

#cssObject

The rendered Rouge theme CSS — a light theme at .highlight, a dark theme under the standard dark-mode scopes, and a final override handing the block background to --color-code-bg so the active theme owns it (Rouge's hardcoded backgrounds fight warm palettes and never switched in dark mode). Also consumed by AssetPipeline's CSS bundle, which is what the head partial actually links; the standalone file below stays for sites that override the head partial and reference it directly.



73
74
75
76
77
78
79
80
81
# File 'lib/abqari/syntax_highlighter.rb', line 73

def css
  parts = [light_theme.render(scope: '.highlight')]
  if (dark = dark_theme)
    parts << "@media (prefers-color-scheme: dark) {\n#{dark.render(scope: DARK_MEDIA_SCOPE)}\n}"
    parts << dark.render(scope: DARK_TOGGLE_SCOPE)
  end
  parts << background_override
  parts.join("\n")
end

#writeObject



83
84
85
86
87
88
89
# File 'lib/abqari/syntax_highlighter.rb', line 83

def write
  return unless @site.config['syntax_highlighting']

  dest = File.join(@site.output_dir, 'assets', 'css', 'syntax.css')
  FileUtils.mkdir_p(File.dirname(dest))
  File.write(dest, css)
end