Skip to content

Commit

Permalink
Revert block state completely if lazy line.
Browse files Browse the repository at this point in the history
This fixes an issue with lazily-wrapped footnotes.

Closes #126.
  • Loading branch information
jgm committed Nov 2, 2023
1 parent 91444cb commit 6ec393d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions commonmark-extensions/test/footnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,25 @@ second</a>
[^third
fourth]</p>
````````````````````````````````

Paragraphs in footnotes can be lazily wrapped (#126).

```````````````````````````````` example
[^foo]:bar
baz
[^foo]
.
<p><sup class="footnote-ref"><a href="#fn-foo" id="fnref-foo">1</a></sup></p>
<section class="footnotes">
<div class="footnote" id="fn-foo">
<div class="footnote-number">
<a href="#fnref-foo">1</a>
</div>
<div class="footnote-contents">
<p>bar
baz</p>
</div>
</div>
</section>
````````````````````````````````
5 changes: 4 additions & 1 deletion commonmark/src/Commonmark/Blocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ processLine specs = do
_ -> False }

-- close unmatched blocks
-- but first save state so we can revert if we have a lazy line
revertState <- getState
if null unmatched
then updateState $ \st -> st{ nodeStack = matched }
-- this update is needed or we lose startpos information
Expand All @@ -153,8 +155,9 @@ processLine specs = do
(do getState >>= guard . maybeLazy
-- lazy line
sp <- getPosition
updateState $ const revertState
updateState $ \st -> st{ nodeStack =
map (addStartPos sp) (unmatched ++ matched) })
map (addStartPos sp) (nodeStack st) })
<|>
void (try (blockStart paraSpec))
<|>
Expand Down

0 comments on commit 6ec393d

Please sign in to comment.