quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.68k stars 297 forks source link

Quarto hugo-md rendering doesn't work with shortcodes with named arguments #10292

Open ryarazi opened 1 month ago

ryarazi commented 1 month ago

Bug description

When trying to render quarto .qmd into an .md for a hugo website I get a bug where the names of named arguments are removed from shortcodes.

Steps to reproduce

When I run quarto render on:

---
title: "Test"
format: hugo-md
---

```{=markdown}
{{< vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" >}}

### Expected behavior

I expect to get:

````md
---
title: "Test"
format: hugo-md
---

{{< vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" >}}

Actual behavior

Instead the resulting file is:

---
title: Test
format: hugo-md
---

{{< vimeo "146022717" "my-vimeo-wrapper-class" "My vimeo video" >}}

Your environment

OS: Ubuntu 24.04 LTS using Windows WSL

Quarto check output

Quarto 1.5.54
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.54
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Tex:  (not detected)

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.3
      Path: /home/me/venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3, dev, julia-1.10

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
cderv commented 1 month ago

Thanks for the report.

Our pre-shortcode-filter are currently processing this syntax. And it seems to happen even for unknown shortcode. Somehow, the attribute names are removed 🤔

Extract for the trace json showing shortcode replacement ```` Filter: normalize-table-merge-raw-html (no op) Doc meta: toc-title: "Table of contents" title: "Test" header-includes: [] revealjs-plugins: [] biblio-config: true include-after: [] labels: modified: "Modified" abstract: "Abstract" affiliations: "Affiliations" published: "Published" related_formats: "Other Formats" doi: "Doi" description: "Description" authors: "Authors" keywords: "Keywords" include-before: [] pandoc-api-version: "1,23,1" blocks: - t: "RawBlock" format: "markdown" text: "{{< vimeo id=\"146022717\" class=\"my-vimeo-wrapper-class\" title=\"My vimeo video\" >}}" - t: "Div" attr: "('3ade8a4a-fb1d-4a6c-8409-ac45482d5fc9', ['hidden'], [])" content: [] <--- NO OP HERE ---> Filter: pre-shortcodes-filter Doc meta: toc-title: "Table of contents" title: "Test" header-includes: [] revealjs-plugins: [] biblio-config: true include-after: [] labels: modified: "Modified" abstract: "Abstract" affiliations: "Affiliations" published: "Published" related_formats: "Other Formats" doi: "Doi" description: "Description" authors: "Authors" keywords: "Keywords" include-before: [] pandoc-api-version: "1,23,1" blocks: - t: "RawBlock" format: "markdown" text: "{{< vimeo \"146022717\" \"my-vimeo-wrapper-class\" \"My vimeo video\" >}}" - t: "Div" attr: "('3ade8a4a-fb1d-4a6c-8409-ac45482d5fc9', ['hidden'], [])" content: [] Ops - op: "replace" path: "/blocks/0/text" value: "{{< vimeo \"146022717\" \"my-vimeo-wrapper-class\" \"My vimeo video\" >}}" ````

Escaping shortcode: https://quarto.org/docs/extensions/shortcodes.html#escaping seems to work here.

```{=markdown}
{{{< vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" >}}}


Anyhow, for hugo-md escaping seems to be the key here - though this is a change from what we documented for Hugo https://quarto.org/docs/output-formats/hugo.html#shortcodes

> Note that Hugo [shortcodes](https://gohugo.io/content-management/shortcodes/) and Quarto [shortcodes](https://quarto.org/docs/extensions/shortcodes.html) share the same basic syntax (e.g. {{< var foo >}}). **This is normally not a problem as shortcodes not recognized by Quarto are passed through unmodified to Hugo.**

Not the case anymore. 

We should probably at least update the doc, or fix if this is unintended.
cderv commented 1 month ago

It seems we reconstruct the shortcode when unknown, but we are missing the raw_args names from lst https://github.com/quarto-dev/quarto-cli/blob/de636882956a7a1c61e2c7893d95be7c2b4310ad/src/resources/filters/customnodes/shortcodes.lua#L227-L230

cscheid commented 1 month ago

Definitely a bug we need to fix. I'm surprised about the raw_args behavior, those should not be touching named args at all.