From 65b9a300b9e3e57739d0f52f231a6461b6095659 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 9 Sep 2025 22:15:35 +0200 Subject: [PATCH 1/2] section_class value extended to format latex using "environment". Test added and default updated with a "fineprint" class/environment --- src/pyladoc/__init__.py | 2 +- src/pyladoc/latex.py | 8 ++++++++ src/pyladoc/templates/default_template.tex | 6 ++++++ src/pyladoc/templates/test_template.html | 6 ++++++ tests/test_rendering_example2_doc.py | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pyladoc/__init__.py b/src/pyladoc/__init__.py index 48788af..66bd378 100644 --- a/src/pyladoc/__init__.py +++ b/src/pyladoc/__init__.py @@ -621,7 +621,7 @@ class DocumentWriter(): Args: text: The markdown text to add - section_class: The class for the text section + section_class: The HTML-class and LaTeX-environment name for the text section """ norm_text = _normalize_text_indent(str(text)) diff --git a/src/pyladoc/latex.py b/src/pyladoc/latex.py index e3ff9d8..8b128cc 100644 --- a/src/pyladoc/latex.py +++ b/src/pyladoc/latex.py @@ -191,6 +191,7 @@ def from_html(html_code: str) -> str: self.header_flag = False self.attr_dict: dict[str, str] = {} self.equation_flag = False + self.class_name: str = '' def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: self.attr_dict = {k: v if v else '' for k, v in attrs} @@ -217,6 +218,10 @@ def from_html(html_code: str) -> str: self.latex_code.append("\n\n\\noindent\\rule[0.5ex]{\\linewidth}{1pt}\n\n") elif tag == 'latex': self.equation_flag = True + elif tag == 'div': + self.class_name = self.attr_dict.get('class', '') + if self.class_name: + self.latex_code.append(f"\n\\begin{{{self.class_name}}}\n") def handle_endtag(self, tag: str) -> None: if tag in html_to_latex: @@ -242,6 +247,9 @@ def from_html(html_code: str) -> str: self.latex_code.append("}") elif tag == 'latex': self.equation_flag = False + elif tag == 'div': + if self.class_name: + self.latex_code.append(f"\n\\end{{{self.class_name}}}\n") def handle_data(self, data: str) -> None: if self.equation_flag: diff --git a/src/pyladoc/templates/default_template.tex b/src/pyladoc/templates/default_template.tex index a37d64a..c7af98d 100644 --- a/src/pyladoc/templates/default_template.tex +++ b/src/pyladoc/templates/default_template.tex @@ -16,11 +16,17 @@ \usepackage{booktabs} % For professional-looking tables \usepackage{pgf} % For using pgf grafics \usepackage{textcomp, gensymb} % provides \degree symbol +\usepackage{xcolor} % For colored text \sisetup{ table-align-text-post = false } +% Define fine print environment +\newenvironment{fineprint} + {\begin{quote}\footnotesize\color{gray}} + {\end{quote}} + % Geometry Settings \geometry{margin=1in} % 1-inch margins diff --git a/src/pyladoc/templates/test_template.html b/src/pyladoc/templates/test_template.html index ace6f5e..e9dd468 100644 --- a/src/pyladoc/templates/test_template.html +++ b/src/pyladoc/templates/test_template.html @@ -21,6 +21,12 @@ padding-bottom: 50px; } + div.fineprint + { + font-size: smaller; + color: grey; + } + div h1 { font-size: 32px; diff --git a/tests/test_rendering_example2_doc.py b/tests/test_rendering_example2_doc.py index 572f01d..6d02adb 100644 --- a/tests/test_rendering_example2_doc.py +++ b/tests/test_rendering_example2_doc.py @@ -81,6 +81,8 @@ def make_document(): doc.add_table(df.style.hide(axis="index"), 'This is a example table', 'example1') + doc.add_text("This is a fine print test text section. It uses smaller text and uses grey color.", section_class='fineprint') + return doc From df592aef6a6afe8a8dcd60f5de134c27d61ef3d0 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 9 Sep 2025 22:57:02 +0200 Subject: [PATCH 2/2] ci script updated to run docs build only on push --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3aa3167..4bb11b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,6 +140,7 @@ jobs: path: tests/out/test_*_render*.pdf build-docs: + if: github.event_name == 'push' needs: build-ubuntu runs-on: ubuntu-latest steps: @@ -183,6 +184,7 @@ jobs: path: docs/build/html deploy: + if: github.event_name == 'push' needs: build-docs runs-on: ubuntu-latest permissions: