Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

fixShed doesn't work for indented fenced blocks #147

Open
larsrh opened this issue Mar 19, 2017 · 4 comments
Open

fixShed doesn't work for indented fenced blocks #147

larsrh opened this issue Mar 19, 2017 · 4 comments

Comments

@larsrh
Copy link
Contributor

larsrh commented Mar 19, 2017

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
    }
  }
@larsrh
Copy link
Contributor Author

larsrh commented Mar 19, 2017

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

@tpolecat
Copy link
Owner

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.

@tpolecat
Copy link
Owner

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.

@larsrh
Copy link
Contributor Author

larsrh commented Mar 20, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants