This might be an RST bug, but with this in my conf.py:
rst_prolog = """
.. |br| raw:: html
<br />
"""
And then this file:
Line 1
Line 5
|br|
|br|
Line 10
Err on line 12 :ref:`foo`
The incorrect reference is reported as:
/docs/source/test.rst:18: WARNING: undefined label: foo (if the link has no caption the label must precede a section header)
Which says line 18, when it is actually line 12. This is because of the rst substitution, but with a longer file in a real use case, it makes it almost impossible to find the actual line the bug is on.
The title of this issue is too limiting (although we thought that was the initial problem, which I reported to Eric).
I see errors in files that do not contain replacements/substitutions at all - the line numbers are just way off. Most recently, they generally add 20 to the line number.
The attached dummy file (saved as rst locally, obviously) with an error at line 13, shows an error at line 33.
reading sources... [100%] getting-started/send-data
/Users/barbara/Documents/github-sfx/docs/getting-started/send-data.rst:33: WARNING: Inline interpreted text or phrase reference start-string without end-string.
/Users/barbara/Documents/github-sfx/docs/getting-started/send-data.rst:33: WARNING: Inline interpreted text or phrase reference start-string without end-string.
P.S. I do have rst_prolog in my conf.py, which is in fact 20 lines long. So it appears that is getting added to the line count before the error is generated. (Thanks to @ericholscher for suggesting that was the problem.)
It seems substitution is not related with the increase of line numbers.
In the case above, the rst_prolog has 6 lines. Simply, these lines affects to the line numbers.
In sphinx.io.SphinxFileInput.read(), sphinx simply prepends rst_prolog to the file contents before parsing reST.
This confuses the following processors.
To resolve this, we have to adjust line numbers if any rst_prolog is set.
But, at the same time, we have to treat the errors on rst_prolog. Or some warnings show a minus line numbers :-p
But, at the same time, we have to treat the errors on rst_prolog. Or some warnings show a minus line numbers
Perhaps report that the error is in rst_prolog if the line number is negative?
Oh, this is already fixed by #4294.
Thanks,
Most helpful comment
It seems substitution is not related with the increase of line numbers.
In the case above, the
rst_prologhas 6 lines. Simply, these lines affects to the line numbers.In
sphinx.io.SphinxFileInput.read(), sphinx simply prependsrst_prologto the file contents before parsing reST.This confuses the following processors.
To resolve this, we have to adjust line numbers if any
rst_prologis set.But, at the same time, we have to treat the errors on
rst_prolog. Or some warnings show a minus line numbers :-p