quarto-dev / quarto-cli

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

Variable substitution via shortcodes fails in `icon` and `href` fields of `about` links #10289

Open connortwiegand opened 1 month ago

connortwiegand commented 1 month ago

Bug description

Suppose you have an item baz in _variables.yml, which contains named subitems foo and bar. If one uses the shortcode {{<var baz.foo >}} in the links subkey of an about page, such as:

title: About Page
about:
  links:
    - icon: {{<var baz.foo >}}
      href: {{<var baz.bar >}}

No variable substitution is performed.

This relates to #1627, #8987, and #4680.

Thank You!

Steps to reproduce

_variables.yml, in project root:

gh: 
  txt: GitHub
  lnk: https://github.com/
  icn: "github"

lnkdn:
  txt: Linkedin
  icn: "linkedin"
  lnk: "https://www.linkedin.com/in/"

about/index.qmd:

---
title: "More About Me"
image: ../imgs/bio-photo-1.jpg
sidebar: false
about:
  id: about-content
  template: trestles
  image-shape: round
  image-width: 250px
  links:
    - icon: github
      text: ""
      href: "{{< var gh.lnk >}}"
    - icon: linkedin
      text: "[]({{< var lnkdn.lnk >}})"
---

:::{#about-content}
<!-- stuff -->
:::

I've tried various flavors of the above links key based on similar issues. I've also tried this using an about.qmd in the root of the project. I am not able to get variable substitution to work as expected.

For completeness, here is a portion of my root _quarto.yml:

project:
  type: website

website:
  title: "Connor T. Wiegand"
  description: ""

  navbar:
    title: "Me"
    left:
      - text: About Me
        href: about/index.qmd

FWIW, adding repo-url: https://github.com/connortwiegand/ and replacing one of the link options with "{{< meta website.repo-url >}}" produces the following:

WARNING (/opt/quarto/share/filters/main.lua:17471) Unknown meta key website.repo-url specified in a metadata Shortcode.

Expected behavior

var shortcodes are substituted with their values from _variables.yml.

Actual behavior

No variable substitution is performed.

Your environment

Quarto check output

Quarto 1.5.52
[✓] 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.52
      Path: /opt/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/cwiegand/.TinyTeX/bin/x86_64-linux
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.11.6 (Conda)
      Path: /home/cwiegand/miniconda3/bin/python
      Jupyter: 5.7.2
      Kernels: python3

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

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /usr/lib/R
      LibPaths:
        - /home/cwiegand/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.48
      rmarkdown: 2.27

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

EDIT:

Variable substitution does work inside the text key. But not inside the icon or href keys. So this correctly injects a variable:

about:
  links
    - icon: github
      text: "{{< var gh.text >}}"

While both of these fail:

about:
  links
    - icon:  "{{< var gh.icon >}}"
      href: "{{< var gh.link >}}"
mcanouil commented 1 month ago

FYI, there is nowhere in Quarto where icon supports shortcodes because it's supposed to be a string giving the name of the Bootstrap icon. If Quarto is going to support shortcodes in icon then it should allow for any possible content such as {{< iconify simple-icons:quarto >}}.

Regarding href I am not sure it supports shortcodes either. So I am going to change to enhancement as I don't think there is any bugs here.

cscheid commented 1 month ago

In my view, this is really halfway between a bug and an enhancement. Technically the fix is to add support for shortcode expansion in these contexts (so an "enhancement"), but the fact that we fail to expand shortcodes in these cases is incredibly unintuitive, so a bug.