Basic table support
This commit is contained in:
parent
87dc29dda3
commit
003a592319
|
@ -11,6 +11,8 @@ t_EXAMPLE_BEGIN = r"^\#\+BEGIN_EXAMPLE"
|
||||||
t_EXAMPLE_END = r"^\#\+END_EXAMPLE"
|
t_EXAMPLE_END = r"^\#\+END_EXAMPLE"
|
||||||
t_SRC_BEGIN = r"^\#\+BEGIN_SRC\s+"
|
t_SRC_BEGIN = r"^\#\+BEGIN_SRC\s+"
|
||||||
t_SRC_END = r"^\#\+END_SRC"
|
t_SRC_END = r"^\#\+END_SRC"
|
||||||
|
t_TABLE_START = r"^\s*\|"
|
||||||
|
t_TABLE_END = r"^(?!\s*\|).*$"
|
||||||
t_RESULTS_START = r"^\#\+RESULTS:"
|
t_RESULTS_START = r"^\#\+RESULTS:"
|
||||||
t_CAPTIONS = r"^\#\+CAPTION:"
|
t_CAPTIONS = r"^\#\+CAPTION:"
|
||||||
t_IMG = r"^\[\[\s]]$"
|
t_IMG = r"^\[\[\s]]$"
|
||||||
|
@ -26,6 +28,7 @@ TOKENS = {
|
||||||
tokens.IMAGE: (t_IMG, False, 2, None, False),
|
tokens.IMAGE: (t_IMG, False, 2, None, False),
|
||||||
tokens.CAPTION: (t_CAPTIONS, False, 2, None, False),
|
tokens.CAPTION: (t_CAPTIONS, False, 2, None, False),
|
||||||
tokens.SOURCE: (t_SRC_BEGIN, t_SRC_END, 2, None, False),
|
tokens.SOURCE: (t_SRC_BEGIN, t_SRC_END, 2, None, False),
|
||||||
|
tokens.TABLE: (t_TABLE_START, t_TABLE_END, 0, None, False),
|
||||||
tokens.RESULTS: (t_SRC_BEGIN, t_SRC_END, 2, None, False),
|
tokens.RESULTS: (t_SRC_BEGIN, t_SRC_END, 2, None, False),
|
||||||
tokens.HEADER: (t_HEADER, False, 1, None, True),
|
tokens.HEADER: (t_HEADER, False, 1, None, True),
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,9 @@ 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:]
|
||||||
|
@ -94,17 +96,20 @@ def parseline(text):
|
||||||
match = re.search(rx, text)
|
match = re.search(rx, text)
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
continue
|
||||||
|
value = text[match.end() :]
|
||||||
level = len(match.group(0))
|
level = len(match.group(0))
|
||||||
if count is True:
|
if count is True:
|
||||||
attrs={'depth': level}
|
attrs={'depth': level}
|
||||||
if key == tokens.META:
|
if key == tokens.META:
|
||||||
return (
|
return (
|
||||||
block,
|
block,
|
||||||
Token(token=match.group(0)[s:e], value=text[match.end() :]),
|
Token(token=match.group(0)[s:e], value=value),
|
||||||
)
|
)
|
||||||
if key == tokens.SOURCE:
|
if key == tokens.SOURCE:
|
||||||
return block, Token(token=key, attrs=parse_attrs(text[match.end():]))
|
return block, Token(token=key, attrs=parse_attrs(value))
|
||||||
return block, Token(token=key, value=text[match.end():], attrs=attrs)
|
if key == tokens.TABLE:
|
||||||
|
return block, Token(token=key, value=text+"\n")
|
||||||
|
return block, Token(token=key, value=value, attrs=attrs)
|
||||||
|
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
if text == "":
|
if text == "":
|
||||||
|
|
|
@ -14,6 +14,7 @@ SOURCE = 50
|
||||||
EXAMPLE = 51
|
EXAMPLE = 51
|
||||||
RESULTS = 52
|
RESULTS = 52
|
||||||
COMMENT = 53
|
COMMENT = 53
|
||||||
|
TABLE = 54
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__=0.60
|
__version__=0.65
|
||||||
|
|
|
@ -99,7 +99,7 @@ head -n 5 examples/html-plain/example.py
|
||||||
Token(tokens.SOURCE, """head -n 5 examples/html-plain/example.py\n"""),
|
Token(tokens.SOURCE, """head -n 5 examples/html-plain/example.py\n"""),
|
||||||
]
|
]
|
||||||
result = parse(text).doc
|
result = parse(text).doc
|
||||||
print(result)
|
assert result[0].token == tokens.BLANK
|
||||||
assert result[0].value == expected[0].value
|
assert result[0].value == expected[0].value
|
||||||
assert result[1].attrs.get('language') == 'sh'
|
assert result[1].attrs.get('language') == 'sh'
|
||||||
assert result[1].value == expected[1].value
|
assert result[1].value == expected[1].value
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
from io import StringIO
|
||||||
|
from eorg import tokens
|
||||||
|
from eorg.parser import parse
|
||||||
|
from eorg.generate import html
|
||||||
|
|
||||||
|
|
||||||
|
def test_basic():
|
||||||
|
document = """| Header 1 | Header 2 |
|
||||||
|
| row 1 | row 2 |
|
||||||
|
"""
|
||||||
|
doc = parse(StringIO(document))
|
||||||
|
assert doc.doc[0].token == tokens.TABLE
|
||||||
|
r1 = doc.doc[0].value.strip()
|
||||||
|
r2 = document.strip()
|
||||||
|
print(r1)
|
||||||
|
print(r2)
|
||||||
|
assert r1 == r2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue