2020-10-09 22:39:32 +00:00
|
|
|
from .org_dom import Headline, Line, RawLine
|
2020-06-27 17:20:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_hl_raw_contents(doc: Headline) -> str:
|
|
|
|
lines = []
|
|
|
|
|
|
|
|
for content in doc.contents:
|
|
|
|
lines.append(get_raw_contents(content))
|
|
|
|
|
2020-10-09 22:39:32 +00:00
|
|
|
raw = ''.join(lines)
|
|
|
|
return raw
|
2020-06-27 17:20:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_rawline_contents(doc: RawLine) -> str:
|
|
|
|
return doc.line
|
|
|
|
|
|
|
|
|
2020-10-09 22:39:32 +00:00
|
|
|
def get_span_contents(doc: Line) -> str:
|
|
|
|
return doc.get_raw()
|
|
|
|
|
|
|
|
|
2020-06-27 17:20:34 +00:00
|
|
|
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)
|
2020-10-09 22:39:32 +00:00
|
|
|
if isinstance(doc, Line):
|
|
|
|
return get_span_contents(doc)
|
|
|
|
if isinstance(doc, list):
|
|
|
|
return ''.join([get_raw_contents(chunk) for chunk in doc])
|
2020-06-27 17:20:34 +00:00
|
|
|
raise NotImplementedError('Unhandled type: ' + str(doc))
|