forked from kenkeiras/org-rw
Rename to org-rw.
This commit is contained in:
parent
83710a4fc1
commit
bb24f9495e
10 changed files with 30 additions and 30 deletions
2
org_rw/__init__.py
Normal file
2
org_rw/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from .org_rw import *
|
||||
from .utils import *
|
1161
org_rw/org_rw.py
Normal file
1161
org_rw/org_rw.py
Normal file
File diff suppressed because it is too large
Load diff
38
org_rw/utils.py
Normal file
38
org_rw/utils.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, Strike, Text,
|
||||
Underlined, Verbatim)
|
||||
|
||||
|
||||
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_text_contents(doc: Text) -> 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])
|
||||
if isinstance(doc, (Text, Bold, Code, Italic, Strike, Underlined, Verbatim)):
|
||||
return doc.get_raw()
|
||||
print("Unhandled type: " + str(doc))
|
||||
raise NotImplementedError("Unhandled type: " + str(doc))
|
Loading…
Add table
Add a link
Reference in a new issue