@@ -284,22 +284,19 @@ object LaikaCustomizations {
284284 val spanDirectives = Seq (
285285 SpanDirectives .create(" math" ) {
286286 import SpanDirectives .dsl .*
287- rawBody.map { body =>
288- RawContent (
289- NonEmptySet .of(" html" , " rss" ),
290- KaTeX (body, false )
287+ rawBody.evalMap { body =>
288+ KaTeX (body, false ).map(katexStr =>
289+ RawContent (NonEmptySet .of(" html" , " rss" ), katexStr)
291290 )
292291 }
293292 }
294293 )
295294 val blockDirectives = Seq (
296295 BlockDirectives .create(" math" ) {
297296 import BlockDirectives .dsl .*
298- rawBody.map { body =>
299- RawContent (
300- NonEmptySet .of(" html" , " rss" ),
301- KaTeX (body, true ),
302- Styles (" bulma-has-text-centered" )
297+ rawBody.evalMap { body =>
298+ KaTeX (body, true ).map(katexStr =>
299+ RawContent (NonEmptySet .of(" html" , " rss" ), katexStr, Styles (" bulma-has-text-centered" ))
303300 )
304301 }
305302 },
@@ -438,14 +435,18 @@ object KaTeX {
438435 ctx.getBindings(" js" ).getMember(" katex" )
439436 }
440437
441- def apply (latex : String , displayMode : Boolean = false ): String =
438+ def apply (latex : String , displayMode : Boolean = false ): Either [ String , String ] =
442439 synchronized {
443440 val options = Map (
444441 " throwOnError" -> true ,
445442 " strict" -> true ,
446443 " displayMode" -> displayMode
447- )
448- katex.invokeMember(" renderToString" , latex, options.asJava).asString
444+ ).asJava
445+ try {
446+ Right (katex.invokeMember(" renderToString" , latex, options).asString)
447+ } catch {
448+ case ex : Exception => Left (ex.getMessage)
449+ }
449450 }
450451
451452}
0 commit comments