mirror of https://github.com/eyhc1/rendercv.git
renderer: refactor
This commit is contained in:
parent
238b2ad8c7
commit
1b35201508
|
@ -113,12 +113,12 @@ class LaTeXFile(TemplatedFile):
|
||||||
data_model: dm.RenderCVDataModel,
|
data_model: dm.RenderCVDataModel,
|
||||||
environment: jinja2.Environment,
|
environment: jinja2.Environment,
|
||||||
):
|
):
|
||||||
latexfile_data_model = copy.deepcopy(data_model)
|
latex_file_data_model = copy.deepcopy(data_model)
|
||||||
transformed_sections = transform_markdown_sections_to_latex_sections(
|
transformed_sections = transform_markdown_sections_to_latex_sections(
|
||||||
latexfile_data_model.cv.sections_input
|
latex_file_data_model.cv.sections_input
|
||||||
)
|
)
|
||||||
latexfile_data_model.cv.sections_input = transformed_sections
|
latex_file_data_model.cv.sections_input = transformed_sections
|
||||||
super().__init__(latexfile_data_model, environment)
|
super().__init__(latex_file_data_model, environment)
|
||||||
|
|
||||||
def render_templates(self) -> tuple[str, str, list[tuple[str, list[str], str]]]:
|
def render_templates(self) -> tuple[str, str, list[tuple[str, list[str], str]]]:
|
||||||
"""Render and return all the templates for the $\\LaTeX$ file.
|
"""Render and return all the templates for the $\\LaTeX$ file.
|
||||||
|
@ -138,7 +138,7 @@ class LaTeXFile(TemplatedFile):
|
||||||
entries: list[str] = []
|
entries: list[str] = []
|
||||||
for i, entry in enumerate(section.entries):
|
for i, entry in enumerate(section.entries):
|
||||||
is_first_entry = i == 0
|
is_first_entry = i == 0
|
||||||
|
|
||||||
entries.append(
|
entries.append(
|
||||||
self.template(
|
self.template(
|
||||||
section.entry_type,
|
section.entry_type,
|
||||||
|
@ -183,15 +183,19 @@ class LaTeXFile(TemplatedFile):
|
||||||
# ones with \textnormal:
|
# ones with \textnormal:
|
||||||
|
|
||||||
# Find all the nested commands:
|
# Find all the nested commands:
|
||||||
nested_commands = re.findall(r"\\textbf{[^}]*?(\\textbf{.*?})", result)
|
nested_commands = re.findall(
|
||||||
nested_commands += re.findall(r"\\textit{[^}]*?(\\textit{.*?})", result)
|
r"\\textbf{[^}]*?(\\textbf{.*?})|\\textit{[^}]*?(\\textit{.*?})"
|
||||||
nested_commands += re.findall(r"\\underline{[^}]*?(\\underline{.*?})", result)
|
r"|\\underline{[^}]*?(\\underline{.*?})",
|
||||||
|
result,
|
||||||
|
)
|
||||||
|
|
||||||
# Replace the inner commands with \textnormal:
|
# Replace the inner commands with \textnormal:
|
||||||
for nested_command in nested_commands:
|
for nested_command in nested_commands:
|
||||||
new_command = nested_command.replace("textbf", "textnormal")
|
new_command = (
|
||||||
new_command = new_command.replace("textit", "textnormal")
|
nested_command.replace("textbf", "textnormal")
|
||||||
new_command = new_command.replace("underline", "textnormal")
|
.replace("textit", "textnormal")
|
||||||
|
.replace("underline", "textnormal")
|
||||||
|
)
|
||||||
result = result.replace(nested_command, new_command)
|
result = result.replace(nested_command, new_command)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -855,7 +859,8 @@ def copy_theme_files_to_output_directory(
|
||||||
)
|
)
|
||||||
|
|
||||||
for theme_file in theme_directory_path.iterdir():
|
for theme_file in theme_directory_path.iterdir():
|
||||||
if not ("j2.tex" in theme_file.name or "py" in theme_file.name):
|
dont_copy_files_with_these_extensions = [".j2.tex", ".py"]
|
||||||
|
if theme_file.suffix not in dont_copy_files_with_these_extensions:
|
||||||
if theme_file.is_dir():
|
if theme_file.is_dir():
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
str(theme_file),
|
str(theme_file),
|
||||||
|
|
Loading…
Reference in New Issue