Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow shortcodes expansion in icon attribute/YAML/code cell option #10004

Closed
mcanouil opened this issue Jun 14, 2024 · 5 comments · Fixed by #10206
Closed

Allow shortcodes expansion in icon attribute/YAML/code cell option #10004

mcanouil opened this issue Jun 14, 2024 · 5 comments · Fixed by #10206
Assignees
Labels
enhancement New feature or request shortcodes issues related to shortcodes
Milestone

Comments

@mcanouil
Copy link
Collaborator

For other Quarto components, you can use the text: "{{< iconify octicon:issue-opened-16 >}} Opened Issues" to get an icon from a shortcode in most places (instead of icon: name), but for value box, you can't do that as the icon gets a particular treatment for it to appear on the left of the content of the value box.

It would be nice to be able to use more icons than the limited set of Bootstrap in particular in value box in dashboard as there are no alternatives/workarounds:

::: {.valuebox icon="{{< iconify octicon:log-24 >}}" color="blue"}
Articles per day

`{python} articles`
:::

The approach of allowing shortcode inside icon could also be expanded to all icon everywhere in Quarto.

@mcanouil mcanouil added the enhancement New feature or request label Jun 14, 2024
@cderv
Copy link
Collaborator

cderv commented Jun 14, 2024

Is shortcode allowed on Div syntax attributes in general ? Your issue is quite specific to dashboard and valuebox, but I think using shortcodes on Fenced Div attributes is not working in general.

Shortcode replacement for this happens in AST processing, but our reader does not see initially a Div.

Take this

---
title: test
keep-md: true
format: html
---

::: {.custom title="{{< meta title >}}"}
Content
:::

image

But using trace, the starting Doc is a Para first

blocks:
  - t: "Para"
    content:
      - "::: {.custom title="
      - t: "Quoted"
        content:
          - "\""
          - t: "Span"
            attr: "('', ['quarto-shortcode__'], ['data-is-shortcode,1', 'data-raw,{{< meta title >}}'])"
            content:
              - t: "Span"
                attr: "('', ['quarto-shortcode__-param'], ['data-is-shortcode,1', 'data-value,meta', 'data-raw,meta'])"
                content: []
              - " "
              - t: "Span"
                attr: "('', ['quarto-shortcode__-param'], ['data-is-shortcode,1', 'data-value,title', 'data-raw,title'])"
                content: []
      - "}Content:::"

So I don't know enough about Shortcode handling to see how / if this could be supported

@cderv cderv added triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. shortcodes issues related to shortcodes labels Jun 14, 2024
@cderv cderv added this to the Future milestone Jun 14, 2024
@mcanouil
Copy link
Collaborator Author

The use case was indeed mostly the dashboard, but the enhancement could be more broad.

@cscheid
Copy link
Collaborator

cscheid commented Jun 17, 2024

There's a few things to check here. One of them is that when using shortcodes inside attributes, we currently have a limitation where we expect the attributes to be specified with single quotes. So this works:

---
title: test
keep-md: true
format: html
---

::: {.custom title='{{< meta title >}}'}
Content
:::

However, I think that is won't work for iconify, because we don't let extension shortcodes know the context in which they're resolving, and so iconify won't know that it's being called inside an attribute and so should return a string as result (rather than pandoc AST nodes).

@cscheid cscheid removed the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Jun 17, 2024
@mcanouil
Copy link
Collaborator Author

Hum the single quote "trick" does not seem to work at least in callouts.

image
---
title: "Hello, Quarto"
format: html
---

::: {.callout-note title='{{< meta title >}}'}
A note
:::

@cscheid cscheid modified the milestones: Future, v1.6 Jun 20, 2024
@cscheid
Copy link
Collaborator

cscheid commented Jul 2, 2024

What's going on

Shortcodes are processed in the shortcodes filter:

filter = shortcodes_filter(),

This shortcode filter does process shortcodes inside attributes; the issue is that by the time we get to the shortcodes filter, the content is no longer inside an attribute. That happens because custom AST nodes are processed in quarto_ast_pipeline, which is part of the normalization stage of our filter chain, and happens before shortcode filters.

We need that specific order, because shortcodes in the main markdown body are actually custom AST nodes (we made that design choice to fix old bugs like {{< video url--with_underscores_fails >}}). But that means that if a callout has attributes with shortcodes, then those need to be processed before the content of the attribute is resolved into Pandoc AST.

I don't like the fact that we'll have shortcode resolution happening in different stages, but I don't think we can avoid that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request shortcodes issues related to shortcodes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants