Small patch to handle links properly
This commit is contained in:
parent
c616c3f712
commit
c3095e43a9
|
@ -39,3 +39,4 @@ class Token:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Token(token={self.token}, value={self.value})"
|
return f"Token(token={self.token}, value={self.value})"
|
||||||
|
|
||||||
|
image_extensions = (".jpg", ".jpeg", ".png", ".svg")
|
||||||
|
|
|
@ -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}'
|
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):
|
def parse_list_html(doc, token, cls="", root=True):
|
||||||
response = StringIO()
|
response = StringIO()
|
||||||
response.write(f"<p{cls}>")
|
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):
|
def parse_text_html(doc, token, cls="", root=True):
|
||||||
# if its the start of a text body wrap html tags
|
# if its the start of a text body wrap html tags
|
||||||
# else more complicated so return the 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"<p{cls}>{token.value}</p>"
|
||||||
return f"{token.value}"
|
return f"{token.value}"
|
||||||
|
|
||||||
|
@ -46,8 +50,8 @@ builddoc = {
|
||||||
"HEADER1": ("h2", None),
|
"HEADER1": ("h2", None),
|
||||||
"HEADER2": ("h3", None),
|
"HEADER2": ("h3", None),
|
||||||
"HEADER3": ("h4", None),
|
"HEADER3": ("h4", None),
|
||||||
# "BREAK": "br",
|
|
||||||
"IMG": (img, "materialboxed center-align responsive-img"),
|
"IMG": (img, "materialboxed center-align responsive-img"),
|
||||||
|
"LINK": (link, None),
|
||||||
"B": ("b", None),
|
"B": ("b", None),
|
||||||
"U": ("u", None),
|
"U": ("u", None),
|
||||||
"I": ("i", None),
|
"I": ("i", None),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import re
|
import re
|
||||||
from eorg.const import TOKENS, METADATA, ESCAPE
|
from eorg.const import TOKENS, METADATA, ESCAPE, image_extensions
|
||||||
|
|
||||||
|
|
||||||
class Token:
|
class Token:
|
||||||
|
@ -148,7 +148,11 @@ def parse_text(txt):
|
||||||
char = next(step, None)
|
char = next(step, None)
|
||||||
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 ''
|
return ''
|
||||||
|
|
||||||
def emphasis(char, step, end='*', tag='B'):
|
def emphasis(char, step, end='*', tag='B'):
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = 0.5
|
__version__ = 0.5.1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue