Skip to content

Commit

Permalink
fixed formatting of page headers with code
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 2, 2024
1 parent 76285a7 commit 0ff17b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/api-guide/directory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ laika.navigationOrder = [
generic.md
syntax.md
position.md
registers.md
state.md
expr
token
errors
Expand Down
File renamed without changes.
27 changes: 17 additions & 10 deletions project/ParsleySitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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("<title>") =>
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
}
}
}

0 comments on commit 0ff17b7

Please sign in to comment.