feat: add support for image dimensions

This commit is contained in:
Johan Fagerberg
2026-02-19 09:44:33 +01:00
committed by Manuel Rüger
parent c32cd79dc8
commit 4d887bde74
6 changed files with 65 additions and 7 deletions

View File

@@ -139,10 +139,14 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu
return ast.WalkStop, err
}
r.Attachments.Attach(attachment)
effectiveAlign := calculateAlign(r.MarkConfig.ImageAlign, attachment.Width)
err = r.Stdlib.Templates.ExecuteTemplate(
writer,
"ac:image",
struct {
Align string
Width string
Height string
Title string
@@ -150,6 +154,7 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu
Attachment string
Url string
}{
effectiveAlign,
attachment.Width,
attachment.Height,
attachment.Name,
@@ -170,10 +175,14 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu
return ast.WalkStop, err
}
r.Attachments.Attach(attachment)
effectiveAlign := calculateAlign(r.MarkConfig.ImageAlign, attachment.Width)
err = r.Stdlib.Templates.ExecuteTemplate(
writer,
"ac:image",
struct {
Align string
Width string
Height string
Title string
@@ -181,6 +190,7 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu
Attachment string
Url string
}{
effectiveAlign,
attachment.Width,
attachment.Height,
attachment.Name,

View File

@@ -3,6 +3,7 @@ package renderer
import (
"bytes"
"path/filepath"
"strconv"
"strings"
"github.com/kovetskiy/mark/attachment"
@@ -15,6 +16,30 @@ import (
"github.com/yuin/goldmark/util"
)
// calculateAlign determines the appropriate ac:align value based on width
// Images >= 760px wide use "wide", otherwise use the configured alignment
func calculateAlign(configuredAlign string, width string) string {
if configuredAlign == "" {
return ""
}
if width == "" {
return configuredAlign
}
// Parse width and check if >= 760
widthInt, err := strconv.Atoi(width)
if err != nil {
return configuredAlign
}
if widthInt >= 760 {
return "wide"
}
return configuredAlign
}
type ConfluenceImageRenderer struct {
html.Config
Stdlib *stdlib.Lib
@@ -78,6 +103,8 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by
r.Attachments.Attach(attachments[0])
effectiveAlign := calculateAlign(r.ImageAlign, attachments[0].Width)
err = r.Stdlib.Templates.ExecuteTemplate(
writer,
"ac:image",
@@ -90,9 +117,9 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by
Attachment string
Url string
}{
r.ImageAlign,
"",
"",
effectiveAlign,
attachments[0].Width,
attachments[0].Height,
string(n.Title),
string(nodeToHTMLText(n, source)),
attachments[0].Filename,