Skip to content

Commit

Permalink
Add support for rendered description
Browse files Browse the repository at this point in the history
The description supports markdown inlines.
  • Loading branch information
dragonstyle committed Oct 31, 2022
1 parent e252d7f commit 85da84f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion _extensions/quarto-ext/lightbox/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: Lightbox
author: RStudio, PBC
version: 0.1.4
version: 0.1.5
quarto-required: ">=1.2.198"
contributes:
filters:
Expand Down
18 changes: 15 additions & 3 deletions _extensions/quarto-ext/lightbox/lightbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ local needsLightbox = false
local imgCount = 0

-- attributes to forward from the image to the newly created link
local kDescription = "description"
local kForwardedAttr = {
"title", "description", "desc-position",
"title", kDescription, "desc-position",
"type", "effect", "zoomable", "draggable"
}

Expand All @@ -20,6 +21,17 @@ local kGalleryPrefix = "quarto-lightbox-gallery-"
-- A list of images already within links that we can use to filter
local imagesWithinLinks = pandoc.List({})

local function readAttrValue(el, attrName)
if attrName == kDescription then
local doc = pandoc.read(el.attr.attributes[attrName])
local attrInlines = doc.blocks[1].content
return pandoc.write(pandoc.Pandoc(attrInlines), "html")
else
return el[attrName]
end

end

return {
{
Meta = function(meta)
Expand Down Expand Up @@ -137,8 +149,8 @@ return {
for i, v in ipairs(kForwardedAttr) do
if imgEl.attr.attributes[v] ~= nil then
-- forward the attribute
linkAttributes[v] = imgEl.attr.attributes[v]

linkAttributes[v] = readAttrValue(imgEl, v)
-- clear the attribute
imgEl.attr.attributes[v] = nil
end
Expand Down
2 changes: 1 addition & 1 deletion example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Here is a simple image with a description. This also overrides the
description position and places it to the left of the image.

![Beach in
Chilmark](images/mv-0.jpg){description="Chilmark has a reputation as having some of the best beaches on Martha's Vineyard. Chilmark beaches are resident only in the summer, so be sure to have your proof of residency ready if you'd like to visit one of these special places."
Chilmark](images/mv-0.jpg){description="Chilmark has a reputation as having some of the best beaches on Martha's Vineyard. Chilmark beaches are resident only in the summer, so be sure to have your proof of residency ready if you'd like to visit one of these special places. _credit:_ [Chilmark Beach](https://unsplash.com/photos/VBDJGOMCwps)"
desc-position="left"}

## Elsewhere
Expand Down

0 comments on commit 85da84f

Please sign in to comment.