Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Created December 6, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/9d56031b09e0f7d864b0c3e0f5f9f91f to your computer and use it in GitHub Desktop.
Save tk0miya/9d56031b09e0f7d864b0c3e0f5f9f91f to your computer and use it in GitHub Desktop.
# extension testbed
# Description: ``:index:`` ロールのタイトルを強調表示する
from docutils import nodes
from sphinx import addnodes
from sphinx.transforms import SphinxTransform
class IndexStyleTransform(SphinxTransform):
default_priority = 200
def apply(self):
for node in self.document.traverse(addnodes.index):
# Note: index ロールは index, target, text の順でノードを生成する
# refs: sphinx/roles:Index
siblings = node.traverse(siblings=True, include_self=False)
text = siblings[1]
node.parent.replace(text, nodes.strong(text, text))
def setup(app):
app.add_transform(IndexStyleTransform)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment