Extract titles from gemtext and use them as GeminiItem.name if that's missing.

This commit is contained in:
Solderpunk 2023-11-19 14:27:47 +01:00
parent 0a9846b342
commit a459e49fa0
1 changed files with 9 additions and 0 deletions

View File

@ -699,6 +699,7 @@ you'll be able to transparently follow links to Gopherspace!""")
"""
self.index = []
preformatted = False
title = ""
with open(self.active_raw_file, "r") as fp:
body = fp.read()
@ -732,6 +733,8 @@ you'll be able to transparently follow links to Gopherspace!""")
elif line.startswith("#"):
line = line[1:].lstrip("\t ")
fp.write("\x1b[1m\x1b[4m" + line + "\x1b[0m""\n")
if not title:
title = line
else:
fp.write(textwrap.fill(line, self.options["width"]) + "\n")
@ -739,6 +742,12 @@ you'll be able to transparently follow links to Gopherspace!""")
self.page_index = 0
self.index_index = -1
# If the supplied GI didn't have a name (e.g. we arrived at it from a
# manually entered URL, not a link), use the title inferred from the
# first top level header
if not menu_gi.name:
menu_gi.name = title
def _format_geminiitem(self, index, gi, url=False):
"""
Render a link line.