Fix bare links next to [
or ]
characters.
This commit is contained in:
parent
a6607ba0f3
commit
8d8dcbfdce
@ -44,7 +44,7 @@ MONITORED_EVENT_TYPES = (
|
|||||||
'IN_MOVE_SELF',
|
'IN_MOVE_SELF',
|
||||||
)
|
)
|
||||||
|
|
||||||
WHITESPACE_RE = re.compile(r'\s')
|
TEXT_OR_LINK_RE = re.compile(r'([^\s\[\]]+|.)')
|
||||||
|
|
||||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
@ -409,22 +409,20 @@ def render_text_tokens(tokens, acc, headline, graph):
|
|||||||
contents = []
|
contents = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line_chunks = []
|
line_chunks = []
|
||||||
for word in WHITESPACE_RE.split(line):
|
for word in TEXT_OR_LINK_RE.findall(line):
|
||||||
if ':/' in word and not (word.startswith('org-protocol://')):
|
if ':/' in word and not (word.startswith('org-protocol://')):
|
||||||
if not (word.startswith('http://')
|
if not (word.startswith('http://')
|
||||||
or word.startswith('https://')
|
or word.startswith('https://')
|
||||||
or word.startswith('ftp://')
|
or word.startswith('ftp://')
|
||||||
or word.startswith('ftps://')
|
or word.startswith('ftps://')
|
||||||
):
|
):
|
||||||
print("Line:", line)
|
raise Exception('Is this a link? {} (on {})\nLine: {}\nChunks: {}'.format(word, headline.doc.path, line, chunks))
|
||||||
print("Chunks:", WHITESPACE_RE.split(line))
|
|
||||||
raise Exception('Is this a link? {} (on {})'.format(word, headline.doc.path))
|
|
||||||
line_chunks.append('<a href="{url}">{description}</a>'
|
line_chunks.append('<a href="{url}">{description}</a>'
|
||||||
.format(url=word,
|
.format(url=word,
|
||||||
description=html.escape(word)))
|
description=html.escape(word)))
|
||||||
else:
|
else:
|
||||||
line_chunks.append(html.escape(word))
|
line_chunks.append(html.escape(word))
|
||||||
contents.append(' '.join(line_chunks))
|
contents.append(''.join(line_chunks))
|
||||||
|
|
||||||
acc.append('<span class="line">{}</span>'.format('</p><p>'.join(contents)))
|
acc.append('<span class="line">{}</span>'.format('</p><p>'.join(contents)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user