mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-01 21:02:33 +00:00
feat: add support for image dimensions
This commit is contained in:
committed by
Manuel Rüger
parent
c32cd79dc8
commit
4d887bde74
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user