@@ -848,3 +848,76 @@ def test_custom_myst_sub_delimiters_code_block(
848848 app_expected .outdir / "markdown_document.html"
849849 ).read_text ()
850850 assert content_html == expected_content_html
851+
852+ @staticmethod
853+ def test_substitution_code_role (
854+ tmp_path : Path ,
855+ make_app : Callable [..., SphinxTestApp ],
856+ ) -> None :
857+ """
858+ The ``substitution-code`` role replaces the placeholders defined in
859+ ``conf.py`` as specified.
860+ """
861+ source_directory = tmp_path / "source"
862+ source_directory .mkdir ()
863+ index_source_file = source_directory / "index.rst"
864+ markdown_source_file = source_directory / "markdown_document.md"
865+ (source_directory / "conf.py" ).touch ()
866+
867+ index_source_file_content = dedent (
868+ text = """\
869+ .. toctree::
870+
871+ markdown_document
872+ """ ,
873+ )
874+ markdown_source_file_content = dedent (
875+ text = """\
876+ # Title
877+
878+ Example {substitution-code}`PRE-|a|-POST`
879+ """ ,
880+ )
881+ index_source_file .write_text (data = index_source_file_content )
882+ markdown_source_file .write_text (data = markdown_source_file_content )
883+ app = make_app (
884+ srcdir = source_directory ,
885+ exception_on_warning = True ,
886+ confoverrides = {
887+ "extensions" : [
888+ "myst_parser" ,
889+ "sphinx_substitution_extensions" ,
890+ ],
891+ "myst_enable_extensions" : ["substitution" ],
892+ "myst_substitutions" : {
893+ "a" : "example_substitution" ,
894+ },
895+ "myst_sub_delimiters" : ("|" , "|" ),
896+ },
897+ )
898+ app .build ()
899+ assert app .statuscode == 0
900+ content_html = (app .outdir / "markdown_document.html" ).read_text ()
901+ app .cleanup ()
902+
903+ equivalent_source = dedent (
904+ text = """\
905+ # Title
906+
907+ Example `PRE-example_substitution-POST`
908+ """ ,
909+ )
910+
911+ markdown_source_file .write_text (data = equivalent_source )
912+ app_expected = make_app (
913+ srcdir = source_directory ,
914+ exception_on_warning = True ,
915+ confoverrides = {"extensions" : ["myst_parser" ]},
916+ )
917+ app_expected .build ()
918+ assert app_expected .statuscode == 0
919+
920+ expected_content_html = (
921+ app_expected .outdir / "markdown_document.html"
922+ ).read_text ()
923+ assert content_html == expected_content_html
0 commit comments