Repository: executablebooks/MyST-Parser (python)

Issue:
sphinx.errors.NoUri
### Describe the bug

**context**
I don't know whether this error relates to MyST-Parser, but I began getting this error after MyST-Parser 0.19.0 was released.

**expectation**
I expected no errors like my previous builds with myst v0.18.1.
https://readthedocs.org/projects/deepmd/builds/19634134/

**bug**
But instead, the `sphinx.errors.NoUri` error happens after myst v0.19.0 was released.
https://readthedocs.org/projects/deepmd/builds/19635616/
https://readthedocs.org/projects/deepmd/builds/19635930/
https://readthedocs.org/projects/deepmd/builds/19647300/

Here's an error message I ran into...

```console
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/cmd/build.py", line 284, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_update()
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 308, in build_update
    self.build(['__all__'], to_build)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 377, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/latex/__init__.py", line 288, in write
    doctree = self.assemble_doctree(
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/latex/__init__.py", line 354, in assemble_doctree
    self.env.resolve_references(largetree, indexfile, self)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 656, in resolve_references
    self.apply_post_transforms(doctree, fromdocname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 668, in apply_post_transforms
    transformer.apply_transforms()
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/transforms/__init__.py", line 80, in apply_transforms
    super().apply_transforms()
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/docutils/transforms/__init__.py", line 171, in apply_transforms
    transform.apply(**kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/transforms/post_transforms/__init__.py", line 37, in apply
    self.run(**kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/myst_parser/sphinx_ext/myst_refs.py", line 80, in run
    self.resolve_myst_ref_doc(node)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/myst_parser/sphinx_ext/myst_refs.py", line 181, in resolve_myst_ref_doc
    ref_node = make_refnode(
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/util/nodes.py", line 550, in make_refnode
    node['refuri'] = builder.get_relative_uri(fromdocname, todocname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/latex/__init__.py", line 141, in get_relative_uri
    return self.get_target_uri(to, typ)
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/latex/__init__.py", line 135, in get_target_uri
    raise NoUri(docname, typ)
sphinx.errors.NoUri: ('install/install-tf.2.8', None)

Exception occurred:
  File "/home/docs/checkouts/readthedocs.org/user_builds/deepmd/conda/latest/lib/python3.9/site-packages/sphinx/builders/latex/__init__.py", line 135, in get_target_uri
    raise NoUri(docname, typ)
sphinx.errors.NoUri: ('install/install-tf.2.8', None)
The full traceback has been saved in /tmp/sphinx-err-0n6n9ja3.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
```

**problem**
Indeed I don't know the reason.


### Reproduce the bug

This is my repository: https://github.com/deepmodeling/deepmd-kit/tree/devel/doc

The error happens in this file:
https://github.com/deepmodeling/deepmd-kit/blob/devel/doc/install/install-from-source.md

with this sentence:
```md
You may follow [the instruction](install-tf.2.8.md) or run the script `$deepmd_source_dir/source/install/build_tf.py` to install the corresponding C++ interface.
```

### List your environment

The error happens on the Read the doc server.
```py
python 3.9.16
Sphinx 6.1.3
myst-parser 0.19.0
sphinx_rtd_theme 1.2.0
```

Pull request:
🐛 FIX NoURI error in doc reference resolution
closes #733 

Patch:
diff --git a/myst_parser/sphinx_ext/myst_refs.py b/myst_parser/sphinx_ext/myst_refs.py
index 8a4dc20..74edcb3 100644
--- a/myst_parser/sphinx_ext/myst_refs.py
+++ b/myst_parser/sphinx_ext/myst_refs.py
@@ -178,9 +178,12 @@ class MystReferenceResolver(ReferencesResolver):
             )
 
         assert self.app.builder
-        ref_node = make_refnode(
-            self.app.builder, from_docname, ref_docname, targetid, innernode
-        )
+        try:
+            ref_node = make_refnode(
+                self.app.builder, from_docname, ref_docname, targetid, innernode
+            )
+        except NoUri:
+            ref_node = innernode
         node.replace_self(ref_node)
 
     def resolve_myst_ref_any(


Test patch:
diff --git a/tests/test_sphinx/sourcedirs/texi_table/index.md b/tests/test_sphinx/sourcedirs/texi_table/index.md
deleted file mode 100644
index 9face4b..0000000
--- a/tests/test_sphinx/sourcedirs/texi_table/index.md
+++ /dev/null
@@ -1,3 +0,0 @@
-| foo | bar |
-| --- | --- |
-| baz | bim |
diff --git a/tests/test_sphinx/sourcedirs/texi_table/conf.py b/tests/test_sphinx/sourcedirs/texinfo/conf.py
similarity index 100%
rename from tests/test_sphinx/sourcedirs/texi_table/conf.py
rename to tests/test_sphinx/sourcedirs/texinfo/conf.py
diff --git a/tests/test_sphinx/sourcedirs/texinfo/file.md b/tests/test_sphinx/sourcedirs/texinfo/file.md
new file mode 100644
index 0000000..eeea438
--- /dev/null
+++ b/tests/test_sphinx/sourcedirs/texinfo/file.md
@@ -0,0 +1,3 @@
+---
+orphan: true
+---
diff --git a/tests/test_sphinx/sourcedirs/texinfo/index.md b/tests/test_sphinx/sourcedirs/texinfo/index.md
new file mode 100644
index 0000000..c0f15f9
--- /dev/null
+++ b/tests/test_sphinx/sourcedirs/texinfo/index.md
@@ -0,0 +1,9 @@
+Check that NoURIError is handled correctly:
+
+[](file.md)
+
+Check that tables can be built:
+
+| foo | bar |
+| --- | --- |
+| baz | bim |
diff --git a/tests/test_sphinx/test_sphinx_builds.py b/tests/test_sphinx/test_sphinx_builds.py
index b5b9acc..a41e96b 100644
--- a/tests/test_sphinx/test_sphinx_builds.py
+++ b/tests/test_sphinx/test_sphinx_builds.py
@@ -564,15 +564,11 @@ def test_fieldlist_extension(
 
 @pytest.mark.sphinx(
     buildername="texinfo",
-    srcdir=os.path.join(SOURCE_DIR, "texi_table"),
+    srcdir=os.path.join(SOURCE_DIR, "texinfo"),
     freshenv=True,
 )
-def test_texinfo_table(
-    app,
-    status,
-    warning,
-):
-    """Test that tables can be built with the Texinfo builder."""
+def test_texinfo(app, status, warning):
+    """Test Texinfo builds."""
     app.build()
     assert "build succeeded" in status.getvalue()  # Build succeeded
     warnings = warning.getvalue().strip()