[AI]
ГОСТ
This commit is contained in:
@@ -14,6 +14,13 @@ def process_document(
|
||||
template_path: Optional[Path] = None, theme_name: Optional[str] = None,
|
||||
plugins_dir: Optional[Path] = None, dry_run: bool = False
|
||||
):
|
||||
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} не найдена, используем стандартный стиль")
|
||||
|
||||
if plugins_dir and plugins_dir.exists():
|
||||
load_plugins_from_path(plugins_dir)
|
||||
|
||||
@@ -42,6 +49,7 @@ def process_document(
|
||||
|
||||
style_reg = StyleRegistry(style_config_path)
|
||||
style_reg.ensure_styles_in_doc(doc)
|
||||
style_reg.apply_page_layout(doc) # ✅ применяем поля
|
||||
render_markdown_to_docx(doc, md_content, images_dir, style_reg)
|
||||
|
||||
output_path = output_dir / f"{doc_name}.docx"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import yaml
|
||||
from docx import Document
|
||||
from docx.enum.style import WD_STYLE_TYPE
|
||||
from docx.shared import Pt, RGBColor
|
||||
from docx.shared import Pt, Cm, RGBColor
|
||||
from docx.enum.text import WD_LINE_SPACING, WD_ALIGN_PARAGRAPH
|
||||
from docx.styles.style import ParagraphStyle
|
||||
|
||||
class StyleRegistry:
|
||||
def __init__(self, config_path):
|
||||
@@ -20,6 +19,24 @@ class StyleRegistry:
|
||||
style = doc.styles.add_style(name, WD_STYLE_TYPE.PARAGRAPH)
|
||||
self.apply_style(style, name)
|
||||
|
||||
def apply_page_layout(self, doc: Document):
|
||||
"""Применяет настройки страницы (поля)."""
|
||||
page_cfg = self.config.get("page", {})
|
||||
margins = page_cfg.get("margins", {})
|
||||
if not margins:
|
||||
return
|
||||
|
||||
sections = doc.sections
|
||||
for section in sections:
|
||||
if "top" in margins:
|
||||
section.top_margin = Cm(margins["top"])
|
||||
if "bottom" in margins:
|
||||
section.bottom_margin = Cm(margins["bottom"])
|
||||
if "left" in margins:
|
||||
section.left_margin = Cm(margins["left"])
|
||||
if "right" in margins:
|
||||
section.right_margin = Cm(margins["right"])
|
||||
|
||||
def apply_style(self, style, style_name: str):
|
||||
cfg = self.config["styles"].get(style_name)
|
||||
if not cfg:
|
||||
@@ -50,6 +67,9 @@ class StyleRegistry:
|
||||
align = alignment_map.get(para_cfg["alignment"])
|
||||
if align:
|
||||
pf.alignment = align
|
||||
if "first_line_indent" in para_cfg:
|
||||
from docx.shared import Mm
|
||||
pf.first_line_indent = Mm(para_cfg["first_line_indent"])
|
||||
|
||||
def get_color(self, key: str):
|
||||
hex_color = self.config.get("colors", {}).get(key, "000000")
|
||||
|
||||
Reference in New Issue
Block a user