Skip to content

Commit 4bb8ef9

Browse files
committed
DOC: gh-example role
1 parent 5c1a9de commit 4bb8ef9

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

doc/conf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,19 @@
7575
latex_documents = [('index', 'python-sounddevice.tex', project, authors, 'howto')]
7676
latex_show_urls = 'footnote'
7777
latex_domain_indices = False
78+
79+
80+
def gh_example_role(rolename, rawtext, text, lineno, inliner,
81+
options={}, content=()):
82+
from docutils import nodes, utils
83+
github_url = 'https://github.com/spatialaudio/python-sounddevice'
84+
base_url = github_url + '/blob/' + release + '/examples/%s'
85+
text = utils.unescape(text)
86+
full_url = base_url % text
87+
pnode = nodes.reference(internal=False, refuri=full_url)
88+
pnode += nodes.literal(text, text, classes=['file'])
89+
return [pnode], []
90+
91+
92+
def setup(app):
93+
app.add_role('gh-example', gh_example_role)

doc/examples.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,69 @@
33
Play a Sound File
44
-----------------
55

6-
:download:`play_file.py <../examples/play_file.py>`
6+
:gh-example:`play_file.py`
77

88
.. literalinclude:: ../examples/play_file.py
99

1010
Play a Very Long Sound File
1111
---------------------------
1212

13-
:download:`play_long_file.py <../examples/play_long_file.py>`
13+
:gh-example:`play_long_file.py`
1414

1515
.. literalinclude:: ../examples/play_long_file.py
1616

1717
Play a Web Stream
1818
-----------------
1919

20-
:download:`play_stream.py <../examples/play_stream.py>`
20+
:gh-example:`play_stream.py`
2121

2222
.. literalinclude:: ../examples/play_stream.py
2323

2424
Play a Sine Signal
2525
------------------
2626

27-
:download:`play_sine.py <../examples/play_sine.py>`
27+
:gh-example:`play_sine.py`
2828

2929
.. literalinclude:: ../examples/play_sine.py
3030

3131
Input to Output Pass-Through
3232
----------------------------
3333

34-
:download:`wire.py <../examples/wire.py>`
34+
:gh-example:`wire.py`
3535

3636
.. literalinclude:: ../examples/wire.py
3737

3838
Plot Microphone Signal(s) in Real-Time
3939
--------------------------------------
4040

41-
:download:`plot_input.py <../examples/plot_input.py>`
41+
:gh-example:`plot_input.py`
4242

4343
.. literalinclude:: ../examples/plot_input.py
4444

4545
Real-Time Text-Mode Spectrogram
4646
-------------------------------
4747

48-
:download:`spectrogram.py <../examples/spectrogram.py>`
48+
:gh-example:`spectrogram.py`
4949

5050
.. literalinclude:: ../examples/spectrogram.py
5151

5252
Recording with Arbitrary Duration
5353
---------------------------------
5454

55-
:download:`rec_unlimited.py <../examples/rec_unlimited.py>`
55+
:gh-example:`rec_unlimited.py`
5656

5757
.. literalinclude:: ../examples/rec_unlimited.py
5858

5959
Using a stream in an `asyncio` coroutine
6060
----------------------------------------
6161

62-
:download:`asyncio_coroutines.py <../examples/asyncio_coroutines.py>`
62+
:gh-example:`asyncio_coroutines.py`
6363

6464
.. literalinclude:: ../examples/asyncio_coroutines.py
6565

6666
Creating an `asyncio` generator for audio blocks
6767
------------------------------------------------
6868

69-
:download:`asyncio_generators.py <../examples/asyncio_generators.py>`
69+
:gh-example:`asyncio_generators.py`
7070

7171
.. literalinclude:: ../examples/asyncio_generators.py

0 commit comments

Comments
 (0)