Skip to content

Commit

Permalink
Merge pull request #512 from Crozzers/link-patterns-params
Browse files Browse the repository at this point in the history
Allow link patterns to be passed via extras dict
  • Loading branch information
nicholasserra committed May 28, 2023
2 parents bf3a3fd + 731cff1 commit 2c092d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [pull #506] Fix `_uniform_outdent` failing with empty strings (issue #505)
- [pull #509] Fix HTML elements not unhashing correctly (issue 508)
- [pull #511] Remove deprecated `imp` module (issue #510)
- [pull #512] Allow link patterns to be passed via extras dict


## python-markdown2 2.4.8
Expand Down
3 changes: 3 additions & 0 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,14 @@ def __init__(self, html4tags=False, tab_width=4, safe_mode=None,
self._instance_extras = self.extras.copy()

if 'link-patterns' in self.extras:
# allow link patterns via extras dict without kwarg explicitly set
link_patterns = link_patterns or extras['link-patterns']
if link_patterns is None:
# if you have specified that the link-patterns extra SHOULD
# be used (via self.extras) but you haven't provided anything
# via the link_patterns argument then an error is raised
raise MarkdownError("If the 'link-patterns' extra is used, an argument for 'link_patterns' is required")

self.link_patterns = link_patterns
self.footnote_title = footnote_title
self.footnote_return_symbol = footnote_return_symbol
Expand Down

0 comments on commit 2c092d1

Please sign in to comment.