Skip to content

Commit

Permalink
allow individual code block theme overrides
Browse files Browse the repository at this point in the history
Provides support for individual code blocks to be configured with a
custom Confluence theme. The translator will now process class hints on
literal blocks for a `confluence-theme-<theme>` pattern.

Signed-off-by: James Knight <james.d.knight@live.com>
  • Loading branch information
jdknight committed Jul 15, 2023
1 parent a388a70 commit 85deb3c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions sphinxcontrib/confluencebuilder/storage/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sphinxcontrib.confluencebuilder.std.confluence import LITERAL2LANG_FBMAP_V2
from sphinxcontrib.confluencebuilder.std.confluence import LITERAL2LANG_MAP_V1
from sphinxcontrib.confluencebuilder.std.confluence import LITERAL2LANG_MAP_V2
from sphinxcontrib.confluencebuilder.std.confluence import SUPPORTED_CODE_BLOCK_THEMES
from sphinxcontrib.confluencebuilder.std.sphinx import DEFAULT_HIGHLIGHT_STYLE
from sphinxcontrib.confluencebuilder.storage import encode_storage_format
from sphinxcontrib.confluencebuilder.storage import intern_uri_anchor_value
Expand Down Expand Up @@ -780,9 +781,21 @@ def visit_literal_block(self, node):
self.body.append(self._build_ac_param(node, 'language', lang))
self.body.append(self._build_ac_param(node, 'linenumbers', num))

if self.builder.config.confluence_code_block_theme:
theme = self.builder.config.confluence_code_block_theme
self.body.append(self._build_ac_param(node, 'theme', theme))
theme = self.builder.config.confluence_code_block_theme
theme = theme.lower() if theme else None
theme_map = SUPPORTED_CODE_BLOCK_THEMES

for class_ in node.get('classes', []):
if class_.startswith('confluence-theme-'):
theme = class_[len('confluence-theme-'):].lower()
if theme not in theme_map:
self.warn('confluence-theme-* defined an unknown theme: ' +
theme)
break

theme_id = theme_map.get(theme)
if theme_id:
self.body.append(self._build_ac_param(node, 'theme', theme_id))

if firstline is not None and firstline > 1:
self.body.append(
Expand Down

0 comments on commit 85deb3c

Please sign in to comment.