Skip to content

GLightbox options cause HTML output to change #11122

Description

@winniehell

Bug description

Order of GLightbox options changes on (almost) every HTML rendering. This may sound like a minor cosmetic detail but it causes the checksum of the output file to change and therefore makes caching more difficult.

Steps to reproduce

Use any document containing an image, e.g.

---
title: "Empty"
format: html
engine: jupyter
---

![An image]()

run the following commands:

quarto render --to html --output-dir output1
quarto render --to html --output-dir output2  # you may need to run this step more than once
diff output1/index.html output2/index.html

Expected behavior

Output does not differ because input has not changed.

Actual behavior

Order of GLightbox options is changed, e.g.

515c515
< <script>var lightboxQuarto = GLightbox({"selector":".lightbox","descPosition":"bottom","loop":false,"closeEffect":"zoom","openEffect":"zoom"});
---
> <script>var lightboxQuarto = GLightbox({"loop":false,"selector":".lightbox","openEffect":"zoom","descPosition":"bottom","closeEffect":"zoom"});

Your environment

nixos-version: 24.05.20241012.a3f9ad6 (Uakari)

Quarto check output

quarto check
Quarto 99.9.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 71945532e1fc1a5cf113117f6d5ff5bee3991797
      Path: ~/quarto-cli/package/dist/bin

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

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /run/current-system/sw/bin
      Version: undefined

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.5
      Path: ~/quarto-playground/.venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] 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/

Activity

  1. winniehell commented on Oct 20, 2024

    @winniehell
    ContributorAuthor

    I don't know Lua but using pairsByKeys for optionsJson may solve the problem:

    -- https://www.lua.org/pil/19.3.html
    local pairsByKeys = function (t, f)

    local optionsJson = quarto.json.encode(options)
    -- generate the initialization script with the correct options
    local scriptTag = "<script>var lightboxQuarto = GLightbox(" .. optionsJson .. ");</script>"

    -      local optionsJson = quarto.json.encode(options)
    +      local optionsJson = pairsByKeys(quarto.json.encode(options))
  2. mcanouil commented on Oct 20, 2024

    @mcanouil
    Collaborator

    Thanks, I thought I add open an issue about this four months ago but apparently not since I can't find it ...

    Here the relevant comments/codes from the previous discussion:

    • -- Generate the options to configure lightbox
      local options = {
      selector = selector,
      closeEffect = effect,
      openEffect = effect,
      descPosition = descPosition,
      loop = loop,
      }
      if skin ~= nil then
      options.skin = skin
      end
      local optionsJson = quarto.json.encode(options)

    • we have implemented sortedPairs multiple times throughout the codebase... we should pull it into quarto.utils.table and then just use that

      • local function sortedPairs(t, f)
        local a = {}
        for n in pairs(t) do table.insert(a, n) end
        table.sort(a, f)
        local i = 0 -- iterator variable
        local iter = function() -- iterator function
        i = i + 1
        if a[i] == nil then return nil
        else return a[i], t[a[i]]
        end
        end
        return iter
        end
  3. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Oct 20, 2024
  4. winniehell commented on Oct 20, 2024

    @winniehell
    ContributorAuthor

    I made an attempt to fix this in #11124

  5. added this to the v1.6 milestone on Oct 21, 2024
  6. self-assigned this
    on Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions