Collapse non top-level nodes.

This commit is contained in:
Sergio Martínez Portela 2022-05-07 20:38:12 +02:00
parent 0696ffa075
commit 8698035f2e
2 changed files with 39 additions and 7 deletions

View File

@ -17,6 +17,7 @@ EXTENSIONS = [
".org.txt",
]
MIN_HIDDEN_HEADLINE_LEVEL = 2
def load_all(top_dir_relative):
top = os.path.abspath(top_dir_relative)
@ -92,7 +93,7 @@ def main(src_top, dest_top):
main_headline = [h for h in topHeadlines if h != related][0]
with open(endpath, "wt") as f:
f.write(as_document(render(main_headline, doc)))
f.write(as_document(render(main_headline, doc, headlineLevel=0)))
files_generated += 1
else:
logging.error("Cannot render document from id: {}. {} headlines {} related".format(
@ -105,7 +106,7 @@ def main(src_top, dest_top):
endpath = os.path.join(dest_top, headline.id + ".node.html")
with open(endpath, "wt") as f:
f.write(as_document(render(headline, doc)))
f.write(as_document(render(headline, doc, headlineLevel=0)))
files_generated += 1
logging.info("Generated {} files".format(files_generated))
@ -200,7 +201,7 @@ def render(headline, doc):
content = []
render_tree(dom, content)
for child in headline.children:
content.append(render(child, doc))
content.append(render(child, doc, headlineLevel=headlineLevel+1))
if headline.state is None:
state = ""
@ -211,17 +212,23 @@ def render(headline, doc):
todo_state = "todo"
else:
todo_state = "done"
display_state = 'collapsed'
if headlineLevel < MIN_HIDDEN_HEADLINE_LEVEL:
display_state = 'expanded'
return f"""
<div id="{html.escape(headline.id)}" class="node {todo_state}">
<div id="{html.escape(headline.id)}" class="node {todo_state} {display_state}">
<h1 class="title">
{state}
<a href=\"org-protocol://org-id?id={html.escape(headline.id)}\">
<a href=\"javascript:toggle_expand('{html.escape(headline.id)}')\">
{html.escape(headline.title)}
</a>
</h1>
<div class='contents'>
{''.join(content)}
</div>
</div>
"""
@ -230,6 +237,19 @@ def as_document(html):
<html>
<head>
<link href="../static/style.css" rel="stylesheet"/>
<script type="text/javascript">
function toggle_expand(header_id) {{
var e = document.getElementById(header_id);
if (e.classList.contains('expanded')) {{
e.classList.add('collapsed');
e.classList.remove('expanded');
}}
else {{
e.classList.add('expanded');
e.classList.remove('collapsed');
}}
}}
</script>
</head>
<body>
{html}

View File

@ -12,6 +12,18 @@
border-left: 2px solid #2c3e50;
}
.node.collapsed > .contents {
display: none;
}
.node .node.collapsed > .title::before {
content: "🮥";
}
.node .node.expanded > .title::before {
content: "🮦";
}
h1 {
font-size: 150%;
}