From 4d3997bce1d308c6288565bbca71ae93d60ecd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 23 Oct 2022 18:28:08 +0200 Subject: [PATCH] Render `* Target` links. --- scripts/generate.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/generate.py b/scripts/generate.py index 48d803f..14c2043 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -288,6 +288,13 @@ def main(src_top, dest_top): continue logging.info("Updated all in {:.2f}s".format(time.time() - t0)) +def get_headline_with_name(target_name, doc): + target_name = target_name.strip() + for headline in doc.getAllHeadlines(): + if headline.title.get_text().strip() == target_name: + return headline + + return None def print_tree(tree, indentation=0, headline=None): # if headline and headline.id != INDEX_ID: @@ -416,7 +423,11 @@ def render_text_tokens(tokens, acc, headline, graph): elif link_target.startswith('git://'): logging.warn('Not implemented `git://`. Used on {}'.format(link_target)) elif link_target.startswith('* '): - logging.warn('Not implemented `* Headline` links. Used on {}'.format(link_target)) + target_headline = get_headline_with_name(link_target.lstrip('* '), headline.doc) + if target_headline is None: + logging.warn('No headline found corresponding to {}. On file {}'.format(link_target, headline.doc.path)) + else: + link_target = './' + target_headline.id + '.node.html' else: if not ( link_target.startswith('https://')