Compare commits

..

No commits in common. "664a08b2dccd322befa8ac2dde76552cf84f5538" and "ecc97bd9a6a1233509c38ee3ce1d895e588873d0" have entirely different histories.

2 changed files with 5 additions and 64 deletions

View File

@ -277,10 +277,9 @@ def inject_to_template(fields_dict: dict[str, str],
raise Exception('No template provided')
def replace_field(match: re.Match[str]) -> str:
print('--->', match.group(0))
return fields_dict.get(match.group(1), match.group(0))
return fields_dict.get(match.group(1), match.string)
return re.sub(r"(?:\%+\s*)?\<!--(.*?)-->", replace_field, template, 0, re.MULTILINE)
return re.sub(r"(?:\%+\s*)?\<!--(.*?)-->", replace_field, template)
class DocumentWriter():
@ -709,9 +708,9 @@ class DocumentWriter():
True if the PDF file was successfully created
"""
content = self.to_latex(font_family, table_renderer, figure_scale)
latex_code = inject_to_template({'CONTENT': content} | fields_dict,
latex_code = inject_to_template({'CONTENT': content},
latex_template_path,
internal_template='templates/default_template.tex')
'templates/default_template.tex')
if font_family == 'sans-serif':
latex_code = latex.inject_latex_command(latex_code, '\\renewcommand{\\familydefault}{\\sfdefault}')

View File

@ -1,7 +1,7 @@
import pyladoc
def test_inject_to_template_html():
def test_inject_to_template():
template = """
<!DOCTYPE html>
<html lang="en">
@ -25,62 +25,4 @@ def test_inject_to_template_html():
print(result)
assert "Hello, World!" in result
assert "<!-- some comment -->" in result # Keep unrelated HTML comments
assert "<title>Test Title</title>" in result
def test_inject_to_template_latex():
template = """
\\documentclass[a4paper,12pt]{article}
% Packages
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{lmodern} % Load Latin Modern font
\\usepackage{graphicx} % For including images
\\usepackage{amsmath} % For mathematical symbols
\\usepackage{amssymb} % For additional symbols
\\usepackage{hyperref} % For hyperlinks
\\usepackage{caption} % For customizing captions
\\usepackage{geometry} % To set margins
\\usepackage{natbib} % For citations
\\usepackage{float} % For fixing figure positions
\\usepackage{siunitx} % For scientific units
\\usepackage{booktabs} % For professional-looking tables
\\usepackage{pgf} % For using pgf grafics
\\usepackage{textcomp, gensymb} % provides \\degree symbol
\\sisetup{
table-align-text-post = false
}
% Geometry Settings
\\geometry{margin=1in} % 1-inch margins
% Title and Author Information
\\title{<!--PROJECT-->}
<!--AUTHOR-->
\\date{\\today}
\begin{document}
% Title Page
\\maketitle
% <!--CONTENT-->
\\end{document}
"""
content = "Hello, World!"
project_name = "Test Project"
author_name = "Otto"
result = pyladoc.inject_to_template(
{'CONTENT': content, 'PROJECT': project_name, 'AUTHOR': author_name},
template_string=template)
print(result)
assert "\nOtto\n" in result
assert "\\title{Test Project}\n" in result
assert "Hello, World!" in result