Output outline in contenu.tex rather than on standard output
This commit is contained in:
parent
c10d63b115
commit
eb6ee9c947
|
@ -26,7 +26,6 @@ TEMPLATES = {
|
|||
LATEX_SUBS = [(re.compile('_'), '\\_'),
|
||||
]
|
||||
|
||||
|
||||
DOCUMENTCLASS_RE = re.compile(r'\\documentclass\{(?P<document_class>.+?)\}')
|
||||
SKBCONFIG_RE = re.compile(r'\\skbconfig\[\n\s*root\s*=\s*(?P<root>.*),\n\s*rep\s*=\s*(?P<rep>.*),\n\s*pub\s*=\s*(?P<pub>.*),\n\s*fig\s*=\s*(?P<fig>.*),\n\s*sli\s*=\s*(?P<sli>.*),\n\s*acr\s*=\s*(?P<acr>.*),\n\s*bib\s*=\s*(?P<bib>.*)\n\s*\]\{skblocal.tex\}', re.M)
|
||||
SKBINPUT_RE = re.compile(r'[^%]\\skbinput\[from=(?P<rep>.*?)(,.*)?\]\{(?P<tex>.*?)\}', re.M)
|
||||
|
@ -242,7 +241,28 @@ def main():
|
|||
for header in headers_list:
|
||||
print('{}{}'.format('\t' * flattened_levels[header[1]], header[2]))
|
||||
|
||||
def render_outline(header_list, master):
|
||||
item = "\\item {content}"
|
||||
itemize = "\\begin{{itemize}}\n{content}\n\\end{{itemize}}"
|
||||
content_file = path.join(path.dirname(path.abspath(master)), 'programme', 'contenu.tex')
|
||||
with open(content_file, 'w') as content_fh:
|
||||
content_fh.write(itemize.format(content='\n'.join([item.format(content=c[2]) for c in header_list])))
|
||||
|
||||
def structure_outline(header_list):
|
||||
root = Outline('Contenu')
|
||||
current_outline = root
|
||||
for header in header_list:
|
||||
if header[1] > current_outline.level:
|
||||
parent = current_outline
|
||||
elif header[1] == current_outline.level:
|
||||
parent = current_outline.get_parent()
|
||||
elif header[1] == current_outline.level - 1:
|
||||
parent = current_outline.get_parent().get_parent()
|
||||
else:
|
||||
parent = root
|
||||
current_outline = Outline(header[2], parent, header[1])
|
||||
parent.add_child(current_outline)
|
||||
return root
|
||||
|
||||
|
||||
section_re = re.compile(r'\\section\{(?P<name>.*?)\}')
|
||||
|
@ -261,7 +281,10 @@ def main():
|
|||
sections_list = [(section.start(), section_level, section.group('name')) for section in sections]
|
||||
includes_list = [element for skbinput in includes for element in outline_from_include(file_path_from_skbinput(skbinput, args.master, skbconfig), skbinput.start(), document_class)]
|
||||
subsections_list = [(subsection.start(), subsection_level, subsection.group('name')) for subsection in subsections]
|
||||
print(outline_format(filter_outlines(reorder_lists(parts_list, sections_list, includes_list, subsections_list))))
|
||||
structured_outline = structure_outline(filter_outlines(reorder_lists(parts_list, sections_list, includes_list, subsections_list)))
|
||||
content_file = path.join(path.dirname(path.abspath(args.master)), 'programme', 'contenu.tex')
|
||||
with open(content_file, 'w') as content_fh:
|
||||
content_fh.write(structured_outline.render())
|
||||
|
||||
|
||||
jinja_loader = FileSystemLoader('./templates')
|
||||
|
@ -297,6 +320,43 @@ def main():
|
|||
args.func(args)
|
||||
|
||||
|
||||
class Outline:
|
||||
item = "{indent}\\item {content}"
|
||||
itemize = "\n{indent}\\begin{{itemize}}\n{content}\n{indent}\\end{{itemize}}"
|
||||
|
||||
def __init__(self, content, parent=None, level=-1):
|
||||
self.children = []
|
||||
self.parent = parent
|
||||
self.level = level
|
||||
self.content = content
|
||||
|
||||
|
||||
def is_leaf(self):
|
||||
if self.children:
|
||||
return False
|
||||
return True
|
||||
|
||||
def add_child(self, child):
|
||||
self.children.append(child)
|
||||
|
||||
def get_children(self):
|
||||
return self.children
|
||||
|
||||
def get_parent(self):
|
||||
return self.parent
|
||||
|
||||
def render(self):
|
||||
if self.get_parent():
|
||||
rendered = self.item.format(indent=' '*self.level, content=self.content)
|
||||
else:
|
||||
rendered = ''
|
||||
if not self.is_leaf():
|
||||
rendered += self.itemize.format(indent=' '*self.level, content='\n'.join([c.render() for c in self.get_children()]))
|
||||
return rendered
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Outline {self.content} - {self.level}>"
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue