+
Emacs org-mode examples
+
Test DESCRIPTION
+
+
+
Emacs org-mode examplesmore_vertThis is a link
-
-
Card titlemore_vert Test DESCRIPTION
+
+
Card titlemore_vert Test DESCRIPTION
diff --git a/examples/html-plain/example.py b/examples/html-plain/example.py
index 0a4e743..ede27cd 100755
--- a/examples/html-plain/example.py
+++ b/examples/html-plain/example.py
@@ -1,24 +1,8 @@
-import os
+import os
from eorg.parser import parse
+from eorg.generate import html
-doc=[]
with open(os.path.abspath('../../tests/fixtures/test.org'), 'r') as fp:
doc = parse(fp)
-
-builddoc ={
- "TITLE": "h1",
- "EMAIL": "h1",
- "AUTHOR": "h1",
- "HEADER1": "h1",
- "HEADER2": "h2",
- "HEADER3": "h3",
- "SRC_BEGIN": "pre",
- "COMMENT": "pre",
-}
-
-
-with open('test.html', 'w') as fp:
- for item in doc:
- print(item)
- tag = builddoc[item.token]
- fp.write('<%s>%s<%s/>\n' % (tag, item.value, tag))
+ with open('test.html', 'w') as fp:
+ fp.write(html(doc).read())
diff --git a/examples/html-plain/test.html b/examples/html-plain/test.html
index 50afeb1..c5d631e 100644
--- a/examples/html-plain/test.html
+++ b/examples/html-plain/test.html
@@ -1,26 +1,11 @@
-
Emacs org-mode examples
- Emacs org-mode examples2
- Eric H. Neilsen, Jr.
- neilsen@fnal.gov
- Header 1
- Sub Header 1
- Sub Header 2
- Header 2
-emacs-lisp :results silent(some lispy code)
-#+END_SRC
-
-#+BEGIN_COMMENT
-.. title: Building a sumo robot ring
-.. slug: building-a-sumo-robot-ring
-.. date: 2017-08-21 12:00:00 UTC
-.. tags: diy, robots, hackspace
-.. category: hardware
-.. description: Attempt at building a largish sumo ring
-.. type: text
-#+END_COMMENT
-
-
-#+BEGIN_SRC emacs-lisp :results silent
-(test code)
-#+END_SRC
-
+ Header 1
+ Sub Header 1
+body text
+ over multiple lines
+
Sub Header 2
+ Header 2
+
\ No newline at end of file
diff --git a/examples/raw/filtering.py b/examples/raw/filtering.py
new file mode 100644
index 0000000..bee57c3
--- /dev/null
+++ b/examples/raw/filtering.py
@@ -0,0 +1,9 @@
+import os
+from eorg.parser import parse
+from eorg.generate import html
+
+with open(os.path.abspath('../../tests/fixtures/test.org'), 'r') as fp:
+ doc = parse(fp)
+ for row in doc.filter('SRC_BEGIN'):
+ print(row.token)
+ print(row.value)
diff --git a/readme.org b/readme.org
index 0d10274..9bcd6e0 100755
--- a/readme.org
+++ b/readme.org
@@ -21,14 +21,26 @@ python setup.py develop
* Examples
** Generating plain html
Simple raw html generation
-#+BEGIN_SRC sh :results output drawer
-head -n 5 examples/html-plain/example.py
-#+END_SRC
+#+BEGIN_SRC sh :results code
+ import os
+ from eorg.parser import parse
+ from eorg.generate import html
-** Enaml web templating language
-Written mainly to try out enaml-web
-#+BEGIN_SRC sh :results output drawer
-head -n 5 examples/html-enaml/example.py
+ with open(os.path.abspath('../../tests/fixtures/test.org'), 'r') as fp:
+ doc = parse(fp)
+ print(html(doc).read())
#+END_SRC
+Simple raw html generation
+#+BEGIN_SRC sh :results code
+ import os
+ from eorg.parser import parse
+ from eorg.generate import html
+
+ with open(os.path.abspath('../../tests/fixtures/test.org'), 'r') as fp:
+ doc = parse(fp)
+ for row in doc.filter('src'):
+ print(row.token)
+#+END_SRC
+
diff --git a/tests/test_documents.py b/tests/test_documents.py
index b8d3871..0c00159 100755
--- a/tests/test_documents.py
+++ b/tests/test_documents.py
@@ -7,8 +7,8 @@ from eorg.generate import html
def test_basic():
with open(os.path.abspath("./tests/fixtures/test.org"), "r") as fp:
doc = parse(fp)
- assert doc.title != ''
- assert doc.author != ''
+ assert doc.title != ""
+ assert doc.author != ""
assert len(doc) == 20
@@ -18,21 +18,22 @@ def test_body():
assert len([i for i in doc.body()]) > 0
-
-
def test_html_output():
with open(os.path.abspath("./tests/fixtures/test.org"), "r") as fp:
doc = parse(fp)
htmlbody = html(doc).read()
print(htmlbody)
- assert htmlbody == """
#+DATE: jkkj
Header 1
-
Sub Header 1
+ assert (
+ htmlbody
+ == """
Header 1
+
Sub Header 1
body text
over multiple lines
-
Sub Header 2
-
Header 2
+
Sub Header 2
+
Header 2
"""
+ )
diff --git a/tests/test_html.py b/tests/test_html.py
index 5ccd6a7..606723a 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -1,7 +1,8 @@
import os
import pytest
from io import StringIO
-from eorg.parser import Token
+from eorg import tokens
+from eorg.tokens import Token
from eorg.parser import parse
from eorg.parser import parse_text
@@ -9,37 +10,37 @@ from eorg.parser import parse_text
def test_emphasis():
text = "parse emphasis *bold text* _underlined text_ /italic text/ normal text"
expected = [
- Token(token="TEXT", value="parse emphasis "),
- Token(token="B", value="bold text"),
- Token(token="TEXT", value=" "),
- Token(token="U", value="underlined text"),
- Token(token="TEXT", value=" "),
- Token(token="I", value="italic text"),
- Token("TEXT", " normal text"),
+ Token(token=tokens.TEXT, value="parse emphasis "),
+ Token(token=tokens.BOLD, value="bold text"),
+ Token(token=tokens.TEXT, value=" "),
+ Token(token=tokens.UNDERLINED, value="underlined text"),
+ Token(token=tokens.TEXT, value=" "),
+ Token(token=tokens.ITALIC, value="italic text"),
+ Token(tokens.TEXT, " normal text"),
]
result = parse_text(text)
- assert result[0].token == "TEXT"
+ assert result[0].token == tokens.TEXT
assert expected[0].value == result[0].value
- assert result[1].token == "B"
+ assert result[1].token == tokens.BOLD
assert expected[1].value == result[1].value
- assert result[2].token == "TEXT"
+ assert result[2].token == tokens.TEXT
assert expected[2].value == result[2].value
- assert result[3].token == "U"
+ assert result[3].token == tokens.UNDERLINED
assert expected[3].value == result[3].value
- assert result[4].token == "TEXT"
+ assert result[4].token == tokens.TEXT
assert expected[4].value == result[4].value
- assert result[5].token == "I"
+ assert result[5].token == tokens.ITALIC
assert expected[5].value == result[5].value
- assert result[6].token == "TEXT"
+ assert result[6].token == tokens.TEXT
assert expected[6].value == result[6].value
def test_image():
text = "parse image [[../../test.jpg][test]] after image"
expected = [
- Token("TEXT", "parse image "),
- Token("IMG", ["../../test.jpg", "test"]),
- Token("TEXT", " after image"),
+ Token(tokens.TEXT, "parse image "),
+ Token(tokens.IMAGE, ["../../test.jpg", "test"]),
+ Token(tokens.TEXT, " after image"),
]
result = parse_text(text)
assert result[0].value == expected[0].value
@@ -50,9 +51,9 @@ def test_image():
def test_link():
text = "parse link [[../../test.html][test]] after link"
expected = [
- Token("TEXT", "parse link "),
- Token("IMG", ["../../test.html", "test"]),
- Token("TEXT", " after link"),
+ Token(tokens.TEXT, "parse link "),
+ Token(tokens.LINK, ["../../test.html", "test"]),
+ Token(tokens.TEXT, " after link"),
]
result = parse_text(text)
assert result[0].value == expected[0].value
@@ -71,9 +72,9 @@ _I'm underlined text_
)
expected = [
- Token("BREAK", ""),
+ Token(tokens.BLANK, ""),
Token(
- "EXAMPLE",
+ tokens.EXAMPLE,
"""*I'm bold text*
/I'm italic text/
_I'm underlined text_
@@ -94,8 +95,8 @@ head -n 5 examples/html-plain/example.py
)
expected = [
- Token("BREAK", ""),
- Token("SRC", """head -n 5 examples/html-plain/example.py\n"""),
+ Token(tokens.BLANK, ""),
+ Token(tokens.SOURCE, """head -n 5 examples/html-plain/example.py\n"""),
]
result = parse(text).doc
print(result)