Improved figure shortcode, no -1px round of errors.
This commit is contained in:
parent
b1f724e898
commit
73795756ac
1 changed files with 15 additions and 11 deletions
|
|
@ -5,21 +5,25 @@
|
|||
{{ $.Scratch.Set "width" .Width -}}
|
||||
{{ $.Scratch.Set "height" .Height -}}
|
||||
{{ end -}}
|
||||
{{ if (.Get "width") -}}
|
||||
{{ if and (.Get "width") (.Get "height") -}}
|
||||
{{ $.Scratch.Set "width" (int (.Get "width")) -}}
|
||||
{{ $.Scratch.Set "height" (int (.Get "height")) -}}
|
||||
{{ else if (.Get "width") -}}
|
||||
{{ $.Scratch.Set "width" (int (.Get "width")) -}}
|
||||
{{ if lt ($.Scratch.Get "width") ($.Scratch.Get "realwidth") -}}
|
||||
{{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
|
||||
{{ $.Scratch.Set "height" (math.Round $height) -}}
|
||||
{{ end -}}
|
||||
{{ else if (.Get "height") -}}
|
||||
{{ $.Scratch.Set "height" (int (.Get "height")) -}}
|
||||
{{ if lt ($.Scratch.Get "height") ($.Scratch.Get "realheight") -}}
|
||||
{{ $width := (mul ($.Scratch.Get "realwidth") (div (add ($.Scratch.Get "height") 0.0) ($.Scratch.Get "realheight"))) -}}
|
||||
{{ $.Scratch.Set "width" (math.Round $width) -}}
|
||||
{{ end -}}
|
||||
{{ else if and $maxwidth (lt $maxwidth ($.Scratch.Get "width")) -}}
|
||||
{{ $.Scratch.Set "width" $maxwidth -}}
|
||||
{{ end -}}
|
||||
{{ if lt ($.Scratch.Get "width") ($.Scratch.Get "realwidth") -}}
|
||||
{{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
|
||||
{{ $.Scratch.Set "height" (int $height) -}}
|
||||
{{ end -}}
|
||||
{{ if (.Get "height") -}}
|
||||
{{ $.Scratch.Set "height" (int (.Get "height")) -}}
|
||||
{{ end -}}
|
||||
{{ if lt ($.Scratch.Get "height") ($.Scratch.Get "realheight") -}}
|
||||
{{ $width := (mul ($.Scratch.Get "realwidth") (div (add ($.Scratch.Get "height") 0.0) ($.Scratch.Get "realheight"))) -}}
|
||||
{{ $.Scratch.Set "width" (int $width) -}}
|
||||
{{ $.Scratch.Set "height" (math.Round $height) -}}
|
||||
{{ end -}}
|
||||
<figure {{ with .Get "class" }}class="{{ . }}"{{ end }}>
|
||||
{{ with .Get "link" }}<a href="{{ . }}">{{ end -}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue