Skip to content

Footnote definition does not end #20

Closed

Description

@critiqjo
extern crate pulldown_cmark as cmark;

use cmark::{Options, Parser};

fn main() {
    for e in Parser::new_ext("Hello, [^goo]\n\n\
                              [^goo]: world.\n\n\
                              Follow [link][ref]",
                             Options::all()) {
        println!("{:?}", e);
    }
}

The above code outputs (footnote definition extending until the end):

Start(Paragraph)
Text("Hello, ")
FootnoteReference("goo")
End(Paragraph)
Start(FootnoteDefinition("goo"))
Start(Paragraph)
Text("world.")
End(Paragraph)
Start(Paragraph)
Text("Follow ")
Text("[link]")
Text("[ref]")
End(Paragraph)
End(FootnoteDefinition("goo"))

Activity

  1. raphlinus commented on Apr 10, 2016

    @raphlinus
    Collaborator

    I sent a PR to take a look at. One question I have is, how should the following be handled:

    a: [^b]
    
    [^b]: * a
    * b
    
    * c
    
    d
    

    Here we have a conflict between two rules: the footnote should be closed by one blank line, but the list (which is inside the footnote) is closed by two. With the code in the PR, the list [a, b] is inside the footnote def, while c gets its own list. This seems reasonable but I want to think about whether it's truly the best behavior.

    Alternatively (since the spec doesn't nail this down), we can dictate that footnotes and lists are both consistently ended by two blank lines.

  2. notriddle commented on Apr 10, 2016

    @notriddle
    Collaborator

    I (personally) don't see this as a bug. If you look in specs/footnote.txt, multi-paragraph footnotes are deliberately supported, and footnotes are already ended on two blank lines.

  3. critiqjo commented on Apr 10, 2016

    @critiqjo
    Author

    multi-paragraph footnotes are deliberately supported

    I see... I did not "expect" that (or lists) in footnotes. Generally, footnotes are a single paragraph of text.

    since the spec doesn't nail this down

    If we are going to take the route of making footnotes end with a single blank line (which is probably what most people might expect, and markdown is about being intuitive, right?), then deny lists inside it (for consistency in number of blank lines). I'm against it because it will look kinda ugly if footnote definitions (containing lists) are rendered as a numeric list (as in wikipedia).

  4. critiqjo commented on Apr 11, 2016

    @critiqjo
    Author

    Spec for multi-block footnote-definitions.

    1. Footnote definitions are container blocks which cannot be defined within another container.

      > reference[^b].
      >
      > [^b]: but this is not a valid footnote definition
      
    2. A footnote definition can be indented with at most 3 spaces.

         [^b]: footnote text
      
    3. If a sequence of blocks should be contained within a footnote definition, indent it to align with the first non-whitespace character in the definition body.

      [^b]: * list item1 inside footnote
            * list item2 inside footnote
      * list item outside footnote
      
    4. The footnote definition continues as long as the indentation matches (or exceeds):

      [^b]: * list item1 inside footnote
      
      
      
            * list item2 inside footnote
      
      
      
      
            still inside footnote
      
    5. For convenience, the definition body can start in the next line too, with a non-zero indentation (at least N+2 spaces, 0≤N≤3 is the initial indentation):

       [^long-footnote-name]:
         inside footnote
         * list item inside footnote
      
        outside footnote
      

      The definition body cannot start in the next line without the minimum indentation. The following should be treated as an empty footnote definition:

      [^long-empty-footnote]:
       outside footnote
      
    6. Laziness with paragraph continuation:

      [^b]: footnote;
      still in the first line.
            * list item inside footnote;
      within the list item line
      

    UPDATE (2017-03-30): Simplify
    UPDATE (2017-03-31): Better consistency

  5. chriskrycho commented on May 2, 2016

    @chriskrycho

    FWIW, the reason the spec acts the way it does is because, whatever is most common in writing contexts, multi-paragraph footnotes are a genuine need. (I have from time to time used them myself.) Just as importantly in many ways, pretty much all existing implementations with footnote support treat footnotes as a(n indented) block type, which allows them to have multiple paragraphs within them. So whatever is most purely "intuitive" may not be what's best in this case.

  6. ScottAbbey commented on Mar 30, 2017

    @ScottAbbey
    Collaborator

    Regarding the list within footnote issue above:

    but the list (which is inside the footnote) is closed by two.

    This appears to have changed between CommonMark 0.26 and 0.27.

    0.26:

    list items may be separated by single blank lines, but two blank lines end all containing lists

    0.27:

    list items may be separated by any number of blank lines

    So it is clear that the c list item must in all cases be a part of the list that contains the b list item.

  7. ScottAbbey commented on Mar 30, 2017

    @ScottAbbey
    Collaborator

    Follow-up from #21 (comment):

    It looks like this footnote spec is homegrown rather than part of the CommonMark spec. How open is it for change?

    I would not have expected list item b to be part of the [^b] footnote definition at all.

    It appears as though a footnote definition should treated as a container block -- all indications in this thread are that footnotes are expected to support multiple paragraphs, lists, and other blocks.

    If a footnote definition is a container block, it should act very much like list items do in CommonMark. Continuing lines in a footnote definition should be indented to the same level as the first non-whitespace character after the [^b]: item. The rules to end a list item should apply to a footnote definition.

    Is there an argument against treating footnotes as an additional type of container block similar to a list item?

  8. critiqjo commented on Mar 30, 2017

    @critiqjo
    Author

    The following text:

    foot[^note1], foot[^note2]
    
    [^note1]: text1
    [^note2]: text2
    

    Generates:

    [
        Start(Paragraph),
        Text("foot"),
        FootnoteReference("note1"),
        Text(", foot"),
        FootnoteReference("note2"),
        End(Paragraph),
        Start(FootnoteDefinition("note1")),
        Start(Paragraph),
        Text("text1"),
        SoftBreak,
        FootnoteReference("note2"),           # note this
        Text(": text2"),
        End(Paragraph),
        End(FootnoteDefinition("note1"))
    ]
    

    Instead of:

    [
        Start(Paragraph),
        Text("foot"),
        FootnoteReference("note1"),
        Text(", foot"),
        FootnoteReference("note2"),
        End(Paragraph),
        Start(FootnoteDefinition("note1")),
        Start(Paragraph),
        Text("text1"),
        End(Paragraph),
        End(FootnoteDefinition("note1"))
        Start(FootnoteDefinition("note2")),
        Start(Paragraph),
        Text("text2"),
        End(Paragraph),
        End(FootnoteDefinition("note2"))
    ]
    

    Which can be generated if there is a blank line between footnote definitions. Is this intentional too?

  9. ScottAbbey commented on Mar 30, 2017

    @ScottAbbey
    Collaborator

    Which can be generated if there is a blank line between footnote definitions. Is this intentional too?

    It appears to be intentional as that is covered specifically by a test case in the footnotes.txt spec. I would have expected your example to be two separate footnote definitions if I hadn't read that spec first.

    Was this footnote spec copied from somewhere or just made for this program?

  10. notriddle commented on Mar 30, 2017

    @notriddle
    Collaborator

    I just made it up.

  11. critiqjo commented on Mar 30, 2017

    @critiqjo
    Author

    After going through the spec for lists once again, and keeping the goal to maximize intuitiveness, I rewrote the spec I proposed earlier (in-place). Please take a look. I tried to make it consistent with the current style of specs.

  12. ScottAbbey commented on Mar 30, 2017

    @ScottAbbey
    Collaborator

    This example:

    [^long-footnote-name]:
      inside footnote
      * list item inside footnote
    outside footnote
    

    With the footnote identifier change to a list item marker would be all one list item due to lazy continuation rules. The "outside footnote" text would be part of the "list item inside footnote" (see here)

    Considering your second example as a list item rather than a footnote, it seems fine. However, this version should probably all be one footnote due to laziness:

    [^b]: text
    inside footnote
    

    This version with the subsequent line indented to one space beyond the footnote marker should probably be just like a list item starting with a blank line:

    [^b]:
          inside footnote
    

    I agree with your third example.

    It seems like the one place this still differs from list items is dealing with a long footnote name. Subsequent blocks inside a list item (except in the case of laziness) need to be indented as far as the first non-whitespace character after the list marker. If the footnote name is very long, this could be impractical.

    I think the discussion starting with "Would it help to adopt a two-space rule?" under 5.2.1 Motivation in the CommonMark spec may be relevant here.

    Perhaps a two-space rule can be justified by something like "The [^ is the footnote definition indicator, so everything should be indented past that." Not sure. Seems a little messy still.

  13. critiqjo commented on Mar 31, 2017

    @critiqjo
    Author

    @ScottAbbey You're right, that's indeed an inconsistency. I'll update the proposal soon.

    UPDATE: Updated

  14. oberien commented on Aug 4, 2018

    @oberien
    Contributor

    What's the status on this? I just ran into this problem with the following reference-list:

    [^foo]: foo
    [bar]: bar

    This generates the following events, which make the parser not being able to find the link definition and instead calls the broken_link_callback:

    Start(FootnoteDefinition("foo")),
    Start(Paragraph),
    Text("foo"),
    SoftBreak,
    Text("[bar]: bar"),
    End(Paragraph),
    End(FootnoteDefinition("foo"))
  15. chriskrycho commented on Sep 17, 2021

    @chriskrycho

    Looking at the proposed spec here, and this one is probably not quite right:

    1. If a sequence of blocks should be contained within a footnote definition, indent it to align with the first non-whitespace character in the definition body.
    [^b]: * list item1 inside footnote
          * list item2 inside footnote
    * list item outside footnote
    

    The indentation rule here is unnecessarily different from the rules for other container types. Most of them allow this variation instead

    A paragraph of text to host a footnote.[^b]
    
    [^b]: Here is a paragraph in the footnote, and then a list.
    
        * list item1 inside footnote
        * list item2 inside footnote
    
    * list item outside footnote

    This is how pandoc renders it

    <p>A paragraph of text to host a footnote.<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
    <ul>
    <li>list item outside footnote</li>
    </ul>
    <section class="footnotes" role="doc-endnotes">
    <hr />
    <ol>
    <li id="fn1" role="doc-endnote"><p>Here is a paragraph in the footnote, and then a list.</p>
    <ul>
    <li>list item1 inside footnote</li>
    <li>list item2 inside footnote</li>
    </ul>
    <a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></li>
    </ol>
    </section>

    That is, roughly (given the limitations of GH's HTML rendering):

    A paragraph of text to host a footnote.1

    • list item outside footnote

    1. Here is a paragraph in the footnote, and then a list.

      • list item1 inside footnote
      • list item2 inside footnote
      ↩︎

    What's more, it renders the same regardless of the amount you indent within the block as long as there is no end to the contained block—for example, with a list immediately following.

    Without suggesting that Pandoc's implementation is normative, it's nonetheless fairly representative. There's some variation on the treatment of the * list item outside footnote bit in other implementations, as well as on what indentation is required. Pandoc footnotes don’t require indentation at all as long as there is no double-newline ending the block. Most other implementations I’m aware of do require indentation, of whatever size is required to start/continue a new block child in the implementation generally.

    That means rule 3 should actually be something like:

    1. If a sequence of blocks should be contained within a footnote definition, indent it as a block continuation (the same as continuing a list).
    [^fn-def]:
        * list item1 inside footnote
        * list item2 inside footnote
    * list item outside footnote
    

    This could/should be a bit more precise: it would be best to match up that indentation rule with the normal block continuation rules from the CommonMark spec.

  16. chriskrycho commented on Nov 20, 2021

    @chriskrycho

    Note for folks following this thread: I am (albeit very slowly) working my way toward a solution to alllll the footnote issues over on #544. Honestly, it’ll likely be the end of the year before I have something working (at earliest!) but I really, really want “standard” footnotes to just work in pulldown-cmark, so I’m going to keep pushing on it, however slowly.

  17. ssokolow commented on Apr 6, 2023

    @ssokolow

    It also breaks this example from GitHub's GFM docs...

    [^1]: My reference.
    [^2]: To add line breaks within a footnote, prefix new lines with 2 spaces.
      This is a second line.
    

    ...and renders multiple footnote definitions in a group incompatible with Prettier, which collapses away any blank lines you manually insert between them and likely will insist that you're in the wrong if you don't bow to their decision that different Markdown dialects must have non-standard extensions.

    (At least, that was their opinion when I asked for a config option to support how Doxygen draws semantic distinctions between certain synonymous Markdown constructs that Prettier currently normalizes.)

    ...as such, I can't currently use footnotes in any context where more than one definition is grouped together in sequence because my Prettier-on-save will induce pulldown-cmark to produce corrupted output.

  18. ShaunSHamilton commented on Apr 14, 2023

    @ShaunSHamilton

    This one stumped me for a long time. I really hope there will be a fix at some point.

    Currently, I have to:

    [^1]: Def for 1
    
    \
    
    [^2]: Def for 2

    Which would be fine, except it adds a lot of spacing in the resultant HTML

  19. added 7 commits that reference this issue on Jun 1, 2023
    3ce7fd7
    093f124
    e3dc6cf
    cffdb96
    c1ad321
    3a93292
    3d184fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions