Skip to content

Commit 4e1eee0

Browse files
committed
Fixed a bug where using an alias with the word text would fail
1 parent 4a4559e commit 4e1eee0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pylint $(git ls-files '*.py') && pytest -vv
158158

159159
## Changelog
160160

161+
### 0.7.1
162+
163+
**Bug Fix:** fixes a bug where any alias with the word "text" would break the plugin due to faulty logic. Reported in [#7](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/7)
164+
161165
### 0.7.0
162166

163167
2024-02-01

alias/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def on_files(self, files, **_):
150150
'alias': alias,
151151
'text': (
152152
meta_data['alias']['text']
153-
if 'text' in meta_data['alias']
153+
# if meta_data['alias'] is a dictionary and 'text' is a key
154+
if isinstance(meta_data['alias'], dict) and 'text' in meta_data['alias']
154155
else get_page_title(source, meta_data)
155156
),
156157
'url': file.src_uri,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='mkdocs-alias-plugin',
10-
version='0.7.0',
10+
version='0.7.1',
1111
description=
1212
'An MkDocs plugin allowing links to your pages using a custom alias',
1313
long_description=long_description,

test_plugin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,19 @@ def test_replace_tag_with_anchor3():
222222
markdown
223223
)
224224
assert result == 'Test: [The Title](../../../my-alias.md#my anchor)'
225+
226+
def test_plugin_shouldnt_break_with_text():
227+
"""An alias with the word 'text' in it shouldn't break the plugin"""
228+
logger = logging.getLogger()
229+
aliases = { 'text': {
230+
'text': 'The Text',
231+
'alias': 'text',
232+
'url': 'my-alias.md'
233+
} }
234+
markdown = 'Test: [[text]]'
235+
result = re.sub(
236+
ALIAS_TAG_REGEX,
237+
lambda match: replace_tag(match, aliases, logger, PAGE_FILE),
238+
markdown
239+
)
240+
assert result == 'Test: [The Text](../../../my-alias.md)'

0 commit comments

Comments
 (0)