Compare commits

..

No commits in common. "f3ca823b0cd6e8c78b8c57274fac3fb146ad3cd4" and "121ad46680c32b705a35e1ccc1355a0037f7502d" have entirely different histories.

3 changed files with 12 additions and 58 deletions

View File

@ -1306,12 +1306,10 @@ def tokenize_contents(contents: str):
len(contents) > i + 3 len(contents) > i + 3
# At least 3 characters more to open and close a link # At least 3 characters more to open and close a link
and contents[i + 1] == "[" and contents[i + 1] == "["
# TODO: Generalize this to a backtracking, don't just fix the test case...
and contents[i + 2] != "["
): ):
close = contents.find("]]", i) close = contents.find("]", i)
if close != -1: if close != -1 and contents[close + 1] == "]":
# Link with no description # Link with no description
cut_string() cut_string()
@ -1335,7 +1333,7 @@ def tokenize_contents(contents: str):
continue continue
# Possible link close or open of description # Possible link close or open of description
if char == "]" and len(contents) > i + 1 and in_link: if char == "]" and in_link:
if contents[i + 1] == "]": if contents[i + 1] == "]":
cut_string() cut_string()
@ -1345,13 +1343,19 @@ def tokenize_contents(contents: str):
in_link_description = False in_link_description = False
continue continue
elif contents[i + 1] == "[": if contents[i + 1] == "[" and not in_link_description:
cut_string() cut_string()
tokens.append((TOKEN_TYPE_OPEN_DESCRIPTION, None)) tokens.append((TOKEN_TYPE_OPEN_DESCRIPTION, None))
assert "[" == (next(cursor)[1]) assert "[" == (next(cursor)[1])
continue continue
raise Exception(
"Link cannot contain ']' not followed by '[' or ']'. Starting with {}".format(
contents[last_link_start : i + 10]
)
)
if in_link and not in_link_description: if in_link and not in_link_description:
# Link's pointer have no formatting # Link's pointer have no formatting
pass pass

View File

@ -17,7 +17,3 @@
This is [[id:03-markup-first-level-id][a link to a section by id]]. This is [[id:03-markup-first-level-id][a link to a section by id]].
This is a [[https://codigoparallevar.com/3][web link]] followed up with some text. This is a [[https://codigoparallevar.com/3][web link]] followed up with some text.
This is a [[https://codigoparallevar.com/4][[tricky web link]]] followed up with some text.
This is [[[https://codigoparallevar.com/5][another tricky web link]]] followed up with some text.

View File

@ -201,7 +201,7 @@ class TestSerde(unittest.TestCase):
doc = load(f) doc = load(f)
links = list(doc.get_links()) links = list(doc.get_links())
self.assertEqual(len(links), 7) self.assertEqual(len(links), 5)
self.assertEqual(links[0].value, "https://codigoparallevar.com/1") self.assertEqual(links[0].value, "https://codigoparallevar.com/1")
self.assertEqual(links[0].description, "web link") self.assertEqual(links[0].description, "web link")
@ -217,12 +217,6 @@ class TestSerde(unittest.TestCase):
self.assertEqual(links[4].value, "https://codigoparallevar.com/3") self.assertEqual(links[4].value, "https://codigoparallevar.com/3")
self.assertEqual(links[4].description, "web link") self.assertEqual(links[4].description, "web link")
self.assertEqual(links[5].value, "https://codigoparallevar.com/4")
self.assertEqual(links[5].description, "[tricky web link]\u200b")
self.assertEqual(links[6].value, "https://codigoparallevar.com/5")
self.assertEqual(links[6].description, "another tricky web link")
ex = Doc( ex = Doc(
props=[ props=[
("TITLE", "03-Links"), ("TITLE", "03-Links"),
@ -276,18 +270,6 @@ class TestSerde(unittest.TestCase):
WEB_LINK("web link", "https://codigoparallevar.com/3"), WEB_LINK("web link", "https://codigoparallevar.com/3"),
" followed up with some text.\n", " followed up with some text.\n",
), ),
SPAN("\n"),
SPAN(
" This is a ",
WEB_LINK("[tricky web link]\u200b", "https://codigoparallevar.com/4"),
" followed up with some text.\n",
),
SPAN("\n"),
SPAN(
" This is [",
WEB_LINK("another tricky web link", "https://codigoparallevar.com/5"),
"] followed up with some text.\n",
),
], ],
) )
), ),
@ -300,7 +282,7 @@ class TestSerde(unittest.TestCase):
doc = load(f) doc = load(f)
links = list(doc.get_links()) links = list(doc.get_links())
self.assertEqual(len(links), 7) self.assertEqual(len(links), 5)
self.assertEqual(links[0].value, "https://codigoparallevar.com/1") self.assertEqual(links[0].value, "https://codigoparallevar.com/1")
self.assertEqual(links[0].description, "web link") self.assertEqual(links[0].description, "web link")
links[0].value = "https://codigoparallevar.com/1-updated" links[0].value = "https://codigoparallevar.com/1-updated"
@ -326,16 +308,6 @@ class TestSerde(unittest.TestCase):
links[4].value = "https://codigoparallevar.com/3-updated" links[4].value = "https://codigoparallevar.com/3-updated"
links[4].description = "web link #3 with update" links[4].description = "web link #3 with update"
self.assertEqual(links[5].value, "https://codigoparallevar.com/4")
self.assertEqual(links[5].description, "[tricky web link]\u200b")
links[5].value = "https://codigoparallevar.com/4-updated"
links[5].description = "[tricky web link #4 with update]"
self.assertEqual(links[6].value, "https://codigoparallevar.com/5")
self.assertEqual(links[6].description, "another tricky web link")
links[6].value = "https://codigoparallevar.com/5-updated"
links[6].description = "another tricky web link #5 with update"
ex = Doc( ex = Doc(
props=[ props=[
("TITLE", "03-Links"), ("TITLE", "03-Links"),
@ -396,24 +368,6 @@ class TestSerde(unittest.TestCase):
), ),
" followed up with some text.\n", " followed up with some text.\n",
), ),
SPAN("\n"),
SPAN(
" This is a ",
WEB_LINK(
"[tricky web link #4 with update]",
"https://codigoparallevar.com/4-updated",
),
" followed up with some text.\n",
),
SPAN("\n"),
SPAN(
" This is [",
WEB_LINK(
"another tricky web link #5 with update",
"https://codigoparallevar.com/5-updated",
),
"] followed up with some text.\n",
),
], ],
) )
), ),