Skip to content

Commit

Permalink
feat(parser/renderer): support cross-references with Element ID (#47)
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Jan 7, 2018
1 parent af70612 commit 65f9c9c
Show file tree
Hide file tree
Showing 26 changed files with 2,095 additions and 1,680 deletions.
28 changes: 22 additions & 6 deletions parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ InlineContent <- !BlockDelimiter elements:(WS* InlineElement WS*)+ &EOL { // nee
return types.NewInlineContent(elements.([]interface{}))
}

InlineElement <- Passthrough / InlineImage / QuotedText / ExternalLink / DocumentAttributeSubstitution / Characters
InlineElement <- CrossReference / Passthrough / InlineImage / QuotedText / ExternalLink / DocumentAttributeSubstitution / Characters

// ----------------------------------------------------------------------------
// Quoted Texts (bold, italic and monospace) including substitution prevention
Expand Down Expand Up @@ -328,14 +328,14 @@ QuotedTextContent <- QuotedTextContentElement (WS+ QuotedTextContentElement)*
QuotedTextContentElement <- QuotedText / QuotedTextCharacters / CharactersWithQuotePunctuation // word with quote punctuation is only accepted if nothing matched before, so we have a chance to stop

QuotedTextCharacters <- (!NEWLINE !WS !"*" !"_" !"`" .)+ // cannot have "*", "_" or "`" within

CharactersWithQuotePunctuation <- (!NEWLINE !WS .)+ { // can have "*", "_" or "`" within, maybe because the user inserted another quote, or made an error (extra or missing space, for example)
return c.text, nil
}

// make sure unbalanced punctuation for quoted text is treated accordingly
UnbalancedQuotePunctuation <- "*" / "_" / "`"


// ------------------------------------------
// Passthrough
// ------------------------------------------
Expand All @@ -361,6 +361,13 @@ PassthroughWithQuotedText <- "pass:q[" content:(QuotedText / PassthroughMacroCha

PassthroughMacroCharacter <- (!"]" .)

// ------------------------------------------
// Cross References
// ------------------------------------------
CrossReference <- "<<" id:(ID) ">>" {
return types.NewCrossReference(id.(string))
}

// ------------------------------------------
// Links
// ------------------------------------------
Expand Down Expand Up @@ -448,15 +455,20 @@ ParagraphWithLiteralAttribute <- "[literal]" WS* NEWLINE content:(LiteralBlockCo
// ------------------------------------------
// Element Attributes
// ------------------------------------------
ElementAttribute <- meta:(ElementLink / ElementID / ElementTitle)
ElementAttribute <- ElementLink / ElementID / ElementTitle / InvalidElementAttribute

// a link attached to an element, such as a BlockImage
ElementLink <- "[" WS* "link" WS* "=" WS* path:URL WS* "]" EOL {
ElementLink <- "[link=" WS* path:URL WS* "]" EOL {
return types.NewElementLink(path.(string))
}

ElementID <- ElementIDNormal / ElementIDShortHand

// an id attached to an element, such as a BlockImage
ElementID <- "[" WS* "#" id:(ID) WS* "]" EOL {
ElementIDNormal <- "[[" id:(ID) "]]" EOL {
return types.NewElementID(id.(string))
}
ElementIDShortHand <- "[#" id:(ID) "]" EOL {
return types.NewElementID(id.(string))
}

Expand All @@ -466,6 +478,10 @@ ElementTitle <- "." !"." !WS title:(!NEWLINE .)+ EOL {
return types.NewElementTitle(title.([]interface{}))
}

InvalidElementAttribute <- "[" WS+ content:(!"]" .)* "]" {
return types.NewInvalidElementAttribute(c.text)
}

// ------------------------------------------
// BlankLine
// ------------------------------------------
Expand All @@ -485,7 +501,7 @@ URL <- (!NEWLINE !WS !"[" !"]" .)+ {
return string(c.text), nil
}

ID <- (!NEWLINE !WS !"[" !"]" .)+ {
ID <- (!NEWLINE !WS !"[" !"]" !"<<" !">>".)+ {
return string(c.text), nil
}

Expand Down
Loading

0 comments on commit 65f9c9c

Please sign in to comment.