From d3e521f0170dddfb11bab1af555f841f496a60cf Mon Sep 17 00:00:00 2001 From: rubenpieters Date: Sun, 30 Jul 2023 21:55:20 +0200 Subject: [PATCH] Bold property for timing structure elements. --- data/input/11_appendix_timing_structures.yaml | 3 +++ rules_doc_generator/input/yaml/parser.py | 3 ++- rules_doc_generator/model/section.py | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/data/input/11_appendix_timing_structures.yaml b/data/input/11_appendix_timing_structures.yaml index 5a934fa..fcdeb57 100644 --- a/data/input/11_appendix_timing_structures.yaml +++ b/data/input/11_appendix_timing_structures.yaml @@ -16,6 +16,7 @@ sections: toc_entry: Timing Structure of The Corp's Turn rules: - timing_structure: + bold: elements: - text: Draw Phase elements: @@ -47,6 +48,7 @@ sections: toc_entry: Timing Structure of The Runner's Turn rules: - timing_structure: + bold: elements: - text: Action Phase elements: @@ -75,6 +77,7 @@ sections: toc_entry: Timing Structure of a Run rules: - timing_structure: + bold: elements: - text: Initiation Phase elements: diff --git a/rules_doc_generator/input/yaml/parser.py b/rules_doc_generator/input/yaml/parser.py index 3018ad9..29a0c2f 100644 --- a/rules_doc_generator/input/yaml/parser.py +++ b/rules_doc_generator/input/yaml/parser.py @@ -54,8 +54,9 @@ def parse_example(yaml_example: Any) -> Example: def parse_timing_structure(yaml_timing_structure: Any) -> TimingStructureElement: text = parse_with_default(yaml_timing_structure, 'text', None, parse_format_text_field) + bold = parse_boolean(yaml_timing_structure, 'bold') elements = parse_subelements(yaml_timing_structure, 'elements', parse_timing_structure) - return TimingStructureElement(text, elements) + return TimingStructureElement(text, bold, elements) def parse_subrule(yaml_sub_rule: Any = False) -> SubRule: id = parse_id(yaml_sub_rule, 'rule') diff --git a/rules_doc_generator/model/section.py b/rules_doc_generator/model/section.py index 40feae2..a45ec89 100644 --- a/rules_doc_generator/model/section.py +++ b/rules_doc_generator/model/section.py @@ -7,6 +7,7 @@ @dataclass class TimingStructureElement: text: FormatText | None + bold: bool elements: list[TimingStructureElement] def to_html_l1(self, id_map: RefDict) -> str: @@ -35,8 +36,14 @@ def to_html(self, id_map: RefDict) -> str: result += '' return result - def to_latex_l1(self, id_map: RefDict) -> str: - result = f'\\1 \\textbf{{{self.text.to_latex(id_map)}}}\n' + def to_latex_l1(self, id_map: RefDict, bold: bool) -> str: + result = '\\1 ' + if bold: + result += '\\textbf{' + result += self.text.to_latex(id_map) + if bold: + result += '}' + result += '\n' for elem in self.elements: result += elem.to_latex_l2(id_map) return result @@ -51,11 +58,14 @@ def to_latex_l3(self, id_map: RefDict) -> str: return f' \\3 {self.text.to_latex(id_map)}\n' def to_latex(self, id_map: RefDict) -> str: - result = '\setlist[enumerate,1]{label=\\textbf{\\arabic*)}}\n' + if self.bold: + result = '\setlist[enumerate,1]{label=\\textbf{\\arabic*)}}\n' + else: + result = '\setlist[enumerate,1]{label=\\arabic*)}\n' result += '\setlist[enumerate,2]{label=\\alph*)}\n' result += '\setlist[enumerate,3]{label=\\roman*)}\n' for elem in self.elements: - result += elem.to_latex_l1(id_map) + result += elem.to_latex_l1(id_map, self.bold) return result @dataclass