@@ -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 }
0 commit comments