org-rw/org_dom/utils.py
Sergio Martínez Portela 5b886e5e24 Pass markup tests.
2020-10-10 00:39:32 +02:00

32 lines
779 B
Python

from .org_dom import Headline, Line, RawLine
def get_hl_raw_contents(doc: Headline) -> str:
lines = []
for content in doc.contents:
lines.append(get_raw_contents(content))
raw = ''.join(lines)
return raw
def get_rawline_contents(doc: RawLine) -> str:
return doc.line
def get_span_contents(doc: Line) -> str:
return doc.get_raw()
def get_raw_contents(doc) -> str:
if isinstance(doc, Headline):
return get_hl_raw_contents(doc)
if isinstance(doc, RawLine):
return get_rawline_contents(doc)
if isinstance(doc, Line):
return get_span_contents(doc)
if isinstance(doc, list):
return ''.join([get_raw_contents(chunk) for chunk in doc])
raise NotImplementedError('Unhandled type: ' + str(doc))