Skip to content

Commit

Permalink
feat(renderer): support title on labeled lists
Browse files Browse the repository at this point in the history
fixes bytesparadise#267

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jan 20, 2019
1 parent 4e1c15d commit 14c27e4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
48 changes: 48 additions & 0 deletions pkg/parser/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,54 @@ another fenced block
}
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("DocumentBlock"))
})

It("labeled list with title", func() {
actualContent := `.Labeled, single-line
first term:: definition of the first term
second term:: definition of the second term`
expectedResult := types.LabeledList{
Attributes: types.ElementAttributes{
types.AttrTitle: "Labeled, single-line",
},
Items: []types.LabeledListItem{
{
Attributes: types.ElementAttributes{},
Level: 1,
Term: "first term",
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{
Content: "definition of the first term",
},
},
},
},
},
},
{
Attributes: types.ElementAttributes{},
Level: 1,
Term: "second term",
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{
Content: "definition of the second term",
},
},
},
},
},
},
},
}
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("DocumentBlock"))
})
})

Context("unordered list", func() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/renderer/html5/labeled_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var horizontalLabeledListTmpl texttemplate.Template
func init() {
defaultLabeledListTmpl = newTextTemplate("labeled list with default layout",
`{{ $ctx := .Context }}{{ with .Data }}<div{{ if .ID }} id="{{ .ID }}"{{ end }} class="dlist{{ if .Role }} {{ .Role }}{{ end }}">
<dl>
{{ if .Title }}<div class="title">{{ .Title }}</div>
{{ end }}<dl>
{{ $items := .Items }}{{ range $itemIndex, $item := $items }}<dt class="hdlist1">{{ $item.Term }}</dt>{{ if $item.Elements }}
<dd>
{{ renderElements $ctx $item.Elements | printf "%s" }}
Expand Down
21 changes: 21 additions & 0 deletions pkg/renderer/html5/labeled_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on 2 lines.
item 3:: description 3
on 2 lines, too.`
expectedResult := `<div id="listID" class="dlist myrole">
<div class="title">mytitle</div>
<dl>
<dt class="hdlist1">item 1</dt>
<dd>
Expand Down Expand Up @@ -144,6 +145,26 @@ item 2:: something simple`
<p>something simple</p>
</dd>
</dl>
</div>`
verify(GinkgoT(), expectedResult, actualContent)
})

It("labeled list with title", func() {
actualContent := `.Labeled, single-line
first term:: definition of the first term
second term:: definition of the second term`
expectedResult := `<div class="dlist">
<div class="title">Labeled, single-line</div>
<dl>
<dt class="hdlist1">first term</dt>
<dd>
<p>definition of the first term</p>
</dd>
<dt class="hdlist1">second term</dt>
<dd>
<p>definition of the second term</p>
</dd>
</dl>
</div>`
verify(GinkgoT(), expectedResult, actualContent)
})
Expand Down

0 comments on commit 14c27e4

Please sign in to comment.