From 8da965234c00364300426796bc9d49f633746335 Mon Sep 17 00:00:00 2001 From: Mikan <72257910+Mikan-DS@users.noreply.github.com> Date: Mon, 8 Dec 2025 17:21:41 +0300 Subject: [PATCH] =?UTF-8?q?[AI]=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=BA=D0=B0=20=D1=82=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__main__.py | 3 ++- src/core/converter.py | 8 +++++++- tests/test_converter.py | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 7d5b86c..93582f0 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -14,9 +14,10 @@ def convert( output_dir: Path = typer.Option(..., "--output", "-o", help="Папка для результата"), style_config: Path = typer.Option("resources/style_config.yaml", "--style", "-s", help="Файл стилей"), template: Optional[Path] = typer.Option(None, "--template", "-t", help="Шаблон .dotx"), + theme: Optional[str] = typer.Option(None, "--theme", "-T", help="Название темы (gost, academic...)"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Включить отладочные сообщения"), ): log_level = logging.DEBUG if verbose else logging.INFO logging.basicConfig(level=log_level, format='%(levelname)s: %(message)s') - process_document(input_dir, output_dir, style_config, template) \ No newline at end of file + process_document(input_dir, output_dir, style_config, template, theme) \ No newline at end of file diff --git a/src/core/converter.py b/src/core/converter.py index 82f564f..ff1b921 100644 --- a/src/core/converter.py +++ b/src/core/converter.py @@ -9,7 +9,13 @@ import logging logger = logging.getLogger(__name__) -def process_document(input_dir: Path, output_dir: Path, style_config_path: Path, template_path: Optional[Path] = None): +def process_document(input_dir: Path, output_dir: Path, style_config_path: Path, template_path: Optional[Path] = None, theme_name: Optional[str] = None): + if theme_name: + theme_path = Path("resources/themes") / f"{theme_name}.yaml" + if theme_path.exists(): + style_config_path = theme_path + else: + logger.warning(f"Тема {theme_name} не найдена, используем стандартный стиль") for doc_dir in input_dir.iterdir(): if not doc_dir.is_dir(): continue diff --git a/tests/test_converter.py b/tests/test_converter.py index d58d77e..c4d66fb 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -45,4 +45,40 @@ def test_process_document_with_template(create_example_doc): # Удаляем файл после теста output_path.unlink(missing_ok=True) - tpl_path.unlink(missing_ok=True) \ No newline at end of file + tpl_path.unlink(missing_ok=True) + +def test_process_document_with_theme(): + # Создаём тему + theme_dir = Path("resources/themes") + theme_dir.mkdir(exist_ok=True) + theme_path = theme_dir / "test_theme.yaml" + theme_path.write_text(""" +styles: + Heading 1: + font: + name: "Arial" + size: 14 + bold: true + paragraph: + space_before: 10 + space_after: 5 +""", encoding="utf-8") + + # Создаём фикстуру + doc_dir = Path("tests/fixtures/inputs/theme_test") + doc_dir.mkdir(parents=True, exist_ok=True) + (doc_dir / "document.md").write_text("# Заголовок", encoding="utf-8") + (doc_dir / "images").mkdir(exist_ok=True) + + process_document( + input_dir=Path("tests/fixtures/inputs"), + output_dir=Path("tests/output"), + style_config_path=Path("resources/style_config.yaml"), + theme_name="test_theme" + ) + + output_path = Path("tests/output/theme_test.docx") + assert output_path.exists() + + output_path.unlink(missing_ok=True) + theme_path.unlink(missing_ok=True)