diff --git a/pkg/parser/asciidoc-grammar.peg b/pkg/parser/asciidoc-grammar.peg index 69e3fbe2..a2dea702 100644 --- a/pkg/parser/asciidoc-grammar.peg +++ b/pkg/parser/asciidoc-grammar.peg @@ -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 / (!"=" !"," !"]" .) { @@ -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{})) } diff --git a/pkg/parser/asciidoc_parser.go b/pkg/parser/asciidoc_parser.go index b23a9168..0dfce295 100644 --- a/pkg/parser/asciidoc_parser.go +++ b/pkg/parser/asciidoc_parser.go @@ -5334,7 +5334,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 948, col: 5, offset: 37246}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 948, col: 16, offset: 37257}, expr: &choiceExpr{ @@ -6015,7 +6015,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 952, col: 5, offset: 37440}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 952, col: 16, offset: 37451}, expr: &choiceExpr{ @@ -6599,7 +6599,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 955, col: 5, offset: 37600}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 955, col: 16, offset: 37611}, expr: &choiceExpr{ @@ -7083,7 +7083,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 957, col: 9, offset: 37728}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 957, col: 20, offset: 37739}, expr: &choiceExpr{ @@ -33467,7 +33467,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 948, col: 5, offset: 37246}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 948, col: 16, offset: 37257}, expr: &choiceExpr{ @@ -34148,7 +34148,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 952, col: 5, offset: 37440}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 952, col: 16, offset: 37451}, expr: &choiceExpr{ @@ -34732,7 +34732,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 955, col: 5, offset: 37600}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 955, col: 16, offset: 37611}, expr: &choiceExpr{ @@ -35216,7 +35216,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 957, col: 9, offset: 37728}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 957, col: 20, offset: 37739}, expr: &choiceExpr{ @@ -35996,7 +35996,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -36480,7 +36480,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -37243,7 +37243,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -37727,7 +37727,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -52656,7 +52656,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 948, col: 5, offset: 37246}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 948, col: 16, offset: 37257}, expr: &choiceExpr{ @@ -53337,7 +53337,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 952, col: 5, offset: 37440}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 952, col: 16, offset: 37451}, expr: &choiceExpr{ @@ -53921,7 +53921,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 955, col: 5, offset: 37600}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 955, col: 16, offset: 37611}, expr: &choiceExpr{ @@ -54405,7 +54405,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 957, col: 9, offset: 37728}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 957, col: 20, offset: 37739}, expr: &choiceExpr{ @@ -55185,7 +55185,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -55669,7 +55669,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -56432,7 +56432,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -56916,7 +56916,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -59399,7 +59399,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 948, col: 5, offset: 37246}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 948, col: 16, offset: 37257}, expr: &choiceExpr{ @@ -60080,7 +60080,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 952, col: 5, offset: 37440}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 952, col: 16, offset: 37451}, expr: &choiceExpr{ @@ -60664,7 +60664,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 955, col: 5, offset: 37600}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 955, col: 16, offset: 37611}, expr: &choiceExpr{ @@ -61148,7 +61148,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 957, col: 9, offset: 37728}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 957, col: 20, offset: 37739}, expr: &choiceExpr{ @@ -61928,7 +61928,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -62412,7 +62412,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -63175,7 +63175,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 921, col: 57, offset: 36205}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 921, col: 68, offset: 36216}, expr: &choiceExpr{ @@ -63659,7 +63659,7 @@ var g = &grammar{ }, &labeledExpr{ pos: position{line: 923, col: 9, offset: 36325}, - label: "otherAttrs", + label: "otherattrs", expr: &zeroOrMoreExpr{ pos: position{line: 923, col: 20, offset: 36336}, expr: &choiceExpr{ @@ -73773,14 +73773,14 @@ func (p *parser) callonDocumentElement195() (interface{}, error) { return p.cur.onDocumentElement195(stack["key"]) } -func (c *current) onDocumentElement53(alt, width, height, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, height, otherAttrs.([]interface{})) +func (c *current) onDocumentElement53(alt, width, height, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, height, otherattrs.([]interface{})) } func (p *parser) callonDocumentElement53() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onDocumentElement53(stack["alt"], stack["width"], stack["height"], stack["otherAttrs"]) + return p.cur.onDocumentElement53(stack["alt"], stack["width"], stack["height"], stack["otherattrs"]) } func (c *current) onDocumentElement245() (interface{}, error) { @@ -74137,14 +74137,14 @@ func (p *parser) callonDocumentElement357() (interface{}, error) { return p.cur.onDocumentElement357(stack["key"]) } -func (c *current) onDocumentElement238(alt, width, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, nil, otherAttrs.([]interface{})) +func (c *current) onDocumentElement238(alt, width, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, nil, otherattrs.([]interface{})) } func (p *parser) callonDocumentElement238() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onDocumentElement238(stack["alt"], stack["width"], stack["otherAttrs"]) + return p.cur.onDocumentElement238(stack["alt"], stack["width"], stack["otherattrs"]) } func (c *current) onDocumentElement407() (interface{}, error) { @@ -74450,14 +74450,14 @@ func (p *parser) callonDocumentElement496() (interface{}, error) { return p.cur.onDocumentElement496(stack["key"]) } -func (c *current) onDocumentElement400(alt, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, nil, nil, otherAttrs.([]interface{})) +func (c *current) onDocumentElement400(alt, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonDocumentElement400() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onDocumentElement400(stack["alt"], stack["otherAttrs"]) + return p.cur.onDocumentElement400(stack["alt"], stack["otherattrs"]) } func (c *current) onDocumentElement551() (interface{}, error) { @@ -74712,14 +74712,14 @@ func (p *parser) callonDocumentElement611() (interface{}, error) { return p.cur.onDocumentElement611(stack["key"]) } -func (c *current) onDocumentElement539(otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(nil, nil, nil, otherAttrs.([]interface{})) +func (c *current) onDocumentElement539(otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(nil, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonDocumentElement539() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onDocumentElement539(stack["otherAttrs"]) + return p.cur.onDocumentElement539(stack["otherattrs"]) } func (c *current) onDocumentElement657() (interface{}, error) { @@ -86840,14 +86840,14 @@ func (p *parser) callonTitleElement275() (interface{}, error) { return p.cur.onTitleElement275(stack["key"]) } -func (c *current) onTitleElement133(alt, width, height, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, height, otherAttrs.([]interface{})) +func (c *current) onTitleElement133(alt, width, height, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, height, otherattrs.([]interface{})) } func (p *parser) callonTitleElement133() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement133(stack["alt"], stack["width"], stack["height"], stack["otherAttrs"]) + return p.cur.onTitleElement133(stack["alt"], stack["width"], stack["height"], stack["otherattrs"]) } func (c *current) onTitleElement325() (interface{}, error) { @@ -87204,14 +87204,14 @@ func (p *parser) callonTitleElement437() (interface{}, error) { return p.cur.onTitleElement437(stack["key"]) } -func (c *current) onTitleElement318(alt, width, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, nil, otherAttrs.([]interface{})) +func (c *current) onTitleElement318(alt, width, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, nil, otherattrs.([]interface{})) } func (p *parser) callonTitleElement318() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement318(stack["alt"], stack["width"], stack["otherAttrs"]) + return p.cur.onTitleElement318(stack["alt"], stack["width"], stack["otherattrs"]) } func (c *current) onTitleElement487() (interface{}, error) { @@ -87517,14 +87517,14 @@ func (p *parser) callonTitleElement576() (interface{}, error) { return p.cur.onTitleElement576(stack["key"]) } -func (c *current) onTitleElement480(alt, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, nil, nil, otherAttrs.([]interface{})) +func (c *current) onTitleElement480(alt, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonTitleElement480() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement480(stack["alt"], stack["otherAttrs"]) + return p.cur.onTitleElement480(stack["alt"], stack["otherattrs"]) } func (c *current) onTitleElement631() (interface{}, error) { @@ -87779,14 +87779,14 @@ func (p *parser) callonTitleElement691() (interface{}, error) { return p.cur.onTitleElement691(stack["key"]) } -func (c *current) onTitleElement619(otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(nil, nil, nil, otherAttrs.([]interface{})) +func (c *current) onTitleElement619(otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(nil, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonTitleElement619() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement619(stack["otherAttrs"]) + return p.cur.onTitleElement619(stack["otherattrs"]) } func (c *current) onTitleElement103(path, inlineAttributes interface{}) (interface{}, error) { @@ -88161,14 +88161,14 @@ func (p *parser) callonTitleElement875() (interface{}, error) { return p.cur.onTitleElement875(stack["key"]) } -func (c *current) onTitleElement774(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onTitleElement774(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonTitleElement774() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement774(stack["text"], stack["otherAttrs"]) + return p.cur.onTitleElement774(stack["text"], stack["otherattrs"]) } func (c *current) onTitleElement930() (interface{}, error) { @@ -88423,14 +88423,14 @@ func (p *parser) callonTitleElement990() (interface{}, error) { return p.cur.onTitleElement990(stack["key"]) } -func (c *current) onTitleElement918(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onTitleElement918(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonTitleElement918() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement918(stack["otherAttrs"]) + return p.cur.onTitleElement918(stack["otherattrs"]) } func (c *current) onTitleElement737(url, inlineAttributes interface{}) (interface{}, error) { @@ -88805,14 +88805,14 @@ func (p *parser) callonTitleElement1169() (interface{}, error) { return p.cur.onTitleElement1169(stack["key"]) } -func (c *current) onTitleElement1068(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onTitleElement1068(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonTitleElement1068() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement1068(stack["text"], stack["otherAttrs"]) + return p.cur.onTitleElement1068(stack["text"], stack["otherattrs"]) } func (c *current) onTitleElement1224() (interface{}, error) { @@ -89067,14 +89067,14 @@ func (p *parser) callonTitleElement1284() (interface{}, error) { return p.cur.onTitleElement1284(stack["key"]) } -func (c *current) onTitleElement1212(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onTitleElement1212(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonTitleElement1212() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTitleElement1212(stack["otherAttrs"]) + return p.cur.onTitleElement1212(stack["otherattrs"]) } func (c *current) onTitleElement1033(url, inlineAttributes interface{}) (interface{}, error) { @@ -96124,14 +96124,14 @@ func (p *parser) callonInlineElement210() (interface{}, error) { return p.cur.onInlineElement210(stack["key"]) } -func (c *current) onInlineElement68(alt, width, height, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, height, otherAttrs.([]interface{})) +func (c *current) onInlineElement68(alt, width, height, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, height, otherattrs.([]interface{})) } func (p *parser) callonInlineElement68() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement68(stack["alt"], stack["width"], stack["height"], stack["otherAttrs"]) + return p.cur.onInlineElement68(stack["alt"], stack["width"], stack["height"], stack["otherattrs"]) } func (c *current) onInlineElement260() (interface{}, error) { @@ -96488,14 +96488,14 @@ func (p *parser) callonInlineElement372() (interface{}, error) { return p.cur.onInlineElement372(stack["key"]) } -func (c *current) onInlineElement253(alt, width, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElement253(alt, width, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElement253() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement253(stack["alt"], stack["width"], stack["otherAttrs"]) + return p.cur.onInlineElement253(stack["alt"], stack["width"], stack["otherattrs"]) } func (c *current) onInlineElement422() (interface{}, error) { @@ -96801,14 +96801,14 @@ func (p *parser) callonInlineElement511() (interface{}, error) { return p.cur.onInlineElement511(stack["key"]) } -func (c *current) onInlineElement415(alt, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, nil, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElement415(alt, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElement415() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement415(stack["alt"], stack["otherAttrs"]) + return p.cur.onInlineElement415(stack["alt"], stack["otherattrs"]) } func (c *current) onInlineElement566() (interface{}, error) { @@ -97063,14 +97063,14 @@ func (p *parser) callonInlineElement626() (interface{}, error) { return p.cur.onInlineElement626(stack["key"]) } -func (c *current) onInlineElement554(otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(nil, nil, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElement554(otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(nil, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElement554() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement554(stack["otherAttrs"]) + return p.cur.onInlineElement554(stack["otherattrs"]) } func (c *current) onInlineElement38(path, inlineAttributes interface{}) (interface{}, error) { @@ -97445,14 +97445,14 @@ func (p *parser) callonInlineElement810() (interface{}, error) { return p.cur.onInlineElement810(stack["key"]) } -func (c *current) onInlineElement709(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onInlineElement709(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonInlineElement709() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement709(stack["text"], stack["otherAttrs"]) + return p.cur.onInlineElement709(stack["text"], stack["otherattrs"]) } func (c *current) onInlineElement865() (interface{}, error) { @@ -97707,14 +97707,14 @@ func (p *parser) callonInlineElement925() (interface{}, error) { return p.cur.onInlineElement925(stack["key"]) } -func (c *current) onInlineElement853(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onInlineElement853(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElement853() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement853(stack["otherAttrs"]) + return p.cur.onInlineElement853(stack["otherattrs"]) } func (c *current) onInlineElement672(url, inlineAttributes interface{}) (interface{}, error) { @@ -98089,14 +98089,14 @@ func (p *parser) callonInlineElement1104() (interface{}, error) { return p.cur.onInlineElement1104(stack["key"]) } -func (c *current) onInlineElement1003(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onInlineElement1003(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonInlineElement1003() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement1003(stack["text"], stack["otherAttrs"]) + return p.cur.onInlineElement1003(stack["text"], stack["otherattrs"]) } func (c *current) onInlineElement1159() (interface{}, error) { @@ -98351,14 +98351,14 @@ func (p *parser) callonInlineElement1219() (interface{}, error) { return p.cur.onInlineElement1219(stack["key"]) } -func (c *current) onInlineElement1147(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onInlineElement1147(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElement1147() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElement1147(stack["otherAttrs"]) + return p.cur.onInlineElement1147(stack["otherattrs"]) } func (c *current) onInlineElement968(url, inlineAttributes interface{}) (interface{}, error) { @@ -99369,14 +99369,14 @@ func (p *parser) callonInlineElementWithoutSubtitution210() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution210(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution68(alt, width, height, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, height, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution68(alt, width, height, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, height, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution68() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution68(stack["alt"], stack["width"], stack["height"], stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution68(stack["alt"], stack["width"], stack["height"], stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution260() (interface{}, error) { @@ -99733,14 +99733,14 @@ func (p *parser) callonInlineElementWithoutSubtitution372() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution372(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution253(alt, width, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, width, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution253(alt, width, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, width, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution253() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution253(stack["alt"], stack["width"], stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution253(stack["alt"], stack["width"], stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution422() (interface{}, error) { @@ -100046,14 +100046,14 @@ func (p *parser) callonInlineElementWithoutSubtitution511() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution511(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution415(alt, otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(alt, nil, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution415(alt, otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(alt, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution415() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution415(stack["alt"], stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution415(stack["alt"], stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution566() (interface{}, error) { @@ -100308,14 +100308,14 @@ func (p *parser) callonInlineElementWithoutSubtitution626() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution626(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution554(otherAttrs interface{}) (interface{}, error) { - return types.NewImageAttributes(nil, nil, nil, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution554(otherattrs interface{}) (interface{}, error) { + return types.NewImageAttributes(nil, nil, nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution554() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution554(stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution554(stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution38(path, inlineAttributes interface{}) (interface{}, error) { @@ -100690,14 +100690,14 @@ func (p *parser) callonInlineElementWithoutSubtitution810() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution810(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution709(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution709(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution709() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution709(stack["text"], stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution709(stack["text"], stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution865() (interface{}, error) { @@ -100952,14 +100952,14 @@ func (p *parser) callonInlineElementWithoutSubtitution925() (interface{}, error) return p.cur.onInlineElementWithoutSubtitution925(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution853(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution853(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution853() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution853(stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution853(stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution672(url, inlineAttributes interface{}) (interface{}, error) { @@ -101334,14 +101334,14 @@ func (p *parser) callonInlineElementWithoutSubtitution1104() (interface{}, error return p.cur.onInlineElementWithoutSubtitution1104(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution1003(text, otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(text, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution1003(text, otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(text, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution1003() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution1003(stack["text"], stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution1003(stack["text"], stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution1159() (interface{}, error) { @@ -101596,14 +101596,14 @@ func (p *parser) callonInlineElementWithoutSubtitution1219() (interface{}, error return p.cur.onInlineElementWithoutSubtitution1219(stack["key"]) } -func (c *current) onInlineElementWithoutSubtitution1147(otherAttrs interface{}) (interface{}, error) { - return types.NewInlineLinkAttributes(nil, otherAttrs.([]interface{})) +func (c *current) onInlineElementWithoutSubtitution1147(otherattrs interface{}) (interface{}, error) { + return types.NewInlineLinkAttributes(nil, otherattrs.([]interface{})) } func (p *parser) callonInlineElementWithoutSubtitution1147() (interface{}, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onInlineElementWithoutSubtitution1147(stack["otherAttrs"]) + return p.cur.onInlineElementWithoutSubtitution1147(stack["otherattrs"]) } func (c *current) onInlineElementWithoutSubtitution968(url, inlineAttributes interface{}) (interface{}, error) { diff --git a/pkg/parser/cross_reference_test.go b/pkg/parser/cross_reference_test.go index 80ea1995..b164ec8b 100644 --- a/pkg/parser/cross_reference_test.go +++ b/pkg/parser/cross_reference_test.go @@ -20,7 +20,8 @@ with some content linked to <>!` ElementReferences: types.ElementReferences{ "thetitle": types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "thetitle", + types.AttrID: "thetitle", + types.AttrCustomID: true, }, Elements: types.InlineElements{ types.StringElement{ @@ -36,7 +37,8 @@ with some content linked to <>!` Level: 1, Title: types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "thetitle", + types.AttrID: "thetitle", + types.AttrCustomID: true, }, Elements: types.InlineElements{ types.StringElement{ @@ -80,7 +82,8 @@ with some content linked to <>!` ElementReferences: types.ElementReferences{ "thetitle": types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "thetitle", + types.AttrID: "thetitle", + types.AttrCustomID: true, }, Elements: types.InlineElements{ types.StringElement{ @@ -96,7 +99,8 @@ with some content linked to <>!` Level: 1, Title: types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "thetitle", + types.AttrID: "thetitle", + types.AttrCustomID: true, }, Elements: types.InlineElements{ types.StringElement{ diff --git a/pkg/parser/delimited_block_test.go b/pkg/parser/delimited_block_test.go index c7b58aa3..367fb972 100644 --- a/pkg/parser/delimited_block_test.go +++ b/pkg/parser/delimited_block_test.go @@ -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, diff --git a/pkg/parser/document_attributes_test.go b/pkg/parser/document_attributes_test.go index d8e02b1d..6ed23f18 100644 --- a/pkg/parser/document_attributes_test.go +++ b/pkg/parser/document_attributes_test.go @@ -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"}, @@ -53,7 +54,8 @@ Kismet Rainbow Chameleon ` Content: types.DocumentAttributes{ "doctitle": types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "_title", + types.AttrID: "title", + types.AttrCustomID: false, }, Elements: types.InlineElements{ types.StringElement{ @@ -79,7 +81,8 @@ Lazarus het_Draeke ` Content: types.DocumentAttributes{ "doctitle": types.SectionTitle{ Attributes: types.ElementAttributes{ - types.AttrID: "_title", + types.AttrID: "title", + types.AttrCustomID: false, }, Elements: types.InlineElements{ types.StringElement{ @@ -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{ @@ -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{ @@ -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{ @@ -178,7 +184,8 @@ Kismet Rainbow Chameleon ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke ; Lazarus het_Draeke

a section title, with bold content

@@ -65,6 +68,19 @@ var _ = Describe("sections", func() { verify(GinkgoT(), expectedResult, actualContent) }) + It("section level 1 with custom prefix id", func() { + actualContent := ` +:idprefix: id_ + +== a section title` + expectedResult := `
+

a section title

+
+
+
` + verify(GinkgoT(), expectedResult, actualContent) + }) + It("sections with same title", func() { actualContent := `== section 1 diff --git a/pkg/renderer/html5/table_of_contents.go b/pkg/renderer/html5/table_of_contents.go index 80fd64f2..505c0eb7 100644 --- a/pkg/renderer/html5/table_of_contents.go +++ b/pkg/renderer/html5/table_of_contents.go @@ -87,10 +87,7 @@ func renderTableOfContentsSections(ctx *renderer.Context, elements []interface{} return template.HTML(""), errors.Wrapf(err, "error while rendering table of content section") } } - var id string - if i, ok := section.Title.Attributes[types.AttrID].(string); ok { - id = i - } + id := generateID(ctx, section.Title.Attributes) renderedTitleStr := strings.TrimSpace(string(renderedTitle)) sections = append(sections, TableOfContentsSection{ Level: section.Level, diff --git a/pkg/renderer/html5/unordered_list.go b/pkg/renderer/html5/unordered_list.go index afe96e8f..9236ab7d 100644 --- a/pkg/renderer/html5/unordered_list.go +++ b/pkg/renderer/html5/unordered_list.go @@ -49,7 +49,7 @@ func renderUnorderedList(ctx *renderer.Context, l types.UnorderedList) ([]byte, Checklist bool Items []types.UnorderedListItem }{ - ID: l.Attributes.GetAsString(types.AttrID), + ID: generateID(ctx, l.Attributes), Title: getTitle(l.Attributes), Role: l.Attributes.GetAsString(types.AttrRole), Checklist: checkList, diff --git a/pkg/types/element_attributes.go b/pkg/types/element_attributes.go index eb3eb4be..02f92f32 100644 --- a/pkg/types/element_attributes.go +++ b/pkg/types/element_attributes.go @@ -15,6 +15,10 @@ import ( const ( // AttrID the key to retrieve the ID in the element attributes AttrID string = "id" + // AttrCustomID the key to retrieve the flag that indicates if the element ID is custom or generated + AttrCustomID string = "customID" + // AttrIDPrefix the key to retrieve the ID Prefix in the element attributes + AttrIDPrefix string = "idprefix" // AttrTitle the key to retrieve the title in the element attributes AttrTitle string = "title" // AttrRole the key to retrieve the role in the element attributes @@ -152,34 +156,41 @@ func NewSourceAttributes(language string) (ElementAttributes, error) { // WithAttributes set the attributes on the given elements if its type is supported, otherwise returns an error func WithAttributes(element interface{}, attributes []interface{}) (interface{}, error) { - attrbs := NewElementAttributes(attributes) + attrs := NewElementAttributes(attributes) + // look for custom ID + for attrb := range attrs { + if attrb == AttrID { + // mark custom_id flag to `true` + attrs[AttrCustomID] = true + } + } if element, ok := element.(ElementWithAttributes); ok { if len(attributes) > 0 { log.Debugf("setting %d attribute(s) on element of type %T", len(attributes), element) } - element.AddAttributes(attrbs) + element.AddAttributes(attrs) return element, nil } // special case for DelimitedBlock where we need a pointer receiver to modify the `Kind` field of the struct. if element, ok := element.(DelimitedBlock); ok { block := &element - block.AddAttributes(attrbs) + block.AddAttributes(attrs) return element, nil } // special case for any ListItem where we need a pointer receiver to modify the `Kind` field of the struct. if element, ok := element.(OrderedListItem); ok { item := &element - item.AddAttributes(attrbs) + item.AddAttributes(attrs) return element, nil } if element, ok := element.(UnorderedListItem); ok { item := &element - item.AddAttributes(attrbs) + item.AddAttributes(attrs) return element, nil } if element, ok := element.(LabeledListItem); ok { item := &element - item.AddAttributes(attrbs) + item.AddAttributes(attrs) return element, nil } @@ -204,6 +215,17 @@ func (a ElementAttributes) GetAsString(key string) string { return "" } +// GetAsBool returns the value of the key as a bool, or `false` if the key did not exist +// or if its value was not a bool +func (a ElementAttributes) GetAsBool(key string) bool { + if v, ok := a[key]; ok { + if v, ok := v.(bool); ok { + return v + } + } + return false +} + // AddAll adds all the given attributes to the current ones func (a ElementAttributes) AddAll(attributes ElementAttributes) { for k, v := range attributes { @@ -213,7 +235,7 @@ func (a ElementAttributes) AddAll(attributes ElementAttributes) { // NewElementAttributes retrieves the ElementID, ElementTitle and ElementInlineLink from the given slice of attributes func NewElementAttributes(attributes []interface{}, extras ...ElementAttributes) ElementAttributes { - attrbs := ElementAttributes{} + attrs := ElementAttributes{} for _, attrb := range attributes { log.Debugf("processing attribute %[1]v (%[1]T)", attrb) switch attrb := attrb.(type) { @@ -223,17 +245,17 @@ func NewElementAttributes(attributes []interface{}, extras ...ElementAttributes) // which is used to ensure that a `LiteralAttribute` element is set amongst the attributes r := NewElementAttributes(attrb) for k, v := range r { - attrbs[k] = v + attrs[k] = v } case ElementAttributes: // TODO: warn if attribute already exists and is overridden for k, v := range attrb { - attrbs[k] = v + attrs[k] = v } case map[string]interface{}: // TODO: warn if attribute already exists and is overridden for k, v := range attrb { - attrbs[k] = v + attrs[k] = v } case nil: // ignore @@ -244,8 +266,8 @@ func NewElementAttributes(attributes []interface{}, extras ...ElementAttributes) for _, extra := range extras { for k, v := range extra { // no warning on override here - attrbs[k] = v + attrs[k] = v } } - return attrbs + return attrs } diff --git a/pkg/types/grammar_types.go b/pkg/types/grammar_types.go index f2b6d56c..228d03ec 100644 --- a/pkg/types/grammar_types.go +++ b/pkg/types/grammar_types.go @@ -549,6 +549,7 @@ func NewSection(level int, sectionTitle SectionTitle, blocks []interface{}) (Sec // AddAttributes adds all given attributes to the current set of attribute of the element func (s Section) AddAttributes(attributes ElementAttributes) { + log.Debugf("adding attributes to section: %v", attributes) s.Title.AddAttributes(attributes) } @@ -594,13 +595,16 @@ func NewSectionTitle(elements InlineElements, ids []interface{}) (SectionTitle, attributes.AddAll(id) } } + attributes[AttrCustomID] = true // make a default id from the sectionTitle's inline content if _, found := attributes[AttrID]; !found { + log.Debugf("did not find ID attribute for section with elements %v", elements) replacement, err := replaceNonAlphanumerics(elements, "_") if err != nil { return SectionTitle{}, errors.Wrapf(err, "unable to generate default ID while instanciating a new SectionTitle element") } attributes[AttrID] = replacement + attributes[AttrCustomID] = false } sectionTitle := SectionTitle{ Attributes: attributes, @@ -615,6 +619,13 @@ func NewSectionTitle(elements InlineElements, ids []interface{}) (SectionTitle, // AddAttributes adds all given attributes to the current set of attribute of the element func (st SectionTitle) AddAttributes(attributes ElementAttributes) { st.Attributes.AddAll(attributes) + // look for custom ID + for attr := range attributes { + if attr == AttrID { + // mark custom_id flag to `true` + st.Attributes[AttrCustomID] = true + } + } } // Accept implements Visitable#Accept(Visitor) @@ -1826,7 +1837,7 @@ func NewInlineImage(path string, attributes ElementAttributes) (InlineImage, err } // NewImageAttributes returns a map of image attributes, some of which have implicit keys (`alt`, `width` and `height`) -func NewImageAttributes(alt, width, height interface{}, otherAttrs []interface{}) (ElementAttributes, error) { +func NewImageAttributes(alt, width, height interface{}, otherattrs []interface{}) (ElementAttributes, error) { result := ElementAttributes{} var altStr, widthStr, heightStr string if alt, ok := alt.(string); ok { @@ -1841,10 +1852,14 @@ func NewImageAttributes(alt, width, height interface{}, otherAttrs []interface{} result[AttrImageAlt] = altStr result[AttrImageWidth] = widthStr result[AttrImageHeight] = heightStr - for _, otherAttr := range otherAttrs { + for _, otherAttr := range otherattrs { if otherAttr, ok := otherAttr.(ElementAttributes); ok { for k, v := range otherAttr { result[k] = v + if k == AttrID { + // mark custom_id flag to `true` + result[AttrCustomID] = true + } } } } @@ -2298,14 +2313,14 @@ func (l InlineLink) Text() string { const AttrInlineLinkText string = "text" // NewInlineLinkAttributes returns a map of image attributes, some of which have implicit keys (`text`) -func NewInlineLinkAttributes(text interface{}, otherAttrs []interface{}) (ElementAttributes, error) { +func NewInlineLinkAttributes(text interface{}, otherattrs []interface{}) (ElementAttributes, error) { result := ElementAttributes{} var textStr string if text, ok := text.(string); ok { textStr = apply(text, strings.TrimSpace) } result[AttrInlineLinkText] = textStr - for _, otherAttr := range otherAttrs { + for _, otherAttr := range otherattrs { if otherAttr, ok := otherAttr.(ElementAttributes); ok { for k, v := range otherAttr { result[k] = v diff --git a/pkg/types/grammar_types_utils_test.go b/pkg/types/grammar_types_utils_test.go index 6b78d84c..707bc08d 100644 --- a/pkg/types/grammar_types_utils_test.go +++ b/pkg/types/grammar_types_utils_test.go @@ -44,35 +44,35 @@ var _ = Describe("normalizing string", func() { source := InlineElements{ StringElement{Content: "hello"}, } - verify(GinkgoT(), "_hello", source) + verify(GinkgoT(), "hello", source) }) It("héllo with an accent", func() { source := InlineElements{ StringElement{Content: " héllo 1.2 and 3 Spaces"}, } - verify(GinkgoT(), "_héllo_1_2_and_3_spaces", source) + verify(GinkgoT(), "héllo_1_2_and_3_spaces", source) }) It("a an accent and a swedish character", func() { source := InlineElements{ StringElement{Content: `A à ⌘`}, } - verify(GinkgoT(), `_a_à`, source) + verify(GinkgoT(), `a_à`, source) }) It("AŁA", func() { source := InlineElements{ StringElement{Content: `AŁA 0.1 ?`}, } - verify(GinkgoT(), `_ała_0_1`, source) + verify(GinkgoT(), `ała_0_1`, source) }) It("it's 2 spaces, here !", func() { source := InlineElements{ StringElement{Content: `it's 2 spaces, here !`}, } - verify(GinkgoT(), `_it_s_2_spaces_here`, source) + verify(GinkgoT(), `it_s_2_spaces_here`, source) }) It("content with markup", func() { @@ -86,7 +86,7 @@ var _ = Describe("normalizing string", func() { }, }, } - verify(GinkgoT(), `_a_section_title_with_bold_content`, source) + verify(GinkgoT(), `a_section_title_with_bold_content`, source) }) }) diff --git a/pkg/types/non_alphanumerics_replacement.go b/pkg/types/non_alphanumerics_replacement.go index c9004fbc..4b88bc91 100644 --- a/pkg/types/non_alphanumerics_replacement.go +++ b/pkg/types/non_alphanumerics_replacement.go @@ -67,7 +67,9 @@ func newreplaceNonAlphanumericsVisitor() replaceNonAlphanumericsVisitor { func (v *replaceNonAlphanumericsVisitor) Visit(element Visitable) error { // log.Debugf("visiting element of type '%T'", element) if element, ok := element.(StringElement); ok { - v.buf.WriteString("_") + if v.buf.Len() > 0 { + v.buf.WriteString("_") + } normalized, err := v.normalize(element.Content) if err != nil { return errors.Wrapf(err, "error while normalizing String Element")