Skip to content

Commit

Permalink
Merge pull request #682 from kaushalmodi/fix-issue-680
Browse files Browse the repository at this point in the history
fix: Escape Hugo shortcode markers in emacs-lisp src blocks as well
  • Loading branch information
kaushalmodi authored Oct 28, 2022
2 parents 600978a + 8e2baca commit a66063a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1242,15 +1242,15 @@ contents according to the current heading."
(defun org-hugo--escape-hugo-shortcode (code lang)
"Escape Hugo shortcodes if present in CODE string.
The escaping is enabled only if LANG is \"md\", \"org\" or
\"go-html-template\".
The escaping is enabled only if LANG is \"md\", \"org\",
\"go-html-template\" or \"emacs-lisp\".
- Shortcode with Markdown : {{% foo %}} -> {{%/* foo */%}}
- Shortcode without Markdown : {{< foo >}} -> {{</* foo */>}}
Return the escaped/unescaped string."
(if (member lang '("md" "org" "go-html-template"))
(if (member lang '("md" "org" "go-html-template" "emacs-lisp"))
(replace-regexp-in-string
"\\({{<\\)\\([^}][^}]*\\)\\(>}}\\)" "\\1/*\\2*/\\3"
(replace-regexp-in-string
Expand Down
20 changes: 20 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,26 @@ numbering.
#+begin_src org
,#+macro: relref @@hugo:[@@ $1 @@hugo:]({{< relref "$2" >}})@@
#+end_src
**** Shortcode escaped in Emacs-Lisp source blocks
{{{oxhugoissue(680)}}}

#+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
*** Shortcodes *not* escaped
The =figure= shortcode in the below example block *should* be
expanded.. you should be seeing a little unicorn below.
Expand Down
23 changes: 23 additions & 0 deletions test/site/content/posts/source-block-md-with-hugo-shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ numbering.
```


### Shortcode escaped in Emacs-Lisp source blocks {#shortcode-escaped-in-emacs-lisp-source-blocks}

`ox-hugo` Issue #[680](https://github.com/kaushalmodi/ox-hugo/issues/680)

```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)
```


## Shortcodes **not** escaped {#shortcodes-not-escaped}

The `figure` shortcode in the below example block **should** be
Expand Down

0 comments on commit a66063a

Please sign in to comment.