Skip to content

Commit

Permalink
Use event callbacks instead of subextensions
Browse files Browse the repository at this point in the history
  • Loading branch information
TDKorn committed Apr 7, 2024
1 parent f61af91 commit 3edacfb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
9 changes: 6 additions & 3 deletions sphinx_github_style/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@


def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.ext.linkcode')
app.connect("builder-inited", add_static_path)
app.connect('doctree-resolved', add_linkcode_node_class)

app.add_config_value('linkcode_blob', 'head', True)
app.add_config_value('linkcode_link_text', 'View on GitHub', 'html')

linkcode_blob = get_conf_val(app, "linkcode_blob")
linkcode_url = get_linkcode_url(
Expand All @@ -37,10 +41,9 @@ def setup(app: Sphinx) -> Dict[str, Any]:
linkcode_func = get_linkcode_resolve(linkcode_url, repo_dir)
set_conf_val(app, 'linkcode_resolve', linkcode_func)

app.setup_extension('sphinx_github_style.add_linkcode_class')
app.setup_extension('sphinx_github_style.github_style')
app.setup_extension('sphinx.ext.linkcode')
app.add_lexer('python', GitHubLexer)
app.add_css_file('github_style.css')
app.config.pygments_style = 'sphinx_github_style.GitHubStyle'

return {'version': sphinx.__display_version__, 'parallel_read_safe': True}

Expand Down
8 changes: 0 additions & 8 deletions sphinx_github_style/add_linkcode_class.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import sphinx
from sphinx.locale import _
from sphinx.application import Sphinx
from docutils.nodes import Node, Text
from docutils import nodes
from typing import Any, Dict


def add_linkcode_node_class(app: Sphinx, doctree: Node, docname: str) -> None:
Expand All @@ -22,9 +20,3 @@ def add_linkcode_node_class(app: Sphinx, doctree: Node, docname: str) -> None:
if node.parent.get('internal', None) is False:
node['classes'] = ['linkcode-link']
node.children = [Text(_(f'{link_text}'))]


def setup(app: Sphinx) -> Dict[str, Any]:
app.connect('doctree-resolved', add_linkcode_node_class)
app.add_config_value('linkcode_link_text', 'View on GitHub', 'html')
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
5 changes: 0 additions & 5 deletions sphinx_github_style/github_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,3 @@ class GitHubStyle(Style):
Text: pl["syntax-markup-bold"],
}


def setup(app):
app.config.pygments_style = 'sphinx_github_style.GitHubStyle'
app.add_css_file('github_style.css')
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}

0 comments on commit 3edacfb

Please sign in to comment.