fix: Panic on empty link

This commit is contained in:
Manuel Rüger 2025-11-28 14:33:32 +01:00
parent a7390d8b33
commit 888d5de655
3 changed files with 6 additions and 1 deletions

View File

@ -26,7 +26,7 @@ func (r *ConfluenceLinkRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegi
// renderLink renders links specifically for confluence
func (r *ConfluenceLinkRenderer) renderLink(writer util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
n := node.(*ast.Link)
if string(n.Destination[0:3]) == "ac:" {
if len(n.Destination) >= 3 && string(n.Destination[0:3]) == "ac:" {
if entering {
_, err := writer.Write([]byte("<ac:link><ri:page ri:content-title=\""))
if err != nil {

2
testdata/links.html vendored
View File

@ -11,6 +11,8 @@
<p><ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link></p>
<p>Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
<p>Use <a href="foo">Link [Text]</a></p>
<h2 id="Empty-link">Empty link</h2>
<p><a href=""></a></p>
<div class="footnotes" role="doc-endnotes">
<hr />
<ol>

3
testdata/links.md vendored
View File

@ -24,3 +24,6 @@ Use footnotes link [^1]
[^1]: a footnote link
Use [Link [Text]](foo)
## Empty link
[]()