From 0ff17b7a7270057ef59c3c3009fe98241e74efb7 Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Tue, 2 Jan 2024 16:33:24 +0000 Subject: [PATCH] fixed formatting of page headers with code --- docs/api-guide/directory.conf | 2 +- docs/api-guide/{registers.md => state.md} | 0 project/ParsleySitePlugin.scala | 27 ++++++++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) rename docs/api-guide/{registers.md => state.md} (100%) diff --git a/docs/api-guide/directory.conf b/docs/api-guide/directory.conf index 2a0db9e31..9fed597ca 100644 --- a/docs/api-guide/directory.conf +++ b/docs/api-guide/directory.conf @@ -5,7 +5,7 @@ laika.navigationOrder = [ generic.md syntax.md position.md - registers.md + state.md expr token errors diff --git a/docs/api-guide/registers.md b/docs/api-guide/state.md similarity index 100% rename from docs/api-guide/registers.md rename to docs/api-guide/state.md diff --git a/project/ParsleySitePlugin.scala b/project/ParsleySitePlugin.scala index c7fcb5fed..0edfd5f0b 100644 --- a/project/ParsleySitePlugin.scala +++ b/project/ParsleySitePlugin.scala @@ -176,15 +176,22 @@ object Icon { object Renderers { import laika.api.format.TagFormatter val backticksToCode: PartialFunction[(TagFormatter, Element), String] = { - // TODO: generalise to work with backticks within code - case (fmt, Text(content, opt)) if content.startsWith("`") && content.endsWith("`") => - val tickless = content.init.tail - fmt.parents.lift(2) match { - // title of the page? - // FIXME: on the updated laika, this doesn't properly address the backticks problem, because of the new sanitisation - case Some(TemplateSpanSequence(TemplateString(cousin, _) +: _, _)) if cousin.endsWith("") => - fmt.text(tickless) - case _ => fmt.withoutIndentation(_.textElement("code", Text(tickless).withOptions(opt))) - } + // this is somewhere, and needs to be code + case (fmt, Text(Ticked(tickless), opt)) => fmt.withoutIndentation(_.textElement("code", Text(tickless).withOptions(opt))) + // page title + case (isTitleText(fmt), TemplateString(Ticked(tickless), opt)) => fmt.text(tickless) + } + + private object isTitleText { + def unapply(fmt: TagFormatter): Option[TagFormatter] = fmt.parents.headOption.collect { + case TemplateSpanSequence(TemplateString(cousin, _) +: _, _) if cousin.endsWith("<title>") => fmt + } + } + + private object Ticked { + def unapply(str: String): Option[String] = { + if (str.startsWith("`") && str.endsWith("`")) Some(str.init.tail) + else None + } } }