diff --git a/README.md b/README.md index 0575f3e..4194abf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ File in the extended format should follow the specification: + ``` @@ -73,6 +74,12 @@ Setting the sidebar creates a column on the right side. You're able to add any You can set a page emoji icon by specifying the icon in the headers. +```markdown + +``` + +You can set the alignment for all images in the page. Common values are `left`, `center`, and `right`. This adds the `ac:align` attribute to image tags. Can also be set globally via the `--image-align` CLI option (per-page header takes precedence). + Mark supports Go templates, which can be included into article by using path to the template relative to current working dir, e.g.: @@ -845,6 +852,7 @@ GLOBAL OPTIONS: --d2-scale float defines the scaling factor for d2 renderings. (default: 1) [$MARK_D2_SCALE] --features string [ --features string ] Enables optional features. Current features: d2, mermaid, mention, mkdocsadmonitions (default: "mermaid", "mention") [$MARK_FEATURES] --insecure-skip-tls-verify skip TLS certificate verification (useful for self-signed certificates) [$MARK_INSECURE_SKIP_TLS_VERIFY] + --image-align string set image alignment (left, center, right). Can be overridden per-file via the Image-Align header. [$MARK_IMAGE_ALIGN] --help, -h show help --version, -v print the version ``` @@ -859,6 +867,7 @@ password = "password-or-api-key-for-confluence-cloud" base-url = "http://confluence.local" title-from-h1 = true drop-h1 = true +image-align = "center" ``` **NOTE**: Labels aren't supported when using `minor-edit`! diff --git a/markdown/markdown.go b/markdown/markdown.go index 15885ab..da7e78b 100644 --- a/markdown/markdown.go +++ b/markdown/markdown.go @@ -53,7 +53,7 @@ func (c *ConfluenceExtension) Extend(m goldmark.Markdown) { util.Prioritized(crenderer.NewConfluenceFencedCodeBlockRenderer(c.Stdlib, c, c.MarkConfig), 100), util.Prioritized(crenderer.NewConfluenceHTMLBlockRenderer(c.Stdlib), 100), util.Prioritized(crenderer.NewConfluenceHeadingRenderer(c.MarkConfig.DropFirstH1), 100), - util.Prioritized(crenderer.NewConfluenceImageRenderer(c.Stdlib, c, c.Path), 100), + util.Prioritized(crenderer.NewConfluenceImageRenderer(c.Stdlib, c, c.Path, c.MarkConfig.ImageAlign), 100), util.Prioritized(crenderer.NewConfluenceParagraphRenderer(), 100), util.Prioritized(crenderer.NewConfluenceLinkRenderer(), 100), util.Prioritized(crenderer.NewConfluenceTaskListRenderer(), 100), diff --git a/metadata/metadata.go b/metadata/metadata.go index b70edb1..5ca9e2d 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -26,6 +26,7 @@ const ( HeaderInclude = `Include` HeaderSidebar = `Sidebar` ContentAppearance = `Content-Appearance` + HeaderImageAlign = `Image-Align` ) type Meta struct { @@ -39,6 +40,7 @@ type Meta struct { Attachments []string Labels []string ContentAppearance string + ImageAlign string } const ( @@ -130,6 +132,17 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi meta.ContentAppearance = FullWidthContentAppearance } + case HeaderImageAlign: + align := strings.ToLower(strings.TrimSpace(value)) + if align != "left" && align != "center" && align != "right" { + log.Warningf( + nil, + `unknown image alignment %q, expected one of: left, center, right; passing through to Confluence`, + value, + ) + } + meta.ImageAlign = align + default: log.Errorf( nil, diff --git a/renderer/image.go b/renderer/image.go index f024016..474ca7f 100644 --- a/renderer/image.go +++ b/renderer/image.go @@ -20,15 +20,17 @@ type ConfluenceImageRenderer struct { Stdlib *stdlib.Lib Path string Attachments attachment.Attacher + ImageAlign string } // NewConfluenceRenderer creates a new instance of the ConfluenceRenderer -func NewConfluenceImageRenderer(stdlib *stdlib.Lib, attachments attachment.Attacher, path string, opts ...html.Option) renderer.NodeRenderer { +func NewConfluenceImageRenderer(stdlib *stdlib.Lib, attachments attachment.Attacher, path string, imageAlign string, opts ...html.Option) renderer.NodeRenderer { return &ConfluenceImageRenderer{ Config: html.NewConfig(), Stdlib: stdlib, Path: path, Attachments: attachments, + ImageAlign: imageAlign, } } @@ -55,6 +57,7 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by writer, "ac:image", struct { + Align string Width string Height string Title string @@ -62,6 +65,7 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by Attachment string Url string }{ + r.ImageAlign, "", "", string(n.Title), @@ -78,6 +82,7 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by writer, "ac:image", struct { + Align string Width string Height string Title string @@ -85,6 +90,7 @@ func (r *ConfluenceImageRenderer) renderImage(writer util.BufWriter, source []by Attachment string Url string }{ + r.ImageAlign, "", "", string(n.Title), diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index 5ef845d..370fcb0 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -211,6 +211,7 @@ func templates(api *confluence.API) (*template.Template, error) { `ac:image`: text( `