diff --git a/eorg/const.py b/eorg/const.py index 3937acb..8053317 100755 --- a/eorg/const.py +++ b/eorg/const.py @@ -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" diff --git a/eorg/parser.py b/eorg/parser.py index 4073afc..8d7ac86 100644 --- a/eorg/parser.py +++ b/eorg/parser.py @@ -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): diff --git a/examples/raw/output.py b/examples/raw/output.py new file mode 100644 index 0000000..21be6e9 --- /dev/null +++ b/examples/raw/output.py @@ -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)