Skip to content

Commit

Permalink
Render task list item inside label for correct accessibility
Browse files Browse the repository at this point in the history
Fixes #3303
  • Loading branch information
Daniel Karlsson authored and bep committed Aug 9, 2017
1 parent 0abdeee commit c8257f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions helpers/content_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ func (r *HugoHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {

switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
text = append([]byte(`<input type="checkbox" disabled class="task-list-item">`), text[3:]...)
text = append([]byte(`<label><input type="checkbox" disabled class="task-list-item">`), text[3:]...)
text = append(text, []byte(`</label>`)...)

case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
text = append([]byte(`<input type="checkbox" checked disabled class="task-list-item">`), text[3:]...)
text = append([]byte(`<label><input type="checkbox" checked disabled class="task-list-item">`), text[3:]...)
text = append(text, []byte(`</label>`)...)
}

r.Renderer.ListItem(out, text, flags)
Expand Down
8 changes: 4 additions & 4 deletions helpers/content_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ END
`, true, `<p>TODO:</p>
<ul class="task-list">
<li><input type="checkbox" checked disabled class="task-list-item"> On1</li>
<li><input type="checkbox" checked disabled class="task-list-item"> On2</li>
<li><input type="checkbox" disabled class="task-list-item"> Off</li>
<li><label><input type="checkbox" checked disabled class="task-list-item"> On1</label></li>
<li><label><input type="checkbox" checked disabled class="task-list-item"> On2</label></li>
<li><label><input type="checkbox" disabled class="task-list-item"> Off</label></li>
</ul>
<p>END</p>
Expand All @@ -122,7 +122,7 @@ END
{`* [ ] Off
END`, true, `<ul class="task-list">
<li><input type="checkbox" disabled class="task-list-item"> Off</li>
<li><label><input type="checkbox" disabled class="task-list-item"> Off</label></li>
</ul>
<p>END</p>
Expand Down

0 comments on commit c8257f8

Please sign in to comment.