Automatically add content from .. include:: directives (#6)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
0.2.0 (2025-01-01)
|
||||
------------------
|
||||
|
||||
* Added include directive processing feature
|
||||
* Added maxlines configuration
|
||||
|
||||
0.1.0 (2024-01-01)
|
||||
------------------
|
||||
|
||||
* Initial release
|
||||
@@ -0,0 +1,13 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
0.2.0 (2025-01-01)
|
||||
------------------
|
||||
|
||||
* Added include directive processing feature
|
||||
* Added maxlines configuration
|
||||
|
||||
0.1.0 (2024-01-01)
|
||||
------------------
|
||||
|
||||
* Initial release
|
||||
@@ -7,6 +7,7 @@ Welcome to Test Project's documentation!
|
||||
|
||||
page1
|
||||
page2
|
||||
page_with_include
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
Page With Include
|
||||
===============
|
||||
|
||||
This is a test page that includes another file:
|
||||
|
||||
.. include:: CHANGELOG.rst
|
||||
|
||||
This content comes after the include.
|
||||
@@ -25,6 +25,14 @@ def test_build_html_with_llms_txt(basic_sphinx_app):
|
||||
assert "Content for section 1" in content
|
||||
assert "Content for section A" in content
|
||||
|
||||
# Check that the include directive has been processed
|
||||
assert "Page With Include" in content
|
||||
assert "This is a test page that includes another file:" in content
|
||||
assert "Changelog" in content # Content from the included file
|
||||
assert "0.2.0 (2025-01-01)" in content # Content from the included file
|
||||
assert "0.1.0 (2024-01-01)" in content # Additional content from the included file
|
||||
assert "This content comes after the include." in content
|
||||
|
||||
|
||||
def test_custom_filename(temp_dir, rootdir):
|
||||
"""Test using a custom filename for the output."""
|
||||
|
||||
@@ -81,3 +81,97 @@ def test_empty_page_order():
|
||||
# Set only master_doc, but not env
|
||||
manager.set_master_doc("index")
|
||||
assert manager.get_page_order() == []
|
||||
|
||||
|
||||
def test_process_includes(tmp_path):
|
||||
"""Test that include directives are processed correctly."""
|
||||
# Create a manager
|
||||
manager = LLMSFullManager()
|
||||
|
||||
# Create a test file with an include directive
|
||||
include_content = "This is included content.\nWith multiple lines."
|
||||
include_file = tmp_path / "included.txt"
|
||||
with open(include_file, "w", encoding="utf-8") as f:
|
||||
f.write(include_content)
|
||||
|
||||
# Create a source file that includes the test file
|
||||
source_content = (
|
||||
"Line before include.\n.. include:: included.txt\nLine after include."
|
||||
)
|
||||
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 = manager._process_includes(source_content, source_file)
|
||||
|
||||
# Check that the include directive was replaced with the content
|
||||
expected_content = (
|
||||
"Line before include.\nThis is included content.\nWith multiple"
|
||||
" lines.\nLine after include."
|
||||
)
|
||||
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 manager
|
||||
manager = LLMSFullManager()
|
||||
|
||||
# Set up a more complex directory structure
|
||||
docs_dir = tmp_path / "docs"
|
||||
docs_dir.mkdir()
|
||||
|
||||
# Create the original source directory structure
|
||||
source_dir = docs_dir / "source"
|
||||
source_dir.mkdir()
|
||||
|
||||
# Create a subdirectory
|
||||
subdir = source_dir / "subdir"
|
||||
subdir.mkdir()
|
||||
|
||||
# Create an includes directory
|
||||
includes_dir = source_dir / "includes"
|
||||
includes_dir.mkdir()
|
||||
|
||||
# Set the srcdir on the manager
|
||||
manager.srcdir = str(source_dir)
|
||||
|
||||
# Create the included file in the includes directory
|
||||
include_content = "This is included content from another directory."
|
||||
include_file = includes_dir / "common.txt"
|
||||
with open(include_file, "w", encoding="utf-8") as f:
|
||||
f.write(include_content)
|
||||
|
||||
# Create a source file in the subdirectory that includes the file from includes
|
||||
source_content = (
|
||||
"Line before include.\n.. include:: ../includes/common.txt\nLine after include."
|
||||
)
|
||||
source_file = subdir / "page.txt"
|
||||
with open(source_file, "w", encoding="utf-8") as f:
|
||||
f.write(source_content)
|
||||
|
||||
# Create the _sources directory to mimic Sphinx build output
|
||||
build_dir = tmp_path / "build"
|
||||
build_dir.mkdir()
|
||||
sources_dir = build_dir / "_sources"
|
||||
sources_dir.mkdir()
|
||||
|
||||
# Create the same structure in the _sources directory
|
||||
sources_subdir = sources_dir / "subdir"
|
||||
sources_subdir.mkdir()
|
||||
|
||||
# Copy the source file to the _sources directory
|
||||
sources_file = sources_subdir / "page.txt"
|
||||
with open(sources_file, "w", encoding="utf-8") as f:
|
||||
f.write(source_content)
|
||||
|
||||
# Process the include directive from the _sources file
|
||||
processed_content = manager._process_includes(source_content, sources_file)
|
||||
|
||||
# Check that the include directive was replaced with the content
|
||||
expected_content = (
|
||||
"Line before include.\nThis is included content from another"
|
||||
" directory.\nLine after include."
|
||||
)
|
||||
assert processed_content == expected_content
|
||||
|
||||
Reference in New Issue
Block a user