Skip to content

Commit

Permalink
Support specifying image height in #+ATTR_HTML
Browse files Browse the repository at this point in the history
This feature will work in hugo v0.31 and later versions.

It was implemented in gohugoio/hugo#4018.
  • Loading branch information
kaushalmodi committed Oct 30, 2017
1 parent f132daa commit 9df23b7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ and rewrite link paths to make blogging more seamless."
(attr . ,(plist-get attr :attr))
(attrlink . ,(plist-get attr :attrlink))
(alt . ,(plist-get attr :alt))
(width . ,(plist-get attr :width))))
(width . ,(plist-get attr :width))
(height . ,(plist-get attr :height))))
(figure-param-str ""))
(dolist (param figure-params)
(let ((name (car param))
Expand Down
42 changes: 39 additions & 3 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Some text before image.
[[/images/org-mode-unicorn-logo.png]]
Some more text, after image.
*** Setting image size
**** Setting =:width= parameter
The image [[https://www.w3schools.com/tags/att_img_width.asp][width]] can be specified in *pixels* using the =:width=
parameter. *The height of the image will be resized proportionally.*

Expand All @@ -163,12 +164,47 @@ Below image is shown 100 pixels wide.
#+ATTR_HTML: :width 100
[[/images/org-mode-unicorn-logo.png]]

Below image is shown 1000 pixels width! Now the size of this image is
200px × 200px. But the image will still show up in 1000px × 1000px
size, but obviously heavily pixelated!
Below image is shown with a width of 1000 pixels! Now the size of this
image is 200px × 200px. But the image will still show up in 1000px ×
1000px size, but obviously heavily pixelated!

#+ATTR_HTML: :width 1000
[[/images/org-mode-unicorn-logo.png]]
**** Setting =:height= parameter
*NOTE*: Support for specifying =height= parameter to the Hugo =figure=
shortcut was only added recently in [[https://github.com/gohugoio/hugo/pull/4018][hugo PR #4018]]. So setting this
parameter will need *hugo v0.31* or later.

-----

The image [[https://www.w3schools.com/tags/att_img_height.asp][height]] can be specified in *pixels* using the =:height=
parameter. *The weight of the image will be resized proportionally.*

Below image is shown 50 pixels tall.
#+ATTR_HTML: :height 50
[[/images/org-mode-unicorn-logo.png]]

Below image is shown 100 pixels tall.
#+ATTR_HTML: :height 100
[[/images/org-mode-unicorn-logo.png]]

Below image is shown with a height of 1000 pixels! Now the size of
this image is 200px × 200px. But the image will still show up in
1000px × 1000px size, but obviously heavily pixelated!

#+ATTR_HTML: :height 1000
[[/images/org-mode-unicorn-logo.png]]
**** Setting both =:width= and =:height=
The *NOTE* above applies here too.. needs *hugo v0.31* or later.

The figure sizes below are intentionally set /mis-proportionally/ just
for testing.
- =:width 100 :height 200=
#+ATTR_HTML: :width 100 :height 200
[[/images/org-mode-unicorn-logo.png]]
- =:width 200 :height 100=
#+ATTR_HTML: :width 200 :height 100
[[/images/org-mode-unicorn-logo.png]]
*** Other
Similarly, =:link=, =:attr=, =:attrlink= parameters in =#+ATTR_HTML=
are also supported to set the corresponding parameter in the Hugo
Expand Down
50 changes: 47 additions & 3 deletions test/site/content/posts/figure-shortcode-and-attr-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Some more text, after image.

## Setting image size {#setting-image-size}


### Setting `:width` parameter {#setting-width-parameter}

The image [width](https://www.w3schools.com/tags/att_img_width.asp) can be specified in **pixels** using the `:width`
parameter. **The height of the image will be resized proportionally.**

Expand All @@ -62,13 +65,54 @@ Below image is shown 100 pixels wide.

{{<figure src="/images/org-mode-unicorn-logo.png" width="100">}}

Below image is shown 1000 pixels width! Now the size of this image is
200px × 200px. But the image will still show up in 1000px × 1000px
size, but obviously heavily pixelated!
Below image is shown with a width of 1000 pixels! Now the size of this
image is 200px × 200px. But the image will still show up in 1000px ×
1000px size, but obviously heavily pixelated!

{{<figure src="/images/org-mode-unicorn-logo.png" width="1000">}}


### Setting `:height` parameter {#setting-height-parameter}

**NOTE**: Support for specifying `height` parameter to the Hugo `figure`
shortcut was only added recently in [hugo PR #4018](https://github.com/gohugoio/hugo/pull/4018). So setting this
parameter will need **hugo v0.31** or newer.

---

The image [height](https://www.w3schools.com/tags/att_img_height.asp) can be specified in **pixels** using the `:height`
parameter. **The weight of the image will be resized proportionally.**

Below image is shown 50 pixels tall.

{{<figure src="/images/org-mode-unicorn-logo.png" height="50">}}

Below image is shown 100 pixels tall.

{{<figure src="/images/org-mode-unicorn-logo.png" height="100">}}

Below image is shown with a height of 1000 pixels! Now the size of
this image is 200px × 200px. But the image will still show up in
1000px × 1000px size, but obviously heavily pixelated!

{{<figure src="/images/org-mode-unicorn-logo.png" height="1000">}}


### Setting both `:width` and `:height` {#setting-both-width-and-height}

The **NOTE** above applies here too.. needs **hugo v0.31** or newer.

The figure sizes below are intentionally set _mis-proportionally_ just
for testing.

- `:width 100 :height 200`

{{<figure src="/images/org-mode-unicorn-logo.png" width="100" height="200">}}
- `:width 200 :height 100`

{{<figure src="/images/org-mode-unicorn-logo.png" width="200" height="100">}}


## Other {#other}

Similarly, `:link`, `:attr`, `:attrlink` parameters in `#+ATTR_HTML`
Expand Down

0 comments on commit 9df23b7

Please sign in to comment.