Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser/renderer): support cross-references with Element ID #47

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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