Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
20 changes: 13 additions & 7 deletions commonmark-extensions/src/Commonmark/Extensions/Footnote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,31 @@ footnoteBlockSpec = BlockSpec
updateState $ \s -> s{ counters =
M.insert "footnote" (toDyn (num + 1))
(counters s) }
isBlankLine <- option False $ try (skipWhile (hasType Spaces) >> True <$ lookAhead lineEnd)
addNodeToStack $
Node (defBlockData footnoteBlockSpec){
blockData = toDyn (num, lab')
blockData = toDyn (num, lab', isBlankLine)
, blockStartPos = [pos] } []
return BlockStartMatch
, blockCanContain = const True
, blockContainsLines = False
, blockParagraph = False
, blockContinue = \n -> try $ do
() <$ (gobbleSpaces 4)
<|> (skipWhile (hasType Spaces) >> () <$ lookAhead lineEnd)
pos <- getPosition
return $! (pos, n)
, blockContinue = \(Node root children) -> try $ do
let (num, lab', needsIndented) = fromDyn (blockData root) (1 :: Int, mempty :: Text, False)
isBlankLine <- option False $ try (skipWhile (hasType Spaces) >> True <$ lookAhead lineEnd)
if needsIndented && not isBlankLine then
gobbleSpaces 4
else
gobbleUpToSpaces 4
pos <- getPosition
let footnoteData = toDyn (num, lab', isBlankLine)
return $! (pos, Node root{ blockData = footnoteData} children)
, blockConstructor = \node ->
mconcat <$> mapM (\n ->
blockConstructor (blockSpec (rootLabel n)) n)
(subForest (reverseSubforests node))
, blockFinalize = \(Node root children) parent -> do
let (num, lab') = fromDyn (blockData root) (1, mempty)
let (num, lab', _indented) = fromDyn (blockData root) (1, mempty, False)
st <- getState
let mkNoteContents refmap =
runParserT
Expand Down
56 changes: 56 additions & 0 deletions commonmark-extensions/test/footnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,59 @@ second</a>
[^third
fourth]</p>
````````````````````````````````

Only the first line of a footnote's following paragraph needs indented.

```````````````````````````````` example
[^foo]:bar
baz
quux
arst
qwfp
[^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>
<p>quux
arst
qwfp</p>
</div>
</div>
</section>
````````````````````````````````

Lazy continuations require the first line to have text in it,
and to lazily continue a paragraph after the first, it will need to
start with an indented line also.

```````````````````````````````` example
[^foo]:
baz
quux
[^foo]
.
<p>baz</p>
<pre><code>quux
</code></pre>
<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">
</div>
</div>
</section>
````````````````````````````````

0 comments on commit cd06539

Please sign in to comment.