diff options
author | Jonathan Tran <jon@allspice.io> | 2023-06-13 02:44:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 14:44:47 +0800 |
commit | f62cd2f4738c1b3cf7c31e8b98702a709bdd4072 (patch) | |
tree | 17dac9b30739851d0a90b848f79f726c05659979 /modules/markup/markdown/goldmark.go | |
parent | 419804fd4d5cb655a51f245010b8eb1163b26bc2 (diff) | |
download | gitea-f62cd2f4738c1b3cf7c31e8b98702a709bdd4072.tar.gz gitea-f62cd2f4738c1b3cf7c31e8b98702a709bdd4072.zip |
Fix task list checkbox toggle to work with YAML front matter (#25184)
Fixes #25160.
`data-source-position` of checkboxes in a task list was incorrect
whenever there was YAML front matter. This would result in issue content
or PR descriptions getting corrupted with random `x` or space characters
when a user checked or unchecked a task.
Diffstat (limited to 'modules/markup/markdown/goldmark.go')
-rw-r--r-- | modules/markup/markdown/goldmark.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index f03a780900..ff4e6b1bd0 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -177,6 +177,11 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa newChild := NewTaskCheckBoxListItem(listItem) newChild.IsChecked = taskCheckBox.IsChecked newChild.SetAttributeString("class", []byte("task-list-item")) + segments := newChild.FirstChild().Lines() + if segments.Len() > 0 { + segment := segments.At(0) + newChild.SourcePosition = rc.metaLength + segment.Start + } v.AppendChild(v, newChild) } } @@ -457,12 +462,7 @@ func (r *HTMLRenderer) renderTaskCheckBoxListItem(w util.BufWriter, source []byt } else { _, _ = w.WriteString("<li>") } - _, _ = w.WriteString(`<input type="checkbox" disabled=""`) - segments := node.FirstChild().Lines() - if segments.Len() > 0 { - segment := segments.At(0) - _, _ = w.WriteString(fmt.Sprintf(` data-source-position="%d"`, segment.Start)) - } + fmt.Fprintf(w, `<input type="checkbox" disabled="" data-source-position="%d"`, n.SourcePosition) if n.IsChecked { _, _ = w.WriteString(` checked=""`) } |