From 9825a5e698b033241468709f1f5cd3e79c5925cd Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 23 Jun 2020 17:24:43 -0400 Subject: [PATCH] If a link has spaces in it, wrap it in angle brackets Fixes https://github.com/kaushalmodi/ox-hugo/issues/376 --- ox-hugo.el | 10 +++++++++- test/site/content-org/all-posts.org | 4 ++++ test/site/content/posts/image-links.md | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ox-hugo.el b/ox-hugo.el index c3ca42b..94b8bc6 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -2320,7 +2320,15 @@ and rewrite link paths to make blogging more seamless." (org-link-unescape desc))) ;; Only link description, but no link attributes. (desc - (format "[%s](%s)" desc path)) + (let* ((path-has-space (and + (not (string-prefix-p "{{< relref " path)) + (string-match-p "\\s-" path))) + (path (if path-has-space + ;; https://github.com/kaushalmodi/ox-hugo/issues/376 + ;; https://github.com/gohugoio/hugo/issues/6742#issuecomment-573924706 + (format "<%s>" path) + path))) + (format "[%s](%s)" desc path))) ;; Only link attributes, but no link description. (link-param-str (let ((path (org-html-encode-plain-text path))) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 18de9b0..d4b9715 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -162,6 +162,10 @@ even when inside page bundle pages. =org-hugo-default-static-subdirectory-for-externals=. ***** Same image, but hyperlinked to itself [[../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png][file:../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png]] +*** Link to an image with space in filename +This is a link to a file with a space in the filename: +{{{oxhugoissue(376)}}} +[[file:../files-to-be-copied-to-static/foo/unicorn logo.png][Link to ~unicorn logo.png~]] ** Inline hyperlinked and non-hyperlinked images :inline: :PROPERTIES: :EXPORT_FILE_NAME: inline-images diff --git a/test/site/content/posts/image-links.md b/test/site/content/posts/image-links.md index a553a5a..7aa135f 100644 --- a/test/site/content/posts/image-links.md +++ b/test/site/content/posts/image-links.md @@ -142,3 +142,10 @@ Note #### Same image, but hyperlinked to itself {#same-image-but-hyperlinked-to-itself} {{< figure src="/ox-hugo/copy-2-of-unicorn-logo.png" link="/ox-hugo/copy-2-of-unicorn-logo.png" >}} + + +## Link to an image with space in filename {#link-to-an-image-with-space-in-filename} + +This is a link to a file with a space in the filename: +`ox-hugo` Issue #[376](https://github.com/kaushalmodi/ox-hugo/issues/376) +[Link to `unicorn logo.png`]()