Skip to content

Commit 76e2b4f

Browse files
committed
Filter out links from concatenated sources (#14)
1 parent 981b4b1 commit 76e2b4f

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

docs/src/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"sphinx.ext.autodoc",
1717
"sphinx.ext.napoleon",
1818
"sphinx.ext.intersphinx",
19+
"sphinx.ext.extlinks",
1920
"sphinx_rtd_theme",
2021
"sphinx_codeautolink",
2122
]
@@ -34,3 +35,6 @@
3435
"numpy": ("https://numpy.org/doc/stable/", None),
3536
"matplotlib": ("https://matplotlib.org/stable/", None),
3637
}
38+
extlinks = {
39+
'issue': ('https://github.com/felix-hilden/sphinx-codeautolink/issues/%s', '#'),
40+
}

docs/src/examples.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ Examples interlaced with explanations can make for more comprehensible docs.
7979
8080
import sphinx_codeautolink
8181
82+
sphinx_codeautolink.setup()
83+
8284
After explaining some details, the following block may continue where
8385
the previous left off.
8486

8587
.. code:: python
8688
87-
sphinx_codeautolink.setup()
89+
sphinx_codeautolink.parse.parse_names()
8890
8991
This was achieved with::
9092

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Correctly filter out names from concatenated sources (:issue:`14`)
14+
1115
0.1.0 (2021-09-22)
1216
------------------
1317
Initial release

src/sphinx_codeautolink/extension/block.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def visit_literal_block(self, node: nodes.literal_block):
130130
raise ParsingError(msg) from e
131131

132132
if implicit_imports or self.concat_sources:
133-
concat_lens = [source.count('\n') + 1 for source in self.concat_sources]
133+
concat_lens = [s.count('\n') + 1 for s in self.concat_sources]
134134
hidden_len = len(implicit_imports) + sum(concat_lens)
135135
for name in names:
136136
name.lineno -= hidden_len
@@ -144,6 +144,9 @@ def visit_literal_block(self, node: nodes.literal_block):
144144
self.current_document, self.current_refid, list(self.title_stack)
145145
)
146146
for name in names:
147+
if name.lineno < 1:
148+
continue # From concatenated source
149+
147150
if name.lineno != name.end_lineno:
148151
msg = (
149152
'sphinx-codeautolinks: multiline names are not supported, '

0 commit comments

Comments
 (0)