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(renderer): support title on labeled lists #278

Merged
merged 1 commit into from
Jan 20, 2019
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
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