tut
tut copied to clipboard
fixShed doesn't work for indented fenced blocks
When a fenced code block is indented (as required if it's inside an enumeration), tut processes the code block, but doesn't replace tut by scala. This is because checkBoundary allows for leading spaces:
private def checkBoundary(text: String, find: String, code: Boolean, mods: Set[Modifier]): Tut[Unit] =
(text.trim.startsWith(find)).whenM(Tut.mod(s => s.copy(isCode = code, needsNL = false, mods = mods)))
but fixShed gets confused:
private def fixShed(text: String, mods: Set[Modifier]): String = {
val decorationMods = mods.filter(_.isInstanceOf[Decorate])
if (mods(Invisible)) {
""
} else if (text.startsWith("```tut")) { /*** should take leading spaces into account ***/
if (mods(Plain) || mods(Evaluated)) "```" else "```scala"
} else {
if (text.startsWith("```") && decorationMods.nonEmpty) {
val decorations = decorationMods map { case m: Decorate =>
m.decoration
case _ => ""
} mkString " "
s"""$text
|{: $decorations }""".stripMargin
}
else
text
}
}
Also, I just realized that code in indented fenced blocks doesn't get trimmed, which means the output will look like this:
scala> Set(1, 2).toList == Set(2, 1).toList
res0: Boolean = false
To the extent that tut supports indented fences at all it's just accidental. Markdown's handling of leading space seems to depend on the depth of the opening ``` and whether or not it's inside an enumeration, and it also involves inferring a closing ``` if it encounters interior lines that have an indent of 1 space or less. But that's just from playing around, it could be more complicated than that.
How do you think this should be handled? I can hang onto the indentation and delete that number of leading spaces from any interior lines I find, but I don't think it's worth trying to re-implement whatever other nutty stuff MD is doing.
Well, wait. It's more complicated than that. I need to trim the lines before processing them and then re-ident everything as it comes back from the REPL.
I can hang onto the indentation and delete that number of leading spaces from any interior lines I find, but I don't think it's worth trying to re-implement whatever other nutty stuff MD is doing.
Sounds good to me.