Updated simple bullet support to remove bullet text.
This commit is contained in:
parent
7458cc2df9
commit
04220c2af6
|
@ -29,8 +29,8 @@ t_CAPTIONS = r"^\#\+CAPTION:"
|
|||
t_IMG = r"^\[\[\s]]$"
|
||||
t_RESULTS_END = r"^\:..*"
|
||||
|
||||
t_BULLET_START = r"^\s*[\+|\-]"
|
||||
t_BULLET_END = r"^(?!\s*\[\+|\-]).*$"
|
||||
t_BULLET_START = r"^\s*[\+|\-|0-9\.]"
|
||||
t_BULLET_END = r"^\s*(?![\+|\-|0-9]).*$"
|
||||
|
||||
t_HEADER = r"^\*+"
|
||||
t_META_OTHER = r"^[#]\+[A-Z\_]+\:"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from html import escape
|
||||
from io import StringIO
|
||||
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):
|
||||
response = StringIO()
|
||||
response.write(f"<ul{cls}>")
|
||||
for row in item.value.split("\n"):
|
||||
response.write(f"<li>{row}</li>")
|
||||
response.write(f"</ul>")
|
||||
bullet = 'ul'
|
||||
if token.value[0].isdigit():
|
||||
bullet = 'ol'
|
||||
|
||||
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)
|
||||
return response.read()
|
||||
|
||||
|
@ -102,7 +116,7 @@ builddoc = {
|
|||
tokens.VERBATIM: ("code", None),
|
||||
tokens.LIST: (parse_list_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.EXAMPLE: (blockquote, None),
|
||||
tokens.RESULTS: (blockquote, None),
|
||||
|
|
|
@ -76,9 +76,7 @@ class Document:
|
|||
def parse_attrs(text):
|
||||
attrs = {}
|
||||
value_list = text.split(':')
|
||||
print(value_list)
|
||||
attrs['language'] = value_list.pop(0).strip()
|
||||
#attrs['language'] = value_list.pop(0).strip()
|
||||
for row in value_list:
|
||||
values = row.strip().split(' ')
|
||||
attrs[values[0]] = values[1:]
|
||||
|
@ -109,6 +107,8 @@ def parseline(text):
|
|||
return block, Token(token=key, attrs=parse_attrs(value))
|
||||
if key == tokens.TABLE:
|
||||
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)
|
||||
|
||||
text = text.strip()
|
||||
|
|
|
@ -105,22 +105,19 @@ head -n 5 examples/html-plain/example.py
|
|||
assert result[1].value == expected[1].value
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_src_block():
|
||||
def test_bullet_block():
|
||||
text = StringIO(
|
||||
"""
|
||||
+ Bullet 1
|
||||
+ Bullet 2
|
||||
"""
|
||||
+ Bullet 1
|
||||
+ Bullet 2"""
|
||||
)
|
||||
|
||||
expected = [
|
||||
Token(tokens.BLANK, ""),
|
||||
Token(tokens.BULLET, """ Bullet 1\nBullet 2"""),
|
||||
Token(tokens.BULLET, """+ Bullet 1\n+ Bullet 2\n"""),
|
||||
]
|
||||
result = parse(text).doc
|
||||
assert result[0].token == tokens.BLANK
|
||||
assert result[0].value == expected[0].value
|
||||
assert result[1].token == tokens.BULLET
|
||||
|
||||
assert result[1].value == expected[1].value
|
||||
|
|
|
@ -51,3 +51,16 @@ def test_source():
|
|||
rx = const.t_SRC_BEGIN
|
||||
match = re.search(rx, text)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue