Skip to content

Commit

Permalink
fix: Escape Hugo shortcodes in Org source blocks too
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Feb 28, 2022
1 parent 6497963 commit 19cbc09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ox-hugo.el
Expand Up @@ -1023,14 +1023,14 @@ 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\".
The escaping is enabled only if LANG is \"md\" or \"org\".
- Shortcode with Markdown : {{% foo %}} -> {{%/* foo */%}}
- Shortcode without Markdown : {{< foo >}} -> {{</* foo */>}}
Return the escaped/unescaped string."
(if (string= lang "md")
(if (member lang '("md" "org"))
(replace-regexp-in-string
"\\({{<\\)\\([^}][^}]*\\)\\(>}}\\)" "\\1/*\\2*/\\3"
(replace-regexp-in-string
Expand Down
4 changes: 4 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -1971,6 +1971,10 @@ numbering.
{{< figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" >}}
{{% figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" %}}
#+end_src
**** Shortcode escaped in Org source blocks
#+begin_src org
,#+macro: relref @@hugo:[@@ $1 @@hugo:]({{< relref "$2" >}})@@
#+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
Expand Up @@ -32,6 +32,13 @@ numbering.
```


### Shortcode escaped in Org source blocks {#shortcode-escaped-in-org-source-blocks}

```org
#+macro: relref @@hugo:[@@ $1 @@hugo:]({{</* relref "$2" */>}})@@
```


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

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

0 comments on commit 19cbc09

Please sign in to comment.