Skip to content

Commit 5385e89

Browse files
committed
release 3.24.4
1 parent a416d68 commit 5385e89

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## 3.24.4
4+
5+
- Fixed bug introduced by supporting escaped brackets in markdown link labels ...
6+
37

48
## 3.24.3
59

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Robert Forkel'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '3.24.4.dev0'
25+
release = '3.24.4'
2626

2727

2828
# -- General configuration ---------------------------------------------------

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = clldutils
3-
version = 3.24.4.dev0
3+
version = 3.24.4
44
license = Apache 2.0
55
license_files = LICENSE
66
author = Robert Forkel

src/clldutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.24.4.dev0'
1+
__version__ = '3.24.4'

src/clldutils/markup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ class MarkdownLink:
226226
"""
227227
label = attr.ib()
228228
url = attr.ib()
229-
pattern = re.compile(r'(?<!!)\[(?P<label>.*?)(?<!\\)]\((?P<url>[^)]+)\)')
229+
# Link starts with "[" if not preceeded by "!" or escaped with "\".
230+
# We match up to the next unescaped "]" and only optionally match the href enclosed in "()".
231+
# This is we don't force parsing up to the next "]("!
232+
pattern = re.compile(r'(?<!!)(?<!\\)\[(?P<label>.*?)(?<!\\)](\((?P<url>[^)]+)\))?')
230233
html_link = ('a', 'href')
231234

232235
@classmethod
@@ -238,6 +241,8 @@ def from_string(cls, s):
238241

239242
@classmethod
240243
def from_match(cls, match):
244+
if match.groupdict()['url'] is None:
245+
raise AttributeError
241246
return cls(**match.groupdict())
242247

243248
@property
@@ -369,6 +374,9 @@ def replace(cls,
369374
links = list(reversed(links))
370375

371376
def repl_wrapper(m):
377+
if m.groupdict()['url'] is None:
378+
yield m.string[m.start():m.end()]
379+
return
372380
if not simple:
373381
if not links:
374382
# We got them all.

tests/test_markup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ def test_markdownlink1(markdown, expected):
101101
assert MarkdownLink.replace(markdown, lambda ml: ml.update_url(fragment='c')) == expected
102102

103103

104+
def test_non_link_square_brackets():
105+
assert MarkdownLink.replace(
106+
'\\[stuff\\] and [a](b)) ', lambda ml: "--") == '\\[stuff\\] and --) '
107+
assert MarkdownLink.replace(
108+
'[stuff] and [a](b)) ', lambda ml: "--") == '[stuff] and --) '
109+
110+
111+
def test_invalid_markdownlink():
112+
with pytest.raises(ValueError):
113+
_ = MarkdownLink.from_string('[abc]')
114+
115+
104116
def test_escaped_brackets():
105117
text = r'[2001 \[2011\]](http://example.com) and [2022](url)'
106118
ml = MarkdownLink.from_string(text)

0 commit comments

Comments
 (0)