The .org file exported from ox-hugo .md file can't be rebuild

I am trying to use ox-hugo package in emacs to build my personal blog however I am encountering problem when trying to export my personal init.el file to my personal page:

I have managed to discover once I removed the following block from my generated .md file the problem will be gone:

Enabling links within Emacs:


;; Follow Hugo links
(defun org-hugo-follow (link)
	"Follow Hugo link shortcodes"
	(org-link-open-as-file
	 (string-trim "{{% ref test.org %}}" "{{% ref " "%}}")))


;; New link type for Org-Hugo internal links
(org-link-set-parameters
 "hugo"
 :complete (lambda ()
						 (concat "{{% ref */"
										 (file-name-nondirectory
											(read-file-name "File: "))
										 " %}}"))
 :follow #'org-hugo-follow)

The error message is **“/Users/zhouqiaohui/Blog/content/en/post/emacs-learning/Emacs.md:1:1”: unrecognized character in shortcode action: U+002A ‘*’. Note: Parameters with non-alphanumeric args must be quoted **

If I remove


;; New link type for Org-Hugo internal links
(org-link-set-parameters
 "hugo"
 :complete (lambda ()
						 (concat "{{% ref */"
										 (file-name-nondirectory
											(read-file-name "File: "))
										 " %}}"))
 :follow #'org-hugo-follow)

The error message persist but now the shortcode is " ". Also one perculiarity is the error message said the error is at line 1:1 which doesn’t reflect the true lines where the problem exists. I am wondering why it throws these messages and why?

For your reference, the org source block looks the following:

#+begin_src emacs-lisp

  ;; Follow Hugo links
  (defun org-hugo-follow (link)
    "Follow Hugo link shortcodes"
    (org-link-open-as-file
     (string-trim "{{% ref test.org %}}" "{{% ref " "%}}")))

  ;; New link type for Org-Hugo internal links
  (org-link-set-parameters
   "hugo"
   :complete (lambda ()
               (concat "{{% ref */"
                       (file-name-nondirectory
                        (read-file-name "File: "))
                       " %}}"))
   :follow #'org-hugo-follow)

#+end_src

cc: @kaushalmodi

The {{% .. %}} construct is getting exported to Markdown as-is. It doesn’t matter if they are in the emacs-lisp code blocks; Hugo will still try to interpret those as shortcodes.

Right now, ox-hugo prevents the exact export of {{% .. %}} and {{< .. >}} by inserting the Hugo shortcode comment chars in-between them so that Hugo doesn’t parse them as shortcode syntax. But this happens only if they are found in a markdown or Org or Go template HTML code blocks.

See ox-hugo/ox-hugo.el at 41ce9242f661e8f732044bd6a913a37e44688b2f · kaushalmodi/ox-hugo · GitHub

Looking at this example, I need to do that escaping in emacs-lisp code blocks too. Please open an issue on the ox-hugo repo referring to this thread.


@jmooring Thanks for the ping :grinning:

1 Like

This issue will be fixed in ox-hugo once fix: Escape Hugo shortcode markers in emacs-lisp src blocks as well by kaushalmodi · Pull Request #682 · kaushalmodi/ox-hugo · GitHub is merged. Thanks for reporting it.

1 Like