From 7f9d60c748d4eca922ff618db5b3ff58e5163231 Mon Sep 17 00:00:00 2001 From: Oliver Marks Date: Sun, 11 Nov 2018 22:08:25 +0000 Subject: [PATCH] Add in support for meta unknown attributes. --- eorg/const.py | 27 ++++++++++++++++++++++----- eorg/tokens.py | 5 +++-- tests/test_regex.py | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/eorg/const.py b/eorg/const.py index 923ac2b..aa583a3 100755 --- a/eorg/const.py +++ b/eorg/const.py @@ -1,10 +1,21 @@ from eorg import tokens -ESCAPE = ['\n'] + +ESCAPE = ["\n"] -METADATA = ['TITLE', 'AUTHOR', 'EMAIL', 'DESCRIPTION', 'KEYWORDS', 'FILETAGS', 'DATE'] -t_META = r"^[#]\+(" + '|'.join(METADATA) +")\:" -t_BLANK_LINE = '^\s*$' +METADATA = [ + "TITLE", + "AUTHOR", + "EMAIL", + "DESCRIPTION", + "KEYWORDS", + "FILETAGS", + "DATE", + "HTML_DOCTYPE", + "SETUPFILE", +] +t_META = r"^[#]\+(" + "|".join(METADATA) + ")\:" +t_BLANK_LINE = "^\s*$" t_COMMENT_BEGIN = r"^\#\+BEGIN_COMMENT" t_COMMENT_END = r"^\#\+END_COMMENT" t_EXAMPLE_BEGIN = r"^\#\+BEGIN_EXAMPLE" @@ -18,7 +29,11 @@ t_CAPTIONS = r"^\#\+CAPTION:" t_IMG = r"^\[\[\s]]$" t_RESULTS_END = r"^\:..*" +t_BULLET_START = r"^\s*[\+|\-]" +t_BULLET_END = r"^(?!\s*\[\+|\-]).*$" + t_HEADER = r"^\*+" +t_META_OTHER = r"^[#]\+[A-Z\_]+\:" # Start regex, End regex, skip start, skip end, count matches TOKENS = { @@ -29,12 +44,13 @@ TOKENS = { tokens.CAPTION: (t_CAPTIONS, False, 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.BULLET: (t_BULLET_START, t_BULLET_END, 0, None, False), tokens.RESULTS: (t_SRC_BEGIN, t_SRC_END, 2, None, False), tokens.HEADER: (t_HEADER, False, 1, None, True), + tokens.META_OTHER: (t_META_OTHER, False, 2, -1, False), } - class Token: __slots__ = ["token", "value"] @@ -45,4 +61,5 @@ class Token: def __repr__(self): return f"Token(token={self.token}, value={self.value})" + image_extensions = (".jpg", ".jpeg", ".png", ".svg") diff --git a/eorg/tokens.py b/eorg/tokens.py index 481b43c..62ae4a6 100644 --- a/eorg/tokens.py +++ b/eorg/tokens.py @@ -1,6 +1,7 @@ BLANK = 0 META = 1 -HEADER = 2 +META_OTHER = 2 +HEADER = 5 BOLD = 10 ITALIC = 11 UNDERLINED = 12 @@ -10,6 +11,7 @@ TEXT = 21 IMAGE = 22 LINK = 23 CAPTION = 24 +BULLET = 25 SOURCE = 50 EXAMPLE = 51 RESULTS = 52 @@ -17,7 +19,6 @@ COMMENT = 53 TABLE = 54 - class Token: __slots__ = ["token", "value", "attrs"] diff --git a/tests/test_regex.py b/tests/test_regex.py index 2fd238b..6e6fe46 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -6,6 +6,22 @@ from eorg.parser import parse from eorg.generate import html +def test_meta_headers(): + text="#+TITLE: test title" + rx = const.t_META + match = re.search(rx, text) + assert match is not None + + text="#+UNKNOWN: test title" + rx = const.t_META + match = re.search(rx, text) + assert match is None + + text="#+UNKNOWN: test title" + rx = const.t_META_OTHER + match = re.search(rx, text) + assert match is not None + def test_example(): text="#+BEGIN_EXAMPLE" rx = const.t_EXAMPLE_BEGIN