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}>")
|
||||||
|
@ -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,9 +148,13 @@ def parse_text(txt):
|
||||||
char = next(step, None)
|
char = next(step, None)
|
||||||
char = next(step, None)
|
char = next(step, None)
|
||||||
|
|
||||||
|
if path.endswith(image_extensions):
|
||||||
tokens.append(Token('IMG', [path, alt]))
|
tokens.append(Token('IMG', [path, alt]))
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
tokens.append(Token('LINK', [path, alt]))
|
||||||
|
return ''
|
||||||
|
|
||||||
def emphasis(char, step, end='*', tag='B'):
|
def emphasis(char, step, end='*', tag='B'):
|
||||||
if not char or char!=end:
|
if not char or char!=end:
|
||||||
return char
|
return char
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = 0.5
|
__version__ = 0.5.1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue