Add links to LinkItems.

This commit is contained in:
Sergio Martínez Portela 2022-05-06 20:19:11 +02:00
parent c86ec3fc9b
commit 8295154a96

View File

@ -122,13 +122,13 @@ def render_list_group(element, acc):
def render_list_item(element, acc): def render_list_item(element, acc):
acc.append("<li>") acc.append("<li>")
if element.content.tag is not None: if element.tag is not None:
acc.append("<span class='tag'>") acc.append("<span class='tag'>")
acc.append(element.content.tag) acc.append(element.tag)
acc.append("</span>") acc.append("</span>")
acc.append("<span class='item'>") acc.append("<span class='item'>")
acc.append(token_list_to_raw(element.content.content)) render_text_tokens(element.content, acc)
acc.append("</span></li>") acc.append("</span></li>")
@ -137,14 +137,19 @@ def render_code_block(element, acc):
def render_text(element, acc): def render_text(element, acc):
for chunk in element.content: acc.append('<span class="text">')
render_text_tokens(element.content, acc)
acc.append('</span>')
def render_text_tokens(tokens, acc):
for chunk in tokens:
if isinstance(chunk, str): if isinstance(chunk, str):
acc.append('<span class="text">{}</span> '.format(chunk)) acc.append('{}</span> '.format(chunk))
elif isinstance(chunk, Link): elif isinstance(chunk, Link):
# @TODO: URLEscape # @TODO: URLEscape
acc.append('<a href="{}">{}</a>'.format(chunk.value, chunk.description)) acc.append('<a href="{}">{}</a>'.format(chunk.value, chunk.description))
else: else:
raise NotImplemented() raise NotImplementedError('TextToken: {}'.format(chunk))
def render_tag(element, acc): def render_tag(element, acc):
@ -165,8 +170,8 @@ def render_tree(tree, acc):
def render(headline, doc): def render(headline, doc):
# if headline.id != "41b1ee7e-ddbf-41ff-bc79-18258506ebe6": if headline.id != "ea48ec1d-f9d4-4fb7-b39a-faa7b6e2ba95":
# return "" return ""
print("\n===========") print("\n===========")
dom = headline.as_dom() dom = headline.as_dom()
print_tree(dom) print_tree(dom)