kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
874 stars 132 forks source link

short codes phrase with {{< >}} (what am I doing wrong...) #602

Closed jarss closed 2 years ago

jarss commented 2 years ago

shortcode exports with {{< >}}

ox-hugo supposed to "leave these alone" as these don't work in org-mode

How to Reproduce the Issue

Sample:

** PUBLISHED TAONAW: The Art of Not Asking Why :PROPERTIES: :EXPORT_HUGO_SECTION: TAONAW :EXPORT_FILE_NAME: _index :EXPORT_HUGO_LAYOUT: single :EXPORT_HUGO_PAIRED_SHORTCODES: rawhtml :END:

This website is essentially free to maintain[fn:134].

TAONAW is built with [[https://gohugo.io/][Hugo Go]], a free open-source static-site generator. It is designed and authored on a free Linux OS using [[https://www.gnu.org/software/emacs/][Emacs]] [[https://orgmode.org/][org-mode]] and [[https://ox-hugo.scripter.co/][ox-hugo]]. Bandwidth is currently supplied free of charge by GitLab.

I write posts in my free time because I want to and I enjoy doing so. No one is supporting me, sponsoring me, or otherwise paying me anything to write or create or publish any content. The goal is to keep things this way.

If you enjoy what you find here, you can go ahead leave a one-time [[https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XBBGQRR2CX5EJ&source=url][tip]]. This is not payment: you're tipping me for a service I gave (a post you like), not a service you want to get (asking me to write a post).

A note about copying/using the code and other parts of this site: I use free tools and free knowledge to build this site, and you are welcome to take and use anything you'd like, /except/ the logo. The logo of the owl and the book was not free and therefore, you may /not/ copy or re-use it. It was created by another artist, who I hired for money. If you want the name, I'll be more than happy to give it to you. Just ask.

You can also go ahead and copy the content of the posts as well, just please link back to this site.

{{< rawhtml >}}
<a href="https://liberapay.com/JTR/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
{{< /rawhtml >}}

on the site, it shows as following:

2022-03-24_09-07

Ox-Hugo Debug Information

Debug Info # Debug information for `ox-hugo` ## Emacs Version GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20) of 2021-02-13 ## Org Version Org mode version 9.3 (release_9.3 @ /usr/local/share/emacs/27.1/lisp/org/) ## Hugo Version Hugo Static Site Generator v0.80.0-792EF0F4/extended linux/amd64 BuildDate: 2020-12-31T13:46:18Z ### Org `load-path` shadows No Org mode shadows found in `load-path` ## `ox-hugo` defcustoms
org-hugo-section "posts"
org-hugo-use-code-for-kbd nil
org-hugo-preserve-filling t
org-hugo-delete-trailing-ws t
org-hugo-prefer-hyphen-in-tags t
org-hugo-allow-spaces-in-tags t
org-hugo-tag-processing-functions (org-hugo–tag-processing-fn-replace-with-spaces-maybe org-hugo–tag-processing-fn-replace-with-hyphens-maybe)
org-hugo-auto-set-lastmod nil
org-hugo-export-with-toc nil
org-hugo-export-with-section-numbers nil
org-hugo-front-matter-format "toml"
org-hugo-default-static-subdirectory-for-externals "ox-hugo"
org-hugo-external-file-extensions-allowed-for-copying ("jpg" "jpeg" "tiff" "png" "svg" "gif" "mp4" "pdf" "odt" "doc" "ppt" "xls" "docx" "pptx" "xlsx")
org-hugo-date-format "%Y-%m-%dT%T%z"
org-hugo-paired-shortcodes ""
org-hugo-langs-no-descr-in-code-fences nil
org-hugo-suppress-lastmod-period 0.0
org-hugo-front-matter-format "toml"
jarss commented 2 years ago

Looking at the .md file,

The original code was: <a href="https://liberapay.com/JTR/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>

but ox-hugo creates:

{{< rawhtml >}}
&lt;a href="<https://liberapay.com/JTR/donate>"&gt;&lt;img alt="Donate using Liberapay" src="![](https://liberapay.com/assets/widgets/donate.svg)"&gt;&lt;/a&gt;
{{< /rawhtml >}}

in the .md file

I'm not sure why this happens.

Of course, adding the code directly to the .md files (as it was originally) works fine.

kaushalmodi commented 2 years ago

ox-hugo supposed to "leave these alone" as these don't work in org-mode

But default, ox-hugo auto-escapes angle brackets as they are special characters in HTML (like <a>). You see the same behavior when you export the same Org snippet using ox-html. The main reason for this ox-hugo behavior was that I didn't want some Org content to have surprisingly different behavior when exporting using ox-html vs ox-hugo. Escaping the HTML special characters or not is a very base level behavior that I didn't want to change.

The side effect of this decision is that the users don't inadvertently lock-in their Org mode content to be exportable using just Hugo! The aim of ox-hugo is to allow any normal Org content to be easily exportable to Hugo after adding just one ox-hugo specific thing: the HUGO_BASE_DIR keyword (the EXPORT_FILE_NAME subtree property is not ox-hugo specific, but ox-hugo needs that for subtree exports to understand the root level of a post). Now, it would be ironic that people have their Org content polluted with non-Org syntax like {{< foo >}} that would export sensibly with only ox-hugo! And that's why, that syntax is not accepted in raw Org even by ox-hugo.

Due to that, people might also discover inbuilt Org features they didn't know existed :)

For your example:

{{< rawhtml >}}
<a href="https://liberapay.com/JTR/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
{{< /rawhtml >}}

, the same can be done with:

#+begin_export html
<a href="https://liberapay.com/JTR/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
#+end_export

Even better: If you using that frequently at multiple places, convert that to an Org macro (details in the below link).

I have a full section on exporting Shortcodes. Check it out for more options on how to use Hugo shortcodes with ox-hugo.

jarss commented 2 years ago

I don't follow the solution.

I read through the shorcodes part (that's how I know to include :EXPORT_HUGO_PAIRED_SHORTCODES: rawhtml, for example). The expected behavior, "Use :EXPORT_HUGO_PAIRED_SHORTCODES: myshortcode ... let the Org Special Block parsing logic know that “myshortcode” tag needs to be exported as a paired shortcode."

So this means, if I use the short code paired property, the exported .md file should contain the {{ < > }} markings, correct? If that's true, I don't see that in the .md, I see the code I posted in the comment.

So, I'm thinking...

  1. I'm missing a part, of included the wrong syntax somewhere, because I don't understand how this work (this is usually the case) or:
  2. there's a problem elsewhere that exports my code in the way it shows above, which is wrong. Not sure where though. I also tried #+begin_export html. This resulted in... nothing. I don't see anything on the page, no code at all, just blank.

When checking the .md file after using the export html option, I do see the html as it should be, but I don't see it on the local site (local hugo server)

jarss commented 2 years ago

OK. I'm at a lost. I rebuilt the site, I tried again (with export html), and now it works. I must be tired and I did something else wrong, even though I swear all I did is copy paste. Since I can't replicate this, I will push and see if this work on the site, if it does, I'll close this. must be human error....

kaushalmodi commented 2 years ago

that's how I know to include :EXPORT_HUGO_PAIRED_SHORTCODES: rawhtml

That's for the Org Special Blocks. That doesn't mean that you can use Hugo shortcode syntax directly in Org source.

If you use that, you need to do

#+begin_rawhtml
..
#+end_rawhtml

See the "myshortcode" example in https://ox-hugo.scripter.co/doc/shortcodes/#hugo-paired-shortcodes

jarss commented 2 years ago

Ok, since I can't replicate this and it seems to work now... I'll close this. It's odd, what you suggest (#+begin_rawhtml and

+end_rawhtml) lead to the same issue, which makes me think something else was going on that was not related to this issue at all.

It works now, I'm using export html option instead.