// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see
text
, matching TipTap's taskItem shape. func wrapLeadingInlineInParagraph(li *html.Node) { var inline []*html.Node for c := li.FirstChild; c != nil; c = c.NextSibling { if c.Type == html.ElementNode && (c.Data == "ul" || c.Data == "ol") { break } inline = append(inline, c) } allWhitespace := true for _, c := range inline { if !isWhitespaceText(c) { allWhitespace = false break } } if len(inline) == 0 || allWhitespace { return } p := &html.Node{Type: html.ElementNode, Data: "p", DataAtom: atom.P} for _, c := range inline { li.RemoveChild(c) p.AppendChild(c) } li.InsertBefore(p, li.FirstChild) trimEdgeWhitespace(p) } // trimEdgeWhitespace trims leading/trailing whitespace from the first and last // text nodes of n so the wrapped paragraph doesn't keep goldmark's " " // spacing or trailing newline. func trimEdgeWhitespace(n *html.Node) { if first := n.FirstChild; first != nil && first.Type == html.TextNode { first.Data = strings.TrimLeft(first.Data, " \t\n\r") } if last := n.LastChild; last != nil && last.Type == html.TextNode { last.Data = strings.TrimRight(last.Data, " \t\n\r") } } func setAttribute(n *html.Node, key, val string) { for i, a := range n.Attr { if a.Key == key { n.Attr[i].Val = val return } } n.Attr = append(n.Attr, html.Attribute{Key: key, Val: val}) } func boolString(b bool) string { if b { return "true" } return "false" } func isWhitespaceText(n *html.Node) bool { return n.Type == html.TextNode && strings.TrimSpace(n.Data) == "" }