diff --git a/scripts/generate.py b/scripts/generate.py index 76d2616..8e079fc 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -620,7 +620,28 @@ def render_as_document(headline, doc, headlineLevel, graph, title): """ else: - return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title) + return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title, render_toc(doc)) + +def render_toc(doc): + acc = ['') + return ''.join(acc) + +def render_toc_headline(headline, acc): + acc.append('
  • ') + acc.append(f'{html.escape(headline.title.get_text())}') + children = list(headline.children) + if children: + acc.append('') + acc.append('
  • ') + + def render_connections(headline_id, content, graph): if headline_id not in graph['backlinks']: @@ -665,13 +686,13 @@ def render(headline, doc, graph, headlineLevel): tags = f'{"".join(tag_list)}' display_state = 'expanded' - # Update display based on document STARTUP config - visual_level = doc.get_keywords('STARTUP', 'showall') - if visual_level.startswith('show') and visual_level.endswith('levels'): - visual_level_num = int(visual_level[len('show'):-len('levels')]) - 1 - # Note that level is 0 indexed inside this loop - if headlineLevel >= visual_level_num: - display_state = 'collapsed' + # # Update display based on document STARTUP config + # visual_level = doc.get_keywords('STARTUP', 'showall') + # if visual_level.startswith('show') and visual_level.endswith('levels'): + # visual_level_num = int(visual_level[len('show'):-len('levels')]) - 1 + # # Note that level is 0 indexed inside this loop + # if headlineLevel >= visual_level_num: + # display_state = 'collapsed' title = render_inline(headline.title, render_tag, headline, graph) @@ -692,7 +713,7 @@ def render(headline, doc, graph, headlineLevel): """ -def as_document(html, title): +def as_document(html, title, global_toc): return f""" @@ -719,6 +740,10 @@ def as_document(html, title):

    Código para llevar [Notes]

    +
    +

    Table of contents

    + {global_toc} +
    {html} diff --git a/static/style.css b/static/style.css index b40101a..75427ac 100644 --- a/static/style.css +++ b/static/style.css @@ -149,7 +149,8 @@ body nav input { } /* Item list */ -.node .contents ul { +.node .contents ul, +.global-table-of-contents ul { --tree-spacing : 1rem; --tree-radius : 0.75ex; --tree-line-separation: 0.5rem; @@ -158,12 +159,14 @@ body nav input { list-style: none; } -.node .contents ul li { +.node .contents ul li, +.global-table-of-contents ul li{ position: relative; padding-left: calc(var(--tree-spacing) * 2); } -.node .contents ul li::after { +.node .contents ul li::after, +.global-table-of-contents ul li::after { content: ''; display: block; position: absolute; @@ -175,7 +178,8 @@ body nav input { background: var(--tree-color); } -.node .contents ul li::before { +.node .contents ul li::before, +.global-table-of-contents ul li::before { content: ' '; width: var(--tree-spacing); display: inline-block; @@ -186,26 +190,36 @@ body nav input { } /* Nested item list */ -.node .contents ul ul { +.node .contents ul ul, +.global-table-of-contents ul ul { padding: 0; margin-left: calc(var(--tree-spacing)); list-style: none; } -.node .contents ul ul li { +.node .contents ul > li > ul, +.global-table-of-contents ul > li > ul { + margin-left: calc(0px - var(--tree-spacing)); +} + +.node .contents ul ul li, +.global-table-of-contents ul ul li { margin-left: calc(0px - var(--tree-radius) / 2 + 2px); border-left: 2px solid var(--tree-color); } -.node .contents ul ul li::marker { +.node .contents ul ul li::marker, +.global-table-of-contents ul ul li::marker { content: ''; } -.node .contents ul ul li::after { +.node .contents ul ul li::after, +.global-table-of-contents ul ul li::after { left: calc(var(--tree-spacing) * 2 - 0.5ex); } -.node .contents ul ul li::before { +.node .contents ul ul li::before, +.global-table-of-contents ul ul li::before { width: calc(var(--tree-spacing) * 2); height: calc(var(--tree-spacing) + 5px); margin-top: -100%; @@ -215,11 +229,13 @@ body nav input { border-bottom-style: solid; } -.node .contents ul ul li:last-of-type::before { +.node .contents ul ul li:last-of-type::before, +.global-table-of-contents ul ul li:last-of-type::before { border-bottom-left-radius: var(--tree-border-radius); } -.node .contents ul li:last-of-type { +.node .contents ul li:last-of-type, +.global-table-of-contents ul li:last-of-type { border-color: transparent; } @@ -533,8 +549,9 @@ tr.__table-separator { border: 1px solid rgba(255,255,255,0.5); } - .node .contents ul { - --tree-color: #666; + .node .contents ul, + .global-table-of-contents ul { + --tree-color: #aaa; } /* Tables. */