Add support for markdown and link parsing on lists.
This commit is contained in:
parent
7cf643200e
commit
7e944bcb3d
@ -99,6 +99,8 @@ def get_tokens(value):
|
|||||||
return value.contents
|
return value.contents
|
||||||
if isinstance(value, RawLine):
|
if isinstance(value, RawLine):
|
||||||
return [value.line]
|
return [value.line]
|
||||||
|
if isinstance(value, list):
|
||||||
|
return value
|
||||||
raise Exception("Unknown how to get tokens from: {}".format(value))
|
raise Exception("Unknown how to get tokens from: {}".format(value))
|
||||||
|
|
||||||
|
|
||||||
@ -361,6 +363,10 @@ class Headline:
|
|||||||
for content in self.contents:
|
for content in self.contents:
|
||||||
yield from get_links_from_content(content)
|
yield from get_links_from_content(content)
|
||||||
|
|
||||||
|
for lst in self.getLists():
|
||||||
|
for item in lst:
|
||||||
|
yield from get_links_from_content(item.content)
|
||||||
|
|
||||||
def get_lines_between(self, start, end):
|
def get_lines_between(self, start, end):
|
||||||
for line in self.contents:
|
for line in self.contents:
|
||||||
if start <= line.linenum < end:
|
if start <= line.linenum < end:
|
||||||
@ -1551,7 +1557,9 @@ class OrgDocReader:
|
|||||||
match.group("checkbox_value"),
|
match.group("checkbox_value"),
|
||||||
match.group("tag_indentation"),
|
match.group("tag_indentation"),
|
||||||
match.group("tag"),
|
match.group("tag"),
|
||||||
match.group("content"),
|
parse_content_block(
|
||||||
|
[RawLine(linenum=linenum, line=match.group("content"))]
|
||||||
|
).contents,
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(self.headline_hierarchy) == 0:
|
if len(self.headline_hierarchy) == 0:
|
||||||
|
@ -4,7 +4,7 @@ import unittest
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from datetime import datetime as DT
|
from datetime import datetime as DT
|
||||||
|
|
||||||
from org_rw import Timestamp, dumps, load, loads
|
from org_rw import MarkerToken, MarkerType, Timestamp, 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, Doc, Tokens)
|
||||||
@ -459,13 +459,20 @@ class TestSerde(unittest.TestCase):
|
|||||||
# ...
|
# ...
|
||||||
lists = hl.getLists()
|
lists = hl.getLists()
|
||||||
self.assertEqual(len(lists), 3)
|
self.assertEqual(len(lists), 3)
|
||||||
self.assertEqual(lists[0][0].content, " This is a simple list.")
|
self.assertEqual(lists[0][0].content, [" This is a simple list."])
|
||||||
self.assertEqual(lists[0][0].bullet, "-")
|
self.assertEqual(lists[0][0].bullet, "-")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
lists[0][1].content, " This list has multiple elements, with _markup_."
|
lists[0][1].content,
|
||||||
|
[
|
||||||
|
" This list has multiple elements, with ",
|
||||||
|
MarkerToken(closing=False, tok_type=MarkerType.UNDERLINED_MODE),
|
||||||
|
"markup",
|
||||||
|
MarkerToken(closing=True, tok_type=MarkerType.UNDERLINED_MODE),
|
||||||
|
".",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(lists[1][0].content, " This is a simple list.")
|
self.assertEqual(lists[1][0].content, [" This is a simple list."])
|
||||||
self.assertEqual(lists[1][0].bullet, "+")
|
self.assertEqual(lists[1][0].bullet, "+")
|
||||||
|
|
||||||
hl2 = doc.getTopHeadlines()[1]
|
hl2 = doc.getTopHeadlines()[1]
|
||||||
@ -473,19 +480,19 @@ class TestSerde(unittest.TestCase):
|
|||||||
lists2 = hl2.getLists()
|
lists2 = hl2.getLists()
|
||||||
self.assertEqual(len(lists2), 2)
|
self.assertEqual(len(lists2), 2)
|
||||||
|
|
||||||
self.assertEqual(lists2[0][0].content, " First element")
|
self.assertEqual(lists2[0][0].content, [" First element"])
|
||||||
self.assertEqual(lists2[0][0].counter, "1")
|
self.assertEqual(lists2[0][0].counter, "1")
|
||||||
self.assertEqual(lists2[0][0].counter_sep, ".")
|
self.assertEqual(lists2[0][0].counter_sep, ".")
|
||||||
|
|
||||||
self.assertEqual(lists2[0][1].content, " Second element")
|
self.assertEqual(lists2[0][1].content, [" Second element"])
|
||||||
self.assertEqual(lists2[0][1].counter, "2")
|
self.assertEqual(lists2[0][1].counter, "2")
|
||||||
self.assertEqual(lists2[0][1].counter_sep, ".")
|
self.assertEqual(lists2[0][1].counter_sep, ".")
|
||||||
|
|
||||||
self.assertEqual(lists2[1][0].content, " First element")
|
self.assertEqual(lists2[1][0].content, [" First element"])
|
||||||
self.assertEqual(lists2[1][0].counter, "1")
|
self.assertEqual(lists2[1][0].counter, "1")
|
||||||
self.assertEqual(lists2[1][0].counter_sep, ")")
|
self.assertEqual(lists2[1][0].counter_sep, ")")
|
||||||
|
|
||||||
self.assertEqual(lists2[1][1].content, " Second element")
|
self.assertEqual(lists2[1][1].content, [" Second element"])
|
||||||
self.assertEqual(lists2[1][1].counter, "2")
|
self.assertEqual(lists2[1][1].counter, "2")
|
||||||
self.assertEqual(lists2[1][1].counter_sep, ")")
|
self.assertEqual(lists2[1][1].counter_sep, ")")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user