Skip to content

render-time section name given partial anchor #8546

Closed as not planned
Closed as not planned

Description

@aronatkins

Bug description

When a section name is partially defined by a shortcode (env, for example) that dynamic portion of the name is not included in the anchor for that section.

Steps to reproduce

---
title: anchors
format:
  html:
    toc: true
---

## version {{< env VERSION >}}

section something

## version 2023.12.0

section 2023.12.0

Render like:

VERSION=2024.01.0 quarto render

Expected behavior

The document contains #version-2024.01.0 and version-2023.12.0 anchors.

Actual behavior

The document contains #version and version-2023.12.0 anchors.

Your environment

No response

Quarto check output

Quarto 1.4.549
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.549
      Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/aron/Library/TinyTeX/bin/universal-darwin
      Version: 2022

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

[✓] Checking Python 3 installation....OK
      Version: 3.11.7
      Path: /usr/local/opt/[email protected]/bin/python3.11
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
      knitr: 1.45
      rmarkdown: 2.25

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

Activity

  1. added
    bug
    on Feb 1, 2024
  2. aronatkins commented on Feb 1, 2024

    @aronatkins
    ContributorAuthor

    Attempting to use {# ... } is not successful.

    ## version {{< env VERSION >}} {#version-{{< env VERSION >}}}

    This misses the {# ...} and produces HTML with the anchor #version-version-:

    <h2 class="anchored" data-anchor-id="version-version-">version 2024.01.0 {#version-2024.01.0}</h2>
  3. added this to the v1.5 milestone on Feb 1, 2024
  4. aronatkins commented on Feb 1, 2024

    @aronatkins
    ContributorAuthor

    @cscheid - no, the whitespace between < and env does not matter. That variation is in this example but wasn't in my original document. I'll correct the text in this issue to have whitespace so that's not questioned.

  5. cscheid commented on Feb 1, 2024

    @cscheid
    Member

    This is more than a shortcode issue. We don't update the section heading identifiers if their content changes in a filter (which is the case with shortcode evaluation)

  6. cscheid commented on Feb 1, 2024

    @cscheid
    Member

    consider:

    ---
    title: anchors
    format:
      html:
        toc: true
    filters:
      - headings.lua
    ---
    
    ## a heading
    
    Hello something.
    -- headings.lua
    function Header(header)
        header.content = quarto.utils.as_inlines(pandoc.Str("A different heading"))
        return header
    end

    This gives

    <section id="a-heading" class="level2">
    <h2 class="anchored" data-anchor-id="a-heading">A different heading
    ...
    </h2>
    <p>Hello something.</p>
    </section>
    

    I'm not sure if it's enough to change the heading identifier in a filter.

  7. cscheid commented on Feb 1, 2024

    @cscheid
    Member

    Yeah, this is tricky.

    Heading identifiers are used to create crossref indices, so we need to be careful about which parts of our filter pipeline expect identifiers to be stable. We also need to be sure that we're using precisely the same algorithm that Pandoc uses to generate the ids, since this risks regressing on IDs of every website out there.

    I'm inclined to say we're not going to consider this a bug, and recommend you set those identifiers yourself unless there's a very compelling reason to do it.

  8. removed this from the v1.5 milestone on Feb 1, 2024
  9. removed
    bug
    on Feb 1, 2024
  10. aronatkins commented on Feb 2, 2024

    @aronatkins
    ContributorAuthor

    @cscheid - Do you have a recommended way to use an environment variable value within a section heading and its anchor without dropping to R/Python?

    We use this approach when generating a release-notes page; the "current" version is generated dynamically and injected by the build script into the environment provided to Quarto.

    If you don't see a straightforward path, we'll have to shift back to static identifiers. Not a terrible change, but would require some adjustment to our tooling.

  11. cscheid commented on Feb 2, 2024

    @cscheid
    Member

    Do you have a recommended way to use an environment variable value within a section heading and its anchor without dropping to R/Python?

    I'd consider a Lua filter. Unfortunately, we don't have a great Lua filter entry point that targets precisely what you need.

    A Lua filter that's declared at: pre-quarto would see the heading content (and identifiers) before shortcodes are resolved. Here, you can change the identifier without risking crossref issues, but you don't see the shortcode resolution.

    A Lua filter that's declared at: post-quarto would see the heading content (and identifiers) after shortcodes are resolved. Here, you see the shortcode resolution but if you change the identifier, then crossref entries might be corrupted.

  12. added
    wontfix
    on Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions