Skip to content

Commit

Permalink
feat(parser): support relative links (#65)
Browse files Browse the repository at this point in the history
also: rename `ExternalLink` to `Link`.

Fixes #56

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Feb 18, 2018
1 parent ed0ed53 commit 5e47b65
Show file tree
Hide file tree
Showing 7 changed files with 913 additions and 714 deletions.
15 changes: 12 additions & 3 deletions parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ InlineContent <- !BlockDelimiter elements:(WS* InlineElement WS*)+ &EOL { // nee
return types.NewInlineContent(elements.([]interface{}))
}

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

// ----------------------------------------------------------------------------
// Quoted Texts (bold, italic and monospace) including substitution prevention
Expand Down Expand Up @@ -443,11 +443,20 @@ CrossReference <- "<<" id:(ID) ">>" {
// ------------------------------------------
// Links
// ------------------------------------------
Link <- RelativeLink / ExternalLink

ExternalLink <- url:(URL_SCHEME URL) text:("[" (URL_TEXT)* "]")? {
if text != nil {
return types.NewExternalLink(url.([]interface{}), text.([]interface{}))
return types.NewLink(url.([]interface{}), text.([]interface{}))
}
return types.NewLink(url.([]interface{}), nil)
}

RelativeLink <- "link:" url:(URL_SCHEME? URL) text:("[" (URL_TEXT)* "]") {
if text != nil {
return types.NewLink(url.([]interface{}), text.([]interface{}))
}
return types.NewExternalLink(url.([]interface{}), nil)
return types.NewLink(url.([]interface{}), nil)
}

// ------------------------------------------
Expand Down
Loading

0 comments on commit 5e47b65

Please sign in to comment.