Skip to content

Commit

Permalink
Merge pull request #617 from Crozzers/link-processor
Browse files Browse the repository at this point in the history
Add `MarkdownFileLinks` extra (#528)
  • Loading branch information
nicholasserra authored Jan 31, 2025
2 parents a3b766b + 259a47e commit b1c26b2
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 198 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## python-markdown2 2.5.4 (not yet released)

(nothing yet)
- [pull #617] Add MarkdownFileLinks extra (#528)


## python-markdown2 2.5.3
Expand Down
576 changes: 383 additions & 193 deletions lib/markdown2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testall.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _python_ver_from_python(python):
assert ' ' not in python
o = os.popen('''%s -c "import sys; print(sys.version)"''' % python)
ver_str = o.read().strip()
ver_bits = re.split(r"\.|[^\d]", ver_str, 2)[:2]
ver_bits = re.split(r"\.|[^\d]", ver_str, maxsplit=2)[:2]
ver = tuple(map(int, ver_bits))
return ver

Expand Down
4 changes: 2 additions & 2 deletions test/tm-cases/fenced_code_blocks_issue426.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2>URL PARAMETERS IN THE TEMPLATE</h2>
<li><p><code>ContextMixin</code> defines the method <code>get_context_data</code>:</p>

<div class="codehilite">
<pre><span></span><code><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">kwargs</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">extra_context</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">extra_context</span><span class="p">)</span>
Expand All @@ -26,7 +26,7 @@ <h2>URL PARAMETERS IN THE TEMPLATE</h2>
<p>So when overriding one must be careful to extends <code>super</code>'s <code>kwargs</code>:</p>

<div class="codehilite">
<pre><span></span><code><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;page_title&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;Documentation&quot;</span>
<span class="k">return</span> <span class="n">kwargs</span>
Expand Down
2 changes: 1 addition & 1 deletion test/tm-cases/fenced_code_blocks_syntax_indentation.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="codehilite">
<pre><span></span><code><span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
<pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">foo</span><span class="p">():</span>
<span class="nb">print</span> <span class="s2">&quot;foo&quot;</span>

<span class="nb">print</span> <span class="s2">&quot;bar&quot;</span>
Expand Down
3 changes: 3 additions & 0 deletions test/tm-cases/markdown_file_links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p><a href="./file.html">This is a link to a markdown file</a></p>

<p><a href="./something.html">This is a reference to a markdown file link</a></p>
1 change: 1 addition & 0 deletions test/tm-cases/markdown_file_links.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'extras': ['markdown-file-links']}
6 changes: 6 additions & 0 deletions test/tm-cases/markdown_file_links.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[This is a link to a markdown file](./file.md)

[This is a reference to a markdown file link][]


[This is a reference to a markdown file link]: ./something.md
1 change: 1 addition & 0 deletions test/tm-cases/markdown_file_links_no_linkdefs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><a href="./something.md">This is a reference to a markdown file link</a> but link definition swapping is disabled</p>
1 change: 1 addition & 0 deletions test/tm-cases/markdown_file_links_no_linkdefs.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'extras': {'markdown-file-links': {'link_defs': False}}}
4 changes: 4 additions & 0 deletions test/tm-cases/markdown_file_links_no_linkdefs.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[This is a reference to a markdown file link][] but link definition swapping is disabled


[This is a reference to a markdown file link]: ./something.md

0 comments on commit b1c26b2

Please sign in to comment.