From af34e0f2937bb0dfd3700b99d6f0a874fbd57da0 Mon Sep 17 00:00:00 2001 From: Kayce Basques Date: Sun, 7 Dec 2025 09:32:09 -0800 Subject: [PATCH] Don't process includes within code blocks Fixes #57 --- tests/test_llms_txt.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_llms_txt.py b/tests/test_llms_txt.py index 412da2c..51e1b25 100644 --- a/tests/test_llms_txt.py +++ b/tests/test_llms_txt.py @@ -198,6 +198,28 @@ def test_process_includes(tmp_path): assert processed_content == expected_content +def test_process_includes_in_code_block(tmp_path): + """Test that an include directive within a code block is not processed.""" + # Create a processor + config = {"llms_txt_directives": []} + processor = DocumentProcessor(config) + + # Create a source file that includes the test file + source_content = ( + ".. code-block:: rst\n\n .. include:: foo.txt" + ) + source_file = tmp_path / "source.txt" + with open(source_file, "w", encoding="utf-8") as f: + f.write(source_content) + + # Process the include directive + processed_content = processor._process_includes(source_content, source_file) + + # Check that the include directive was replaced with the content + expected_content = source_content + assert processed_content == expected_content + + def test_process_includes_with_relative_paths(tmp_path): """Test that include directives with relative paths are processed correctly.""" # Create a processor