1
+ .. |.~.get_linkcode_resolve | replace :: ``get_linkcode_resolve() ``
2
+ .. _.~.get_linkcode_resolve : https://sphinx-github-style.readthedocs.io/en/latest/modules.html#sphinx_github_style.__init__.get_linkcode_resolve
3
+ .. |linkcode_blob | replace :: ``linkcode_blob ``
4
+ .. _linkcode_blob : https://sphinx-github-style.readthedocs.io/en/latest/index.html#confval-linkcode_blob
5
+ .. |linkcode_link_text | replace :: ``linkcode_link_text ``
6
+ .. _linkcode_link_text : https://sphinx-github-style.readthedocs.io/en/latest/index.html#confval-linkcode_link_text
7
+ .. |linkcode_resolve | replace :: ``linkcode_resolve ``
8
+ .. _linkcode_resolve : https://sphinx-github-style.readthedocs.io/en/latest/index.html#confval-linkcode_resolve
9
+ .. |linkcode_url | replace :: ``linkcode_url ``
10
+ .. _linkcode_url : https://sphinx-github-style.readthedocs.io/en/latest/index.html#confval-linkcode_url
11
+ .. |sphinx+html_context | replace :: ``html_context ``
12
+ .. _sphinx+html_context : https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_context
13
+ .. |.sphinx.ext.linkcode | replace :: ``sphinx.ext.linkcode ``
14
+ .. _.sphinx.ext.linkcode : https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html#module-sphinx.ext.linkcode
15
+ .. |.sphinx.ext.viewcode | replace :: ``sphinx.ext.viewcode ``
16
+ .. _.sphinx.ext.viewcode : https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html#module-sphinx.ext.viewcode
17
+ .. |top_level | replace :: ``top_level ``
18
+ .. _top_level : https://sphinx-github-style.readthedocs.io/en/latest/index.html#confval-top_level
19
+
1
20
.. Title: Sphinx Github Style
2
21
.. Description: A Sphinx extension to add GitHub source code links and syntax highlighting
3
22
.. Author: TDKorn (Adam Korn)
4
23
5
24
.. meta ::
6
25
:title: Sphinx Github Style
7
26
:description: A Sphinx extension to add GitHub source code links and syntax highlighting
8
-
9
- .. |.get_linkcode_resolve | replace :: ``get_linkcode_resolve() ``
10
- .. _.get_linkcode_resolve : https://github.com/TDKorn/sphinx-github-style/blob/v1.0.5/sphinx_github_style/__init__.py#L148-L214
11
- .. |.add_linkcode_node_class | replace :: ``add_linkcode_node_class() ``
12
- .. _.add_linkcode_node_class : https://github.com/TDKorn/sphinx-github-style/blob/v1.0.5/sphinx_github_style/add_linkcode_class.py#L9-L24
13
- .. |.TDKStyle | replace :: ``TDKStyle ``
14
- .. _.TDKStyle : https://github.com/TDKorn/sphinx-github-style/blob/v1.0.5/sphinx_github_style/github_style.py#L44-L139
15
- .. |.TDKMethLexer | replace :: ``TDKMethLexer ``
16
- .. _.TDKMethLexer : https://github.com/TDKorn/sphinx-github-style/blob/v1.0.5/sphinx_github_style/meth_lexer.py#L27-L42
27
+
28
+
17
29
.. |.github_style | replace :: ``github_style.css ``
18
- .. _.github_style : https://github.com/tdkorn/sphinx-github-style/blob/v1.0.5/sphinx_github_style/_static/github_style.css
19
- .. |RTD | replace :: ReadTheDocs
20
- .. _RTD : https://sphinx-github-style.readthedocs.io/en/latest/
21
- .. |docs | replace :: **Explore the docs » **
22
- .. _docs : https://sphinx-github-style.readthedocs.io/en/latest/
30
+ .. _.github_style : https://github.com/tdkorn/sphinx-github-style/tree/v1.0.4/sphinx_github_style/_static/github_style.css
31
+
32
+
33
+
23
34
24
35
25
36
.. raw :: html
26
37
27
38
<div align =" center" >
28
39
29
40
30
- .. image :: docs/source/_static/logo_square_grey_blue.png
41
+ .. image :: https://raw.githubusercontent.com/TDKorn/sphinx-github-style/master/ docs/source/_static/logo_square_grey_blue.png
31
42
:alt: Sphinx GitHub Style: GitHub Integration and Pygments Style for Sphinx Documentation
32
43
:width: 25%
33
44
45
+
46
+
34
47
.. raw :: html
35
48
36
49
<h1 >Sphinx Github Style</h1 >
37
50
38
- GitHub source code links and syntax highlighting for Sphinx docs
51
+
52
+ GitHub source code links and syntax highlighting for Sphinx documentation
53
+
54
+
55
+ .. |docs | replace :: **Explore the docs » **
56
+ .. _docs : https://sphinx-github-style.readthedocs.io/en/latest/
39
57
40
58
|docs |_
41
59
60
+
61
+
62
+
42
63
.. image :: https://img.shields.io/pypi/v/sphinx-github-style?color=eb5202
43
64
:target: https://pypi.org/project/sphinx-github-style/
44
65
:alt: PyPI Version
@@ -61,63 +82,73 @@ GitHub source code links and syntax highlighting for Sphinx docs
61
82
<br />
62
83
63
84
85
+
64
86
About
65
87
~~~~~~~~~~~~~
66
88
67
- ``sphinx-github-style `` is a Sphinx extension that makes your docs look like and link to GitHub
89
+ ``sphinx-github-style `` is a Sphinx extension that links your documentation to GitHub source code.
90
+ It also adds syntax highlighting for code blocks similar to GitHub's pretty lights dark theme.
68
91
69
92
...
70
93
94
+
71
95
GitHub Source Code Links
72
96
===============================
73
97
74
- .. |linkcode | replace :: ``sphinx.ext.linkcode ``
75
- .. _linkcode : https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html
76
98
77
- ** Using ** | linkcode |_, a ``View on GitHub `` ** link is added to the documentation of every class, method and function: **
99
+ Using | .sphinx.ext. linkcode |_, a ``View on GitHub `` link is added to the documentation of every class, method, function, and property:
78
100
79
- .. image :: https://user-images.githubusercontent.com/96394652/220941352-f5530a56-d338-4b90-b83a-4b22b0f632fe.png
80
- :alt: sphinx github style adds a "View on GitHub" link
81
101
82
- **They link to and highlight the corresponding code block in your GitHub repo: **
83
102
84
- .. image :: https://user-images.githubusercontent.com/96394652/220945912-447173db-2ac7-4e00-bec5-3859753bf687.png
85
103
86
104
87
- |
105
+ .. image :: https://raw.githubusercontent.com/TDKorn/sphinx-github-style/master/docs/source/_static/github_link.png
106
+ :alt: sphinx-github-style adds a "View on GitHub" link
107
+
108
+
109
+ They link to and highlight the corresponding code block in your GitHub repository:
110
+
111
+
112
+
113
+ .. image :: https://raw.githubusercontent.com/TDKorn/sphinx-github-style/master/docs/source/_static/github_linked_code.png
114
+ :alt: The linked corresponding highlighted source code block on GitHub
115
+
116
+
88
117
89
118
.. raw :: html
90
119
91
120
<table >
92
- <tr align =" left" >
93
- <th >📝 Note</th >
94
- </tr >
95
- <tr >
96
- <td >
121
+ <tr align =" left" >
122
+ <th >
97
123
98
- These links can be used with/instead of the links added by `` sphinx.ext.viewcode ``
124
+ 📝 Note
99
125
100
- * They use a newly added ``linkcode-link `` class which can be styled using CSS
126
+ .. raw :: html
127
+
128
+ </th >
129
+ <tr ><td >
101
130
131
+ These links can be `styled with CSS <https://sphinx-github-style.readthedocs.io/en/latest/add_linkcode_class.html >`_ and used with/instead
132
+ of the links added by |.sphinx.ext.viewcode |_
102
133
103
134
.. raw :: html
104
135
105
136
</td ></tr >
106
137
</table >
107
138
108
139
109
- |
110
140
111
141
Syntax Highlighting
112
142
====================
113
143
114
- ``sphinx-github-style `` ** also contains a ** ``Pygments `` ** style to highlight code in your documentation similar to GitHub: **
144
+ ``sphinx-github-style `` also contains a ``Pygments `` style to highlight code blocks similar to GitHub:
115
145
116
146
117
- .. image :: https://user-images.githubusercontent.com/96394652/220946796-bf7aa236-964d-48e7-83e2-142aac00b0dd.png
147
+
148
+ .. image :: https://raw.githubusercontent.com/TDKorn/sphinx-github-style/master/docs/source/_static/syntax_highlighting.png
149
+ :alt: A code block highlighted by the Pygments style. It looks identical to GitHub.
118
150
119
151
120
- |
121
152
122
153
Installation
123
154
~~~~~~~~~~~~~~~~
@@ -126,7 +157,6 @@ To install using ``pip``::
126
157
127
158
pip install sphinx-github-style
128
159
129
- |
130
160
131
161
Configuration
132
162
~~~~~~~~~~~~~~~
@@ -139,93 +169,58 @@ Add the extension to your ``conf.py``
139
169
" sphinx_github_style" ,
140
170
]
141
171
142
- ...
143
-
144
172
Optional Configuration Variables
145
173
===================================
146
174
147
175
Add any (or none) of the following configuration variables to your ``conf.py ``
148
176
149
177
150
- ``top_level ``
151
- ^^^^^^^^^^^^^^^^^^^
152
-
153
- .. code-block :: python
154
-
155
- top_level: str
156
-
157
- The name of the package's top-level module. For this repo, it would be ``sphinx_github_style ``
158
-
159
- ...
160
-
161
-
162
- ``linkcode_blob ``
163
- ^^^^^^^^^^^^^^^^^^^
164
-
165
- .. code-block :: python
166
-
167
- linkcode_blob: str = " head"
168
-
169
178
170
- The blob to link to on GitHub - any of ``"head" ``, ``"last_tag" ``, or ``"{blob}" ``
171
179
172
- * ``head `` (default): links to the most recent commit hash; if this commit is tagged, uses the tag instead
173
- * ``last_tag ``: links to the most recent commit tag on the currently checked out branch
174
- * ``blob ``: links to any blob you want, for example ``"master" `` or ``"v2.0.1" ``
180
+ |top_level |_
181
+ The name of the package's top-level module. For this repo, it would be ``sphinx_github_style ``
175
182
183
+ **Type: ** ``str ``
176
184
177
- ...
178
-
179
- ``linkcode_url ``
180
- ^^^^^^^^^^^^^^^^^^^
181
-
182
- .. code-block :: python
183
-
184
- linkcode_url: str = f " https://github.com/ { html_context[' github_user' ]} / { html_context[' github_repo' ]} / { html_context[' github_version' ]} "
185
-
186
- The link to your GitHub repository formatted as ``https://github.com/user/repo ``
185
+ |
187
186
188
- * If not provided, will attempt to create the link from the ``html_context `` dict
187
+ |linkcode_blob |_
188
+ The blob to link to on GitHub - any of ``"head" ``, ``"last_tag" ``, or ``"{blob}" ``
189
189
190
- ...
190
+ ** Type: ** `` str ``
191
191
192
- ``linkcode_link_text ``
193
- ^^^^^^^^^^^^^^^^^^^^^^
192
+ **Default: ** ``"head" ``
194
193
195
- .. code-block :: python
194
+ * ``"head" `` (default): links to the most recent commit hash; if this commit is tagged, uses the tag instead
195
+ * ``"last_tag" ``: links to the most recent commit tag on the currently checked out branch
196
+ * ``"blob" ``: links to any blob you want, for example ``"master" `` or ``"v2.0.1" ``
196
197
197
- linkcode_link_text: str = " View on GitHub "
198
+ |
198
199
200
+ |linkcode_url |_
201
+ The link to your GitHub repository formatted as ``https://github.com/user/repo ``
199
202
200
- The text to use for the linkcode link
203
+ ** Type: ** `` str ``
201
204
202
- ...
205
+ ** Default: ** `` f"https://github.com/{html_context['github_user']}/{html_context['github_repo']}/{html_context['github_version']}" ``
203
206
204
- ``linkcode_resolve ``
205
- ^^^^^^^^^^^^^^^^^^^^^^^^
207
+ * If not provided, will attempt to create the link from the |sphinx+html_context |_ dict
206
208
207
- .. code-block :: python
209
+ |
208
210
209
- linkcode_resolve: Callable
211
+ |linkcode_link_text |_
212
+ The text to use for the linkcode link
210
213
211
- A `` linkcode_resolve() `` function to use for resolving the link target
214
+ ** Type: ** `` str ``
212
215
213
- * Uses default function from | .get_linkcode_resolve |_ if not specified (recommended)
216
+ ** Default: ** `` "View on GitHub" ``
214
217
215
218
|
216
219
217
- Noteworthy Components
218
- ~~~~~~~~~~~~~~~~~~~~~
219
-
220
- * |.TDKStyle |_ - Pygments Style for syntax highlighting similar to Github Pretty Lights Dark Theme
221
- * |.TDKMethLexer |_ - Pygments Lexor to add syntax highlighting to methods
222
- * |.get_linkcode_resolve |_ - to link to GitHub source code using ``sphinx.ext.linkcode ``
223
- * |.add_linkcode_node_class |_ - adds a new ``linkcode-link `` class, allowing for CSS styling separately from ``viewcode `` links
224
- * |.github_style |_ - CSS styling for linkcode links (icon + text)
220
+ |linkcode_resolve |_
221
+ A ``linkcode_resolve() `` function to use when resolving the link target with |.sphinx.ext.linkcode |_
225
222
226
- |
223
+ ** Type: ** `` Callable ``
227
224
228
- Documentation
229
- ~~~~~~~~~~~~~~~~
225
+ **Default: ** Return value from |.~.get_linkcode_resolve |_
230
226
231
- Full documentation can be found on |RTD |_
0 commit comments