Updated simple bullet support to remove bullet text.

This commit is contained in:
Oly 2018-11-12 14:02:45 +00:00
parent 7458cc2df9
commit 04220c2af6
5 changed files with 40 additions and 16 deletions

View File

@ -29,8 +29,8 @@ t_CAPTIONS = r"^\#\+CAPTION:"
t_IMG = r"^\[\[\s]]$" t_IMG = r"^\[\[\s]]$"
t_RESULTS_END = r"^\:..*" t_RESULTS_END = r"^\:..*"
t_BULLET_START = r"^\s*[\+|\-]" t_BULLET_START = r"^\s*[\+|\-|0-9\.]"
t_BULLET_END = r"^(?!\s*\[\+|\-]).*$" t_BULLET_END = r"^\s*(?![\+|\-|0-9]).*$"
t_HEADER = r"^\*+" t_HEADER = r"^\*+"
t_META_OTHER = r"^[#]\+[A-Z\_]+\:" t_META_OTHER = r"^[#]\+[A-Z\_]+\:"

View File

@ -1,3 +1,4 @@
import re
from html import escape from html import escape
from io import StringIO from io import StringIO
from eorg.const import Token, ESCAPE from eorg.const import Token, ESCAPE
@ -43,10 +44,23 @@ def parse_list_html(doc, token, cls="", root=True):
def parse_bullets_html(doc, token, cls="", root=True): def parse_bullets_html(doc, token, cls="", root=True):
response = StringIO() response = StringIO()
response.write(f"<ul{cls}>") bullet = 'ul'
for row in item.value.split("\n"): if token.value[0].isdigit():
response.write(f"<li>{row}</li>") bullet = 'ol'
response.write(f"</ul>")
response.write(f"<{bullet}{cls} style=\"list-style-type: decimal-leading-zero;\">")
for row in token.value.split("\n"):
if row:
text = ''
if row[0] in ['-', '+']:
text = re.sub(r'^\s*[-|+]+\s*', '', row, 1)
if row[0].isdigit():
text = re.sub(r'^\s*[0-9]+\.*\s*', '', row, 1)
response.write(f"<li class=\"collection-item\">{text}</li>")
response.write(f"</{bullet}>")
response.seek(0) response.seek(0)
return response.read() return response.read()
@ -102,7 +116,7 @@ builddoc = {
tokens.VERBATIM: ("code", None), tokens.VERBATIM: ("code", None),
tokens.LIST: (parse_list_html, "flow-text"), tokens.LIST: (parse_list_html, "flow-text"),
tokens.TEXT: (parse_text_html, "flow-text"), tokens.TEXT: (parse_text_html, "flow-text"),
tokens.BULLET: (parse_bullets_html, ""), tokens.BULLET: (parse_bullets_html, "browser-default"),
tokens.SOURCE: (src, None), tokens.SOURCE: (src, None),
tokens.EXAMPLE: (blockquote, None), tokens.EXAMPLE: (blockquote, None),
tokens.RESULTS: (blockquote, None), tokens.RESULTS: (blockquote, None),

View File

@ -76,9 +76,7 @@ class Document:
def parse_attrs(text): def parse_attrs(text):
attrs = {} attrs = {}
value_list = text.split(':') value_list = text.split(':')
print(value_list)
attrs['language'] = value_list.pop(0).strip() attrs['language'] = value_list.pop(0).strip()
#attrs['language'] = value_list.pop(0).strip()
for row in value_list: for row in value_list:
values = row.strip().split(' ') values = row.strip().split(' ')
attrs[values[0]] = values[1:] attrs[values[0]] = values[1:]
@ -109,6 +107,8 @@ def parseline(text):
return block, Token(token=key, attrs=parse_attrs(value)) return block, Token(token=key, attrs=parse_attrs(value))
if key == tokens.TABLE: if key == tokens.TABLE:
return block, Token(token=key, value=text+"\n") return block, Token(token=key, value=text+"\n")
if key == tokens.BULLET:
return block, Token(token=key, value=text+"\n")
return block, Token(token=key, value=value, attrs=attrs) return block, Token(token=key, value=value, attrs=attrs)
text = text.strip() text = text.strip()

View File

@ -105,22 +105,19 @@ head -n 5 examples/html-plain/example.py
assert result[1].value == expected[1].value assert result[1].value == expected[1].value
@pytest.mark.skip def test_bullet_block():
def test_src_block():
text = StringIO( text = StringIO(
""" """
+ Bullet 1 + Bullet 1
+ Bullet 2 + Bullet 2"""
"""
) )
expected = [ expected = [
Token(tokens.BLANK, ""), Token(tokens.BLANK, ""),
Token(tokens.BULLET, """ Bullet 1\nBullet 2"""), Token(tokens.BULLET, """+ Bullet 1\n+ Bullet 2\n"""),
] ]
result = parse(text).doc result = parse(text).doc
assert result[0].token == tokens.BLANK assert result[0].token == tokens.BLANK
assert result[0].value == expected[0].value assert result[0].value == expected[0].value
assert result[1].token == tokens.BULLET assert result[1].token == tokens.BULLET
assert result[1].value == expected[1].value assert result[1].value == expected[1].value

View File

@ -51,3 +51,16 @@ def test_source():
rx = const.t_SRC_BEGIN rx = const.t_SRC_BEGIN
match = re.search(rx, text) match = re.search(rx, text)
assert match is not None assert match is not None
def test_bullets():
# invalid if no language specified
text=" + bullet 1"
rx = const.t_BULLET_START
match = re.search(rx, text)
assert match is not None
text="+ bullet 1"
rx = const.t_BULLET_START
match = re.search(rx, text)
assert match is not None