Skip to content

Commit

Permalink
feat(parser/renderer): support inline footnotes (#183)
Browse files Browse the repository at this point in the history
support for `footnote` and `footnoteref` macros
also, rename `Content` to `Elements` in `Section` type.

Fixes #139

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Sep 15, 2018
1 parent e34547c commit 71300a7
Show file tree
Hide file tree
Showing 28 changed files with 7,343 additions and 5,833 deletions.
26 changes: 23 additions & 3 deletions pkg/parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ TitleElements <- elements:(!NEWLINE WS* !InlineElementID TitleElement WS*)+ { //
return types.NewInlineElements(elements.([]interface{}))
}

TitleElement <- element:(CrossReference / Passthrough / InlineImage / QuotedText / Link / DocumentAttributeSubstitution / Word / Parenthesis) {
TitleElement <- element:(CrossReference / Passthrough / InlineImage / QuotedText / Link / DocumentAttributeSubstitution / InlineFootnote / Word / Parenthesis) {
return element, nil
}

Expand Down Expand Up @@ -527,7 +527,7 @@ InlineElements <-
return types.NewInlineElements(elements.([]interface{}))
}

InlineElement <- element:(QuotedText / CrossReference / Passthrough / InlineImage / Link / DocumentAttributeSubstitution / Word / Parenthesis) {
InlineElement <- element:(QuotedText / CrossReference / Passthrough / InlineImage / Link / DocumentAttributeSubstitution / InlineFootnote / Word / Parenthesis) {
return element, nil
}

Expand Down Expand Up @@ -734,7 +734,27 @@ ImageAttribute <- (!"," !"=" !"]" .)+ { // attribute is followed by "," or "]" (
}

// ------------------------------------------------------------------------------------
// Delimited Blocks (http://asciidoctor.org/docs/user-manual/#built-in-blocks-summary)
// Inline foot notes
// ------------------------------------------------------------------------------------
InlineFootnote <- "footnote:[" content:(FootnoteContent) "]" {
return types.NewFootnote("", content.(types.InlineElements))
} / "footnoteref:[" ref:(FootnoteRef) "," content:(FootnoteContent) "]" {
return types.NewFootnote(ref.(string), content.(types.InlineElements))
} / "footnoteref:[" ref:(FootnoteRef) "]" {
return types.NewFootnote(ref.(string), types.InlineElements{}) // foot note referring to another note
}

FootnoteRef <- (!"," !"]" !EOL .)* { // footnote ID not may span multiple lines
return string(c.text), nil
}

FootnoteContent <- elements:(!"]" !EOL WS* !InlineElementID InlineElement WS*)+ { // footnote content may span multiple lines
return types.NewInlineElements(elements.([]interface{}))
}


// ------------------------------------------------------------------------------------
// Delimited Blocks
// ------------------------------------------------------------------------------------
DelimitedBlock <- FencedBlock / ListingBlock / ExampleBlock
/ CommentBlock / VerseBlock / QuoteBlock
Expand Down
Loading

0 comments on commit 71300a7

Please sign in to comment.