Support for plain text nodes
This commit is contained in:
parent
61715c2b28
commit
9a628fd957
|
@ -1,4 +1,6 @@
|
|||
t_META = r"^[#]\+(TITLE|AUTHOR|EMAIL|DESCRIPTION|KEYWORDS)\:"
|
||||
|
||||
METADATA = ['TITLE', 'AUTHOR', 'EMAIL', 'DESCRIPTION', 'KEYWORDS']
|
||||
t_META = r"^[#]\+(" + '|'.join(METADATA) +")\:"
|
||||
t_COMMENT_BEGIN = r"^\#\+BEGIN_COMMENT"
|
||||
t_COMMENT_END = r"^\#\+END_COMMENT"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import re
|
||||
from eorg.const import TOKENS
|
||||
from eorg.const import TOKENS, METADATA
|
||||
|
||||
|
||||
class Token:
|
||||
|
@ -38,6 +38,12 @@ class Document:
|
|||
for item in self.doc:
|
||||
yield item
|
||||
|
||||
def body(self):
|
||||
for item in self.doc:
|
||||
if item.token in METADATA:
|
||||
continue
|
||||
yield item
|
||||
|
||||
def __len__(self):
|
||||
return len(self.doc)
|
||||
|
||||
|
@ -69,7 +75,7 @@ def parseline(text):
|
|||
Token(token=match.group(0)[s:e], value=text[match.end() :]),
|
||||
)
|
||||
return block, Token(token=key, value=text[match.end() :])
|
||||
return None
|
||||
return False, Token(token='TEXT', value=text)
|
||||
|
||||
|
||||
def parse(stream):
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
import os
|
||||
import pytest
|
||||
from eorg.parser import parse
|
||||
|
||||
|
||||
with open(os.path.abspath("../../tests/fixtures/test.org"), "r") as fp:
|
||||
doc = parse(fp)
|
||||
for item in doc.body():
|
||||
print(item)
|
Loading…
Reference in New Issue