Skip to content

Commit

Permalink
feat(parser/renderer): support element ID prefix
Browse files Browse the repository at this point in the history
Fixes #300

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Feb 24, 2019
1 parent 76ea3f7 commit d2300d8
Show file tree
Hide file tree
Showing 28 changed files with 507 additions and 287 deletions.
24 changes: 12 additions & 12 deletions pkg/parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,10 @@ RelativeLinkURL <- URL_SCHEME? URL {
return string(c.text), nil
}

LinkAttributes <- "[" text:(LinkTextAttribute) ","? WS* otherAttrs:(GenericAttribute)* "]" {
return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{}))
} / "[" otherAttrs:(GenericAttribute)* "]" {
return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{}))
LinkAttributes <- "[" text:(LinkTextAttribute) ","? WS* otherattrs:(GenericAttribute)* "]" {
return types.NewInlineLinkAttributes(text, otherattrs.([]interface{}))
} / "[" otherattrs:(GenericAttribute)* "]" {
return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{}))
}

LinkTextAttribute <- (Alphanums / Spaces / (!"=" !"," !"]" .) {
Expand All @@ -945,17 +945,17 @@ InlineImage <- "image:" !":" path:(URL) inlineAttributes:(ImageAttributes) {
ImageAttributes <- "[" alt:(ImageAttribute) ","
width:(ImageAttribute) ","
height:(ImageAttribute) ","?
otherAttrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, width, height, otherAttrs.([]interface{}))
otherattrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, width, height, otherattrs.([]interface{}))
} / "[" alt:(ImageAttribute) ","
width:(ImageAttribute) ","?
otherAttrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, width, nil, otherAttrs.([]interface{}))
otherattrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, width, nil, otherattrs.([]interface{}))
} / "[" alt:(ImageAttribute) ","?
otherAttrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, nil, nil, otherAttrs.([]interface{}))
} / "[" otherAttrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(nil, nil, nil, otherAttrs.([]interface{}))
otherattrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(alt, nil, nil, otherattrs.([]interface{}))
} / "[" otherattrs:(GenericAttribute)* "]" {
return types.NewImageAttributes(nil, nil, nil, otherattrs.([]interface{}))
}


Expand Down
224 changes: 112 additions & 112 deletions pkg/parser/asciidoc_parser.go

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions pkg/parser/cross_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ with some content linked to <<thetitle>>!`
ElementReferences: types.ElementReferences{
"thetitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
types.AttrID: "thetitle",
types.AttrCustomID: true,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -36,7 +37,8 @@ with some content linked to <<thetitle>>!`
Level: 1,
Title: types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
types.AttrID: "thetitle",
types.AttrCustomID: true,
},
Elements: types.InlineElements{
types.StringElement{
Expand Down Expand Up @@ -80,7 +82,8 @@ with some content linked to <<thetitle,a label to the title>>!`
ElementReferences: types.ElementReferences{
"thetitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
types.AttrID: "thetitle",
types.AttrCustomID: true,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -96,7 +99,8 @@ with some content linked to <<thetitle,a label to the title>>!`
Level: 1,
Title: types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
types.AttrID: "thetitle",
types.AttrCustomID: true,
},
Elements: types.InlineElements{
types.StringElement{
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/delimited_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ end
types.AttrKind: types.Source,
types.AttrLanguage: "ruby",
types.AttrID: "id-for-source-block",
types.AttrCustomID: true,
types.AttrTitle: "app.rb",
},
Kind: types.Source,
Expand Down
68 changes: 45 additions & 23 deletions pkg/parser/document_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ This journey begins on a bleary Monday morning.`
Attributes: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_the_dangerous_and_thrilling_documentation_chronicles",
types.AttrID: "the_dangerous_and_thrilling_documentation_chronicles",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{Content: "The Dangerous and Thrilling Documentation Chronicles"},
Expand Down Expand Up @@ -53,7 +54,8 @@ Kismet Rainbow Chameleon <[email protected]>`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -79,7 +81,8 @@ Lazarus het_Draeke <[email protected]>`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -104,7 +107,8 @@ Kismet Chameleon`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -128,7 +132,8 @@ Chameleon`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -151,7 +156,8 @@ Chameleon`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -178,7 +184,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand Down Expand Up @@ -214,7 +221,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand Down Expand Up @@ -242,7 +250,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -269,7 +278,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -295,7 +305,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -321,7 +332,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -347,7 +359,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -373,7 +386,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -399,7 +413,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -425,7 +440,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -451,7 +467,8 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand All @@ -477,7 +494,8 @@ v1.0:`
Content: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrID: "title",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{
Expand Down Expand Up @@ -719,7 +737,8 @@ This journey begins on a bleary Monday morning.`
Attributes: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_the_dangerous_and_thrilling_documentation_chronicles",
types.AttrID: "the_dangerous_and_thrilling_documentation_chronicles",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{Content: "The Dangerous and Thrilling Documentation Chronicles"},
Expand Down Expand Up @@ -772,17 +791,19 @@ a paragraph with *bold content*`
Attributes: types.DocumentAttributes{
"doctitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_a_header",
types.AttrID: "a_header",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{Content: "a header"},
},
},
},
ElementReferences: types.ElementReferences{
"_section_1": types.SectionTitle{
"section_1": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_section_1",
types.AttrID: "section_1",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{Content: "section 1"},
Expand All @@ -796,7 +817,8 @@ a paragraph with *bold content*`
Level: 1,
Title: types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_section_1",
types.AttrID: "section_1",
types.AttrCustomID: false,
},
Elements: types.InlineElements{
types.StringElement{Content: "section 1"},
Expand Down
6 changes: 4 additions & 2 deletions pkg/parser/element_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ a paragraph`
a paragraph`
expectedResult := types.Paragraph{
Attributes: types.ElementAttributes{
types.AttrID: "img-foobar",
types.AttrID: "img-foobar",
types.AttrCustomID: true,
},
Lines: []types.InlineElements{
{
Expand All @@ -119,7 +120,8 @@ a paragraph`
a paragraph`
expectedResult := types.Paragraph{
Attributes: types.ElementAttributes{
types.AttrID: "img-foobar",
types.AttrID: "img-foobar",
types.AttrCustomID: true,
},
Lines: []types.InlineElements{
{
Expand Down
Loading

0 comments on commit d2300d8

Please sign in to comment.