Skip to content

Commit 85da84f

Browse files
committed
Add support for rendered description
The description supports markdown inlines.
1 parent e252d7f commit 85da84f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

_extensions/quarto-ext/lightbox/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: Lightbox
22
author: RStudio, PBC
3-
version: 0.1.4
3+
version: 0.1.5
44
quarto-required: ">=1.2.198"
55
contributes:
66
filters:

_extensions/quarto-ext/lightbox/lightbox.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ local needsLightbox = false
88
local imgCount = 0
99

1010
-- attributes to forward from the image to the newly created link
11+
local kDescription = "description"
1112
local kForwardedAttr = {
12-
"title", "description", "desc-position",
13+
"title", kDescription, "desc-position",
1314
"type", "effect", "zoomable", "draggable"
1415
}
1516

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

24+
local function readAttrValue(el, attrName)
25+
if attrName == kDescription then
26+
local doc = pandoc.read(el.attr.attributes[attrName])
27+
local attrInlines = doc.blocks[1].content
28+
return pandoc.write(pandoc.Pandoc(attrInlines), "html")
29+
else
30+
return el[attrName]
31+
end
32+
33+
end
34+
2335
return {
2436
{
2537
Meta = function(meta)
@@ -137,8 +149,8 @@ return {
137149
for i, v in ipairs(kForwardedAttr) do
138150
if imgEl.attr.attributes[v] ~= nil then
139151
-- forward the attribute
140-
linkAttributes[v] = imgEl.attr.attributes[v]
141-
152+
linkAttributes[v] = readAttrValue(imgEl, v)
153+
142154
-- clear the attribute
143155
imgEl.attr.attributes[v] = nil
144156
end

example.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Here is a simple image with a description. This also overrides the
1111
description position and places it to the left of the image.
1212

1313
![Beach in
14-
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."
14+
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)"
1515
desc-position="left"}
1616

1717
## Elsewhere

0 commit comments

Comments
 (0)