Skip to content

Commit 22e6973

Browse files
committed
Add image license info as figure captions
1 parent 7d21fe9 commit 22e6973

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+106
-17
lines changed

build.scala

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,24 @@ object LaikaCustomizations {
196196
)
197197
}
198198

199-
val overrides = HTML.Overrides { case (fmt, h: Header) =>
200-
addAnchorLinks(fmt, h)
199+
def renderFigure(fmt: TagFormatter, fig: Figure) = {
200+
val renderedImg = HTML.defaultRenderer(fmt, fig.image)
201+
val contentBlock = BlockSequence(fig.content)
202+
val renderedContent = HTML.defaultRenderer(fmt, contentBlock)
203+
val renderedCaption =
204+
fmt.rawElement("figcaption", contentBlock, renderedContent)
205+
fmt.rawElement(
206+
"figure",
207+
fig.clearOptions,
208+
s"${renderedImg}\n${renderedCaption}"
209+
)
210+
}
211+
212+
val overrides = HTML.Overrides {
213+
case (fmt, h: Header) =>
214+
addAnchorLinks(fmt, h)
215+
case (fmt, f: Figure) =>
216+
renderFigure(fmt, f)
201217
}
202218

203219
object RssExtensions extends ExtensionBundle {
@@ -284,6 +300,29 @@ object LaikaCustomizations {
284300
Styles("bulma-has-text-centered")
285301
)
286302
}
303+
},
304+
BlockDirectives.create("figure") {
305+
import BlockDirectives.dsl.*
306+
(
307+
attribute(0).as[String].widen,
308+
attribute("intrinsicWidth").as[Double].optional,
309+
attribute("intrinsicHeight").as[Double].optional,
310+
attribute("style").as[String].optional,
311+
attribute("alt").as[String].optional,
312+
attribute("title").as[String].optional,
313+
parsedBody,
314+
cursor
315+
).mapN { (src, width, height, style, alt, title, body, cursor) =>
316+
val img = Image(
317+
InternalTarget(VirtualPath.parse(src)).relativeTo(cursor.path),
318+
width.map(LengthUnit.px(_)),
319+
height.map(LengthUnit.px(_)),
320+
alt,
321+
title
322+
)
323+
val options = Styles(style.getOrElse("default-image-block"))
324+
Figure(SpanSequence(img), Seq.empty, body, options)
325+
}
287326
}
288327
)
289328
}

src/blog/conf-cadiz-2016-09-30.md

Lines changed: 1 addition & 1 deletion

src/blog/conf-cadiz-2017-10-26.md

Lines changed: 1 addition & 1 deletion

src/blog/lake-district-workshop-2016-09-14.md

Lines changed: 1 addition & 1 deletion

src/blog/meetup-lausanne-2025-08-22.md

Lines changed: 1 addition & 1 deletion

src/blog/scala-io-2016-10-27.md

Lines changed: 1 addition & 1 deletion

src/blog/scalaxhack-2016-12-10.md

Lines changed: 1 addition & 1 deletion

src/blog/summit-berlin-2018-05-18.md

Lines changed: 1 addition & 1 deletion

src/blog/summit-boston-2018-03-20.md

Lines changed: 1 addition & 1 deletion

src/blog/summit-copenhagen-2017-06-03.md

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)