mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
renderer: HTML-escape admonition title and guard against empty attachments
mkDocsAdmonition: escape the admonition title with html.EscapeString before inserting it into the Confluence storage format XML. An unescaped title containing '<', '>', '&', or '"' would break the XML structure. image: add a len(attachments)==0 guard before accessing attachments[0] in the local-attachment code path. ResolveLocalAttachments always returns either an error or the requested attachments, so this is currently unreachable, but the explicit check prevents a future silent panic if the function's behaviour changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
2b62ffd822
commit
17436efd17
@ -2,6 +2,7 @@ package renderer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -143,6 +144,9 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
if len(attachments) == 0 {
|
||||||
|
return ast.WalkStop, fmt.Errorf("no attachment resolved for %q", string(n.Destination))
|
||||||
|
}
|
||||||
|
|
||||||
r.Attachments.Attach(attachments[0])
|
r.Attachments.Attach(attachments[0])
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package renderer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
stdhtml "html"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
parser "github.com/stefanfritsch/goldmark-admonitions"
|
parser "github.com/stefanfritsch/goldmark-admonitions"
|
||||||
@ -81,7 +82,7 @@ func (r *ConfluenceMkDocsAdmonitionRenderer) renderMkDocsAdmonition(writer util.
|
|||||||
|
|
||||||
title, _ := strconv.Unquote(string(n.Title))
|
title, _ := strconv.Unquote(string(n.Title))
|
||||||
if title != "" {
|
if title != "" {
|
||||||
titleHTML := fmt.Sprintf("<p><strong>%s</strong></p>\n", title)
|
titleHTML := fmt.Sprintf("<p><strong>%s</strong></p>\n", stdhtml.EscapeString(title))
|
||||||
if _, err := writer.Write([]byte(titleHTML)); err != nil {
|
if _, err := writer.Write([]byte(titleHTML)); err != nil {
|
||||||
return ast.WalkStop, err
|
return ast.WalkStop, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user