diff options
-rw-r--r-- | helpers/content_renderer.go | 6 | ||||
-rw-r--r-- | helpers/content_renderer_test.go | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/helpers/content_renderer.go b/helpers/content_renderer.go index f0d8cda12..376351f7a 100644 --- a/helpers/content_renderer.go +++ b/helpers/content_renderer.go @@ -101,10 +101,14 @@ func (r *HugoHTMLRenderer) List(out *bytes.Buffer, text func() bool, flags int) if out.Len() > marker { list := out.Bytes()[marker:] if bytes.Contains(list, []byte("task-list-item")) { + // Find the index of the first >, it might be 3 or 4 depending on whether + // there is a new line at the start, but this is safer than just hardcoding it. + closingBracketIndex := bytes.Index(list, []byte(">")) // Rewrite the buffer from the marker out.Truncate(marker) + // Safely assuming closingBracketIndex won't be -1 since there is a list // May be either dl, ul or ol - list := append(list[:4], append([]byte(` class="task-list"`), list[4:]...)...) + list := append(list[:closingBracketIndex], append([]byte(` class="task-list"`), list[closingBracketIndex:]...)...) out.Write(list) } } diff --git a/helpers/content_renderer_test.go b/helpers/content_renderer_test.go index 2f155de07..63e681d97 100644 --- a/helpers/content_renderer_test.go +++ b/helpers/content_renderer_test.go @@ -119,6 +119,14 @@ END <li>[x] On1</li> </ul> `}, + {`* [ ] Off + +END`, true, `<ul class="task-list"> +<li><input type="checkbox" disabled class="task-list-item"> Off</li> +</ul> + +<p>END</p> +`}, } { blackFridayConfig := c.NewBlackfriday() blackFridayConfig.TaskLists = this.taskListEnabled |