From a6607ba0f35872385fb3f64a651150010f440d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 23 Oct 2022 21:16:22 +0200 Subject: [PATCH] WIP: Support bare links (no []). --- scripts/generate.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index 1833389..fc40371 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -10,6 +10,7 @@ import sys import uuid from datetime import datetime import traceback +import re import inotify.adapters @@ -43,6 +44,8 @@ MONITORED_EVENT_TYPES = ( 'IN_MOVE_SELF', ) +WHITESPACE_RE = re.compile(r'\s') + ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) STATIC_PATH = os.path.join(ROOT_DIR, 'static') @@ -402,8 +405,29 @@ def render_text_tokens(tokens, acc, headline, graph): acc.append('

') for chunk in tokens: if isinstance(chunk, str): - lines = chunk.replace('\n\n', '

') - acc.append('{}'.format(lines)) + lines = chunk.split('\n\n') + contents = [] + for line in lines: + line_chunks = [] + for word in WHITESPACE_RE.split(line): + if ':/' in word and not (word.startswith('org-protocol://')): + if not (word.startswith('http://') + or word.startswith('https://') + or word.startswith('ftp://') + or word.startswith('ftps://') + ): + print("Line:", line) + print("Chunks:", WHITESPACE_RE.split(line)) + raise Exception('Is this a link? {} (on {})'.format(word, headline.doc.path)) + line_chunks.append('{description}' + .format(url=word, + description=html.escape(word))) + else: + line_chunks.append(html.escape(word)) + contents.append(' '.join(line_chunks)) + + acc.append('{}'.format('

'.join(contents))) + elif isinstance(chunk, Link): link_target = chunk.value if link_target.startswith('id:'):