Small patch to handle links properly

This commit is contained in:
Oliver Marks 2018-11-01 21:18:48 +00:00
parent c616c3f712
commit c3095e43a9
4 changed files with 14 additions and 5 deletions

View File

@ -39,3 +39,4 @@ class Token:
def __repr__(self):
return f"Token(token={self.token}, value={self.value})"
image_extensions = (".jpg", ".jpeg", ".png", ".svg")

View File

@ -23,6 +23,10 @@ def img(doc, item, cls="", root=True):
return f'<img{cls} style="margin:auto;" src="{item.value[0]}" alt="{item.value[1]}" />{text}'
def link(doc, item, cls="", root=True):
return f'<a {cls} style="margin:auto;" href="{item.value[0]}">{item.value[1]}</a>'
def parse_list_html(doc, token, cls="", root=True):
response = StringIO()
response.write(f"<p{cls}>")
@ -37,7 +41,7 @@ def parse_list_html(doc, token, cls="", root=True):
def parse_text_html(doc, token, cls="", root=True):
# if its the start of a text body wrap html tags
# else more complicated so return the tags
#if root is True:
# if root is True:
# return f"<p{cls}>{token.value}</p>"
return f"{token.value}"
@ -46,8 +50,8 @@ builddoc = {
"HEADER1": ("h2", None),
"HEADER2": ("h3", None),
"HEADER3": ("h4", None),
# "BREAK": "br",
"IMG": (img, "materialboxed center-align responsive-img"),
"LINK": (link, None),
"B": ("b", None),
"U": ("u", None),
"I": ("i", None),

View File

@ -1,5 +1,5 @@
import re
from eorg.const import TOKENS, METADATA, ESCAPE
from eorg.const import TOKENS, METADATA, ESCAPE, image_extensions
class Token:
@ -148,7 +148,11 @@ def parse_text(txt):
char = next(step, None)
char = next(step, None)
tokens.append(Token('IMG', [path, alt]))
if path.endswith(image_extensions):
tokens.append(Token('IMG', [path, alt]))
return ''
tokens.append(Token('LINK', [path, alt]))
return ''
def emphasis(char, step, end='*', tag='B'):

View File

@ -1,2 +1,2 @@
__version__ = 0.5
__version__ = 0.5.1