Add simple support for nested markup.

This commit is contained in:
Sergio Martínez Portela 2020-10-25 20:23:08 +01:00
parent 5b886e5e24
commit f6de69fd90
6 changed files with 356 additions and 121 deletions

View file

@ -5,7 +5,7 @@ from datetime import datetime as DT
from org_dom import dumps, load, loads
from utils.dom_assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE,
UNDERLINED, VERBATIM, Dom)
UNDERLINED, VERBATIM, WEB_LINK, Dom,)
DIR = os.path.dirname(os.path.abspath(__file__))
@ -47,6 +47,7 @@ class TestSerde(unittest.TestCase):
self.assertEqual(dumps(doc), orig)
def test_markup_file_02(self):
self.maxDiff = 1024
with open(os.path.join(DIR, '02-markup.org')) as f:
doc = load(f)
@ -60,22 +61,73 @@ class TestSerde(unittest.TestCase):
],
content=[
SPAN(" This is a ", BOLD("bold phrase"),
"."),
SPAN(""),
".\n"),
SPAN("\n"),
SPAN(" This is a ",
VERBATIM("verbatim phrase"), "."),
SPAN(""),
VERBATIM("verbatim phrase"), ".\n"),
SPAN("\n"),
SPAN(" This is a ", ITALIC("italic phrase"),
"."),
SPAN(""),
".\n"),
SPAN("\n"),
SPAN(" This is a ",
STRIKE("strike-through phrase"), "."),
SPAN(""),
STRIKE("strike-through phrase"), ".\n"),
SPAN("\n"),
SPAN(" This is a ",
UNDERLINED("underlined phrase"), "."),
SPAN(""),
UNDERLINED("underlined phrase"), ".\n"),
SPAN("\n"),
SPAN(" This is a ", CODE("code phrase"),
"."),
".\n"),
SPAN("\n"),
SPAN(" This is a nested ", BOLD(["bold ", VERBATIM(["verbatim ", ITALIC(["italic ", STRIKE(["strike ", UNDERLINED(["underlined ", CODE("code ."), " ."]), " ."]), " ."]), " ."]), " ."])),
SPAN("\n"),
# SPAN(""),
# # TODO: THIS IS INTERLEAVED, not nested
# In ORG: This is a interleaved *bold =verbatim /italic +strike _underlined ~code .* .= ./ .+ ._ .~
# SPAN(" This is a nested ", BOLD(["bold ", VERBATIM(["verbatim ", ITALIC(["italic ", STRIKE(["strike ", UNDERLINED(["underlined ", CODE("code ."), " ."]), " ."]), " ."]), " ."]), " ."])),
# SPAN(""),
SPAN("\n"),
SPAN(" This is a _ non-underlined phrase because an incorrectly placed content _.\n"),
SPAN("\n"),
SPAN(" This is a _ non-underlined phrase because an incorrectly placed content beginning_.\n"),
SPAN("\n"),
SPAN(""),
SPAN(" This is a _non-underlined phrase because an incorrectly placed content end _.\n"),
SPAN("\n"),
SPAN(""),
SPAN(" This is a _non-underlined phrase because the lack of an end.\n"),
SPAN("\n"),
SPAN("\n"),
SPAN(" This is a _non-underlined phrase because an empty line between beginning and\n"),
SPAN("\n"),
SPAN(""),
SPAN(" end._\n"),
])))
ex.assert_matches(self, doc)
# def test_links_file_03(self):
# with open(os.path.join(DIR, '03-links.org')) as f:
# doc = load(f)
# ex = Dom(props=[('TITLE', '03-Links'),
# ('DESCRIPTION', 'Simple org file to test links'),
# ('TODO', 'TODO(t) PAUSED(p) | DONE(d)')],
# children=(HL('First level',
# props=[
# ('ID', '03-markup-first-level-id'),
# ('CREATED', DT(2020, 1, 1, 1, 1)),
# ],
# content=[
# SPAN(" This is a ", WEB_LINK("web link", "https://codigoparallevar.com"),
# "."),
# ])))
# ex.assert_matches(self, doc)