Don't draw tables of contents with <2 elements.
This commit is contained in:
parent
57af01c5be
commit
61b1b79f95
@ -675,11 +675,16 @@ def render_as_document(headline, doc, headlineLevel, graph, title):
|
|||||||
return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title, render_toc(doc))
|
return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title, render_toc(doc))
|
||||||
|
|
||||||
def render_toc(doc):
|
def render_toc(doc):
|
||||||
acc = ['<ul>']
|
acc = ['<ul class="toc">']
|
||||||
for headline in doc.getTopHeadlines():
|
for headline in doc.getTopHeadlines():
|
||||||
render_toc_headline(headline, acc)
|
render_toc_headline(headline, acc)
|
||||||
|
|
||||||
acc.append('</ul>')
|
acc.append('</ul>')
|
||||||
|
|
||||||
|
if sum([chunk == '<li>' for chunk in acc]) < 2:
|
||||||
|
# If < 2 headlines, ignore it
|
||||||
|
return None
|
||||||
|
|
||||||
return ''.join(acc)
|
return ''.join(acc)
|
||||||
|
|
||||||
def render_toc_headline(headline, acc):
|
def render_toc_headline(headline, acc):
|
||||||
@ -767,6 +772,15 @@ def render(headline, doc, graph, headlineLevel):
|
|||||||
|
|
||||||
|
|
||||||
def as_document(html, title, global_toc):
|
def as_document(html, title, global_toc):
|
||||||
|
if global_toc is None:
|
||||||
|
toc_section = ""
|
||||||
|
else:
|
||||||
|
toc_section = f"""
|
||||||
|
<div class="global-table-of-contents">
|
||||||
|
<h2>Table of contents</h2>
|
||||||
|
{global_toc}
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
return f"""<!DOCTYPE html>
|
return f"""<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -798,10 +812,7 @@ def as_document(html, title, global_toc):
|
|||||||
<h1><a href="./index.html">Código para llevar [Notes]</a></h1>
|
<h1><a href="./index.html">Código para llevar [Notes]</a></h1>
|
||||||
<input type="text" id="searchbox" disabled="true" placeholder="Search (requires JS)" />
|
<input type="text" id="searchbox" disabled="true" placeholder="Search (requires JS)" />
|
||||||
</nav>
|
</nav>
|
||||||
<div class="global-table-of-contents">
|
{toc_section}
|
||||||
<h2>Table of contents</h2>
|
|
||||||
{global_toc}
|
|
||||||
</div>
|
|
||||||
{html}
|
{html}
|
||||||
|
|
||||||
<script src="../static/search-box.js"></script>
|
<script src="../static/search-box.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user