Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion myst_parser/warnings_.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def create_warning(
message,
type=type_str,
subtype=subtype_str,
location=node if node is not None else (document["source"], line),
location=node
if node is not None
else (document.settings.env.docname, line),
)
if _is_suppressed_warning(
type_str, subtype_str, document.settings.env.config.suppress_warnings
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sphinx/sourcedirs/substitutions_missing/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extensions = ["myst_parser"]
exclude_patterns = ["_build"]
myst_enable_extensions = ["substitution"]
myst_substitutions = {"defined": "This is defined"}
5 changes: 5 additions & 0 deletions tests/test_sphinx/sourcedirs/substitutions_missing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Title

{{ defined }}

{{ missing }}
21 changes: 21 additions & 0 deletions tests/test_sphinx/test_sphinx_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,27 @@ def test_substitutions(
get_sphinx_app_output(app, filename="index.html", regress_html=True)


@pytest.mark.sphinx(
buildername="html",
srcdir=os.path.join(SOURCE_DIR, "substitutions_missing"),
freshenv=True,
)
def test_substitutions_missing(
app,
status,
warning,
):
"""Test that missing substitution generate warning without '.rst' suffix in location."""
app.build()
assert "build succeeded" in status.getvalue() # Build succeeded
warnings = warning.getvalue().strip().splitlines()
assert len(warnings) == 1
assert (
"index.md:5: WARNING: Substitution error:UndefinedError: 'missing' is undefined [myst.substitution]"
in warnings[0]
)


@pytest.mark.sphinx(
buildername="gettext", srcdir=os.path.join(SOURCE_DIR, "gettext"), freshenv=True
)
Expand Down