Skip to content

Commit

Permalink
Support specifying the image width in #+ATTR_HTML
Browse files Browse the repository at this point in the history
Known issue as of Hugo v0.30: The Hugo figure shortcode does not
support specifying the height parameter! So ox-hugo will support only
the width parameter for now.

figure shortcode in Hugo source:
https://github.com/gohugoio/hugo/blob/b6f2e3b4382de83479bfcf91321b7ee3a758b141/tpl/tplimpl/template_embedded.go#L22-L37

https://discourse.gohugo.io/t/can-i-find-out-the-image-size/2196/12?u=kaushalmodi
  • Loading branch information
kaushalmodi committed Oct 26, 2017
1 parent d330e16 commit 4a476d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ and rewrite link paths to make blogging more seamless."
(class . ,(plist-get attr :class))
(attr . ,(plist-get attr :attr))
(attrlink . ,(plist-get attr :attrlink))
(alt . ,(plist-get attr :alt))))
(alt . ,(plist-get attr :alt))
(width . ,(plist-get attr :width))))
(figure-param-str ""))
(dolist (param figure-params)
(let ((name (car param))
Expand Down
18 changes: 18 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ Some text before image.
#+ATTR_HTML: :caption A unicorn!
[[/images/org-mode-unicorn-logo.png]]
Some more text, after image.
*** Setting image size
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.*

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

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!

#+ATTR_HTML: :width 1000
[[/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
20 changes: 20 additions & 0 deletions test/site/content/posts/figure-shortcode-and-attr-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ Some text before image.
Some more text, after image.


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

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.**

Below image is shown 50 pixels wide.

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

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!

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


## Other {#other}

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

0 comments on commit 4a476d9

Please sign in to comment.