Add support for markdown and link parsing on lists.

This commit is contained in:
Sergio Martínez Portela 2021-08-03 23:05:15 +02:00
parent 7cf643200e
commit 7e944bcb3d
2 changed files with 24 additions and 9 deletions

View File

@ -99,6 +99,8 @@ def get_tokens(value):
return value.contents
if isinstance(value, RawLine):
return [value.line]
if isinstance(value, list):
return value
raise Exception("Unknown how to get tokens from: {}".format(value))
@ -361,6 +363,10 @@ class Headline:
for content in self.contents:
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):
for line in self.contents:
if start <= line.linenum < end:
@ -1551,7 +1557,9 @@ class OrgDocReader:
match.group("checkbox_value"),
match.group("tag_indentation"),
match.group("tag"),
match.group("content"),
parse_content_block(
[RawLine(linenum=linenum, line=match.group("content"))]
).contents,
)
if len(self.headline_hierarchy) == 0:

View File

@ -4,7 +4,7 @@ import unittest
from datetime import date
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,
VERBATIM, WEB_LINK, Doc, Tokens)
@ -459,13 +459,20 @@ class TestSerde(unittest.TestCase):
# ...
lists = hl.getLists()
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][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, "+")
hl2 = doc.getTopHeadlines()[1]
@ -473,19 +480,19 @@ class TestSerde(unittest.TestCase):
lists2 = hl2.getLists()
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_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_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_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_sep, ")")