Compare commits
1 Commits
bb24f9495e
...
330fd8f7b5
Author | SHA1 | Date | |
---|---|---|---|
|
330fd8f7b5 |
@ -818,7 +818,7 @@ def parse_headline(hl) -> Headline:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class OrgDoc:
|
class OrgDom:
|
||||||
def __init__(self, headlines, keywords, contents):
|
def __init__(self, headlines, keywords, contents):
|
||||||
self.headlines: List[Headline] = list(map(parse_headline, headlines))
|
self.headlines: List[Headline] = list(map(parse_headline, headlines))
|
||||||
self.keywords: List[Property] = keywords
|
self.keywords: List[Property] = keywords
|
||||||
@ -976,16 +976,16 @@ class OrgDoc:
|
|||||||
yield from self.dump_headline(headline)
|
yield from self.dump_headline(headline)
|
||||||
|
|
||||||
|
|
||||||
class OrgDocReader:
|
class OrgDomReader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.headlines: List[Headline] = []
|
self.headlines: List[Headline] = []
|
||||||
self.keywords: List[Property] = []
|
self.keywords: List[Property] = []
|
||||||
self.headline_hierarchy: List[OrgDoc] = []
|
self.headline_hierarchy: List[OrgDom] = []
|
||||||
self.contents: List[RawLine] = []
|
self.contents: List[RawLine] = []
|
||||||
self.delimiters: List[DelimiterLine] = []
|
self.delimiters: List[DelimiterLine] = []
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
return OrgDoc(self.headlines, self.keywords, self.contents)
|
return OrgDom(self.headlines, self.keywords, self.contents)
|
||||||
|
|
||||||
## Construction
|
## Construction
|
||||||
def add_headline(self, linenum: int, match: re.Match) -> int:
|
def add_headline(self, linenum: int, match: re.Match) -> int:
|
||||||
@ -1131,7 +1131,7 @@ class OrgDocReader:
|
|||||||
|
|
||||||
|
|
||||||
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
||||||
reader = OrgDocReader()
|
reader = OrgDomReader()
|
||||||
reader.read(s, environment)
|
reader.read(s, environment)
|
||||||
doc = reader.finalize()
|
doc = reader.finalize()
|
||||||
if extra_cautious: # Check that all options can be properly re-serialized
|
if extra_cautious: # Check that all options can be properly re-serialized
|
||||||
|
@ -6,7 +6,7 @@ from datetime import datetime as DT
|
|||||||
from org_rw import dumps, load, loads
|
from org_rw import dumps, load, loads
|
||||||
|
|
||||||
from utils.assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE, UNDERLINED,
|
from utils.assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE, UNDERLINED,
|
||||||
VERBATIM, WEB_LINK, Doc, Tokens)
|
VERBATIM, WEB_LINK, Dom, Tokens)
|
||||||
|
|
||||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
with open(os.path.join(DIR, "01-simple.org")) as f:
|
with open(os.path.join(DIR, "01-simple.org")) as f:
|
||||||
doc = load(f)
|
doc = load(f)
|
||||||
|
|
||||||
ex = Doc(
|
ex = Dom(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "01-Simple"),
|
("TITLE", "01-Simple"),
|
||||||
("DESCRIPTION", "Simple org file"),
|
("DESCRIPTION", "Simple org file"),
|
||||||
@ -70,7 +70,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
with open(os.path.join(DIR, "02-markup.org")) as f:
|
with open(os.path.join(DIR, "02-markup.org")) as f:
|
||||||
doc = load(f)
|
doc = load(f)
|
||||||
|
|
||||||
ex = Doc(
|
ex = Dom(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "02-Markup"),
|
("TITLE", "02-Markup"),
|
||||||
("DESCRIPTION", "Simple org file to test markup"),
|
("DESCRIPTION", "Simple org file to test markup"),
|
||||||
@ -213,7 +213,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
self.assertEqual(links[3].value, "id:03-markup-first-level-id")
|
self.assertEqual(links[3].value, "id:03-markup-first-level-id")
|
||||||
self.assertEqual(links[3].description, "a link to a section by id")
|
self.assertEqual(links[3].description, "a link to a section by id")
|
||||||
|
|
||||||
ex = Doc(
|
ex = Dom(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "03-Links"),
|
("TITLE", "03-Links"),
|
||||||
("DESCRIPTION", "Simple org file to test links"),
|
("DESCRIPTION", "Simple org file to test links"),
|
||||||
@ -293,7 +293,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
links[3].value = "id:03-markup-non-existent-level-id"
|
links[3].value = "id:03-markup-non-existent-level-id"
|
||||||
links[3].description = None
|
links[3].description = None
|
||||||
|
|
||||||
ex = Doc(
|
ex = Dom(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "03-Links"),
|
("TITLE", "03-Links"),
|
||||||
("DESCRIPTION", "Simple org file to test links"),
|
("DESCRIPTION", "Simple org file to test links"),
|
||||||
|
@ -19,7 +19,7 @@ def get_raw(doc):
|
|||||||
return doc.get_raw()
|
return doc.get_raw()
|
||||||
|
|
||||||
|
|
||||||
class Doc:
|
class Dom:
|
||||||
def __init__(self, *, props=None, children=None):
|
def __init__(self, *, props=None, children=None):
|
||||||
self.props = props
|
self.props = props
|
||||||
self.children = children
|
self.children = children
|
||||||
|
Loading…
Reference in New Issue
Block a user