Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4adac1c

Browse files
authored
Merge pull request#423 from kylechui/main
feat: Support footnotes that start on the next line.
2 parents9f4ff6f +0516c9e commit4adac1c

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

‎src/mistune/plugins/footnotes.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
_PARAGRAPH_SPLIT=re.compile(r"\n{2,}")
1717
# https://michelf.ca/projects/php-markdown/extra/#footnotes
1818
REF_FOOTNOTE= (
19-
r"^(?P<footnote_lead> {0,3})"
20-
r"\[\^(?P<footnote_key>"+LINK_LABEL+r")]:[ \t]"
19+
r"^(?P<footnote_lead> {0,4})"
20+
r"\[\^(?P<footnote_key>"+LINK_LABEL+r")]:[ \t\n]"
2121
r"(?P<footnote_text>[^\n]*(?:\n+|$)"
22-
r"(?:(?P=footnote_lead) {1,3}(?! )[^\n]*\n+)*"
22+
r"(?:(?P=footnote_lead) {1,4}(?! )[^\n]*\n+)*"
2323
r")"
2424
)
2525

@@ -70,8 +70,11 @@ def parse_footnote_item(block: "BlockParser", key: str, index: int, state: Block
7070
spaces=len(second_line)-len(second_line.lstrip())
7171
pattern=re.compile(r"^ {"+str(spaces)+r",}",flags=re.M)
7272
text=pattern.sub("",text).strip()
73-
items=_PARAGRAPH_SPLIT.split(text)
74-
children= [{"type":"paragraph","text":s}forsinitems]
73+
74+
footer_state=BlockState()
75+
footer_state.process(text)
76+
block.parse(footer_state)
77+
children=footer_state.tokens
7578
else:
7679
text=text.strip()
7780
children= [{"type":"paragraph","text":text}]

‎tests/fixtures/footnotes.txt‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,67 @@ multiple lines [^1]
3131
three
3232

3333
four
34+
35+
five
3436
.
3537
<p>multiple lines <sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p>
36-
<pre><code>four</code></pre>
38+
<pre><code> five</code></pre>
3739
<section class="footnotes">
3840
<ol>
3941
<li id="fn-1"><p>foo</p>
4042
<p>one</p>
4143
<p>two</p>
42-
<p>three<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
44+
<p>three</p>
45+
<p>four<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
46+
</ol>
47+
</section>
48+
````````````````````````````````
49+
50+
```````````````````````````````` example
51+
multi-line footnote[^1]
52+
53+
[^1]:
54+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
55+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
56+
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
57+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
58+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
59+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
60+
.
61+
<p>multi-line footnote<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p>
62+
<section class="footnotes">
63+
<ol>
64+
<li id="fn-1"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
65+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
66+
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
67+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
68+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
69+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
70+
</ol>
71+
</section>
72+
````````````````````````````````
73+
74+
```````````````````````````````` example
75+
fenced code block in footnote[^1]
76+
77+
[^1]:
78+
first
79+
80+
```sh
81+
second
82+
third
83+
```
84+
85+
fourth
86+
.
87+
<p>fenced code block in footnote<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p>
88+
<section class="footnotes">
89+
<ol>
90+
<li id="fn-1"><p>first</p>
91+
<pre><code class="language-sh">second
92+
third
93+
</code></pre>
94+
<p>fourth<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
4395
</ol>
4496
</section>
4597
````````````````````````````````

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp