Permalink
Browse files

Fix clickable image links with #+NAME

Earlier the a id tag was placed incorrectly.. fixed now.
  • Loading branch information...
kaushalmodi committed Jan 15, 2018
1 parent 53cfa26 commit fef0ec50deef8191897da3aae0735d9ba09f33f8
Showing with 45 additions and 24 deletions.
  1. +24 −19 ox-hugo.el
  2. +11 −3 test/site/content-org/all-posts.org
  3. +10 −2 test/site/content/posts/image-links.md
@@ -1301,11 +1301,6 @@ and rewrite link paths to make blogging more seamless."
(useful-parent (if grand-parent
grand-parent
parent))
(label (let ((lbl (and (org-element-property :name useful-parent)
(org-export-get-reference useful-parent info))))
(if lbl
(format "<a id=\"%s\"></a>\n" lbl)
"")))
(attr (org-export-read-attribute :attr_html useful-parent))
;; Hugo `figure' shortcode named parameters
;; https://gohugo.io/content-management/shortcodes/#figure
@@ -1337,7 +1332,7 @@ and rewrite link paths to make blogging more seamless."
(format "%s=\"%s\" "
name val))))))
;; (message "[org-hugo-link DBG] figure params: %s" figure-param-str)
(format "%s{{<figure %s>}}" label (org-trim figure-param-str))))
(format "{{<figure %s>}}" (org-trim figure-param-str))))
((string= type "coderef")
(let ((ref (org-element-property :path link)))
(format (org-export-get-coderef-format ref contents)
@@ -1467,19 +1462,29 @@ INFO is a plist used as a communication channel."
"Transcode PARAGRAPH element into Hugo Markdown format.
CONTENTS is the paragraph contents. INFO is a plist used as a
communication channel."
(unless (org-hugo--plist-get-true-p info :hugo-preserve-filling)
(setq contents (concat (mapconcat 'identity (split-string contents) " ") "\n")))
;; Glue footnotes to the words before them using &nbsp; so that the
;; footnote reference does not end up on a new line by itself.
(setq contents (replace-regexp-in-string
;; "something FN" -> "something&nbsp;FN"
"[[:blank:]]+\\(\\[\\^[^]]+\\]\\)" "&nbsp;\\1"
(replace-regexp-in-string
;; "FN ." -> "FN."
"\\(\\[\\^[^]]+\\]\\)[[:blank:]]*\\([.]+\\)" "\\1\\2"
contents)))
;; (message "[org-hugo-paragraph DBG] para: %s" contents)
(org-md-paragraph paragraph contents info))
(let (;; The label is mainly for paragraphs that are standalone
;; images with #+NAME keyword.
(label (let ((lbl (and (org-element-property :name paragraph)
(org-export-get-reference paragraph info))))
(if lbl
(format "<a id=\"%s\"></a>\n" lbl)
"")))
ret)
(unless (org-hugo--plist-get-true-p info :hugo-preserve-filling)
(setq contents (concat (mapconcat 'identity (split-string contents) " ") "\n")))
;; Glue footnotes to the words before them using &nbsp; so that the
;; footnote reference does not end up on a new line by itself.
(setq contents (replace-regexp-in-string
;; "something FN" -> "something&nbsp;FN"
"[[:blank:]]+\\(\\[\\^[^]]+\\]\\)" "&nbsp;\\1"
(replace-regexp-in-string
;; "FN ." -> "FN."
"\\(\\[\\^[^]]+\\]\\)[[:blank:]]*\\([.]+\\)" "\\1\\2"
contents)))
;; (message "[org-hugo-paragraph DBG] para: %s" contents)
(setq ret (concat label
(org-md-paragraph paragraph contents info)))
ret))
;;;; Source Blocks
(defun org-hugo-src-block (src-block _contents info)
@@ -66,10 +66,18 @@ tag and look the same size.
[[/images/org-mode-unicorn-logo.png][Click here to see the unicorn]]
*** Clickable image that opens the image (works!)
Click below image to jump to the unicorn image.
[[file:/images/org-mode-unicorn-logo.png][file:/images/org-mode-unicorn-logo.png]]
[[/images/org-mode-unicorn-logo.png][file:/images/org-mode-unicorn-logo.png]]
- NOTE :: =file:= has to be used in both Link and Description components
of the Org link.
- NOTE :: =file:= has to be used in the *Description component* of the
Org link.
-----
Here's the same link with =#+NAME= specified.. which should also be
clickable.
#+NAME: fig__unicorn
[[/images/org-mode-unicorn-logo.png][file:/images/org-mode-unicorn-logo.png]]
*** Link to image outside of standard Hugo =static= directory
[[../files-to-be-copied-to-static/static/images/copy-of-unicorn-logo.png]]
@@ -47,8 +47,16 @@ tag and look the same size.
Click below image to jump to the unicorn image.
[{{<figure src="/images/org-mode-unicorn-logo.png">}}](/images/org-mode-unicorn-logo.png)
- **NOTE:** `file:` has to be used in both Link and Description components
of the Org link.
- **NOTE:** `file:` has to be used in the **Description component** of the
Org link.
---
Here's the same link with `#+NAME` specified.. which should also be
clickable.
<a id="orgf772560"></a>
[{{<figure src="/images/org-mode-unicorn-logo.png">}}](/images/org-mode-unicorn-logo.png)
## Link to image outside of standard Hugo `static` directory {#link-to-image-outside-of-standard-hugo-static-directory}

0 comments on commit fef0ec5

Please sign in to comment.