All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.scaladoc.site.FlexmarkSectionWrapper.scala Maven / Gradle / Ivy

There is a newer version: 3.6.3-RC1-bin-20241114-6a7d5d3-NIGHTLY
Show newest version
package dotty.tools.scaladoc
package site

import com.vladsch.flexmark.util.{ast => mdu, sequence}
import com.vladsch.flexmark.{ast => mda}
import com.vladsch.flexmark.formatter.Formatter
import scala.jdk.CollectionConverters._

import dotty.tools.scaladoc.tasty.comments.markdown.Section

object FlexmarkSectionWrapper {
  def apply(md: mdu.Document): mdu.Document = {
    val children = md.getChildren.asScala.toList
    val newChildren = getNewChildren(Nil, None, children)
    md.removeChildren()
    newChildren.foreach(md.appendChild)
    md
  }

  def getNewChildren(finished: List[mdu.Node], current: Option[(mda.Heading, List[mdu.Node])], rest: List[mdu.Node]): List[mdu.Node] = rest match {
    case Nil => current.fold(finished)(finished :+ Section(_, _))
    case (h: mda.Heading) :: rest => current.fold(getNewChildren(finished, Some(h, Nil), rest))((head, b) => getNewChildren(finished :+ Section(head, b), Some(h, Nil), rest))
    case (n: mdu.Node) :: rest => current.fold(getNewChildren(finished :+ n, None, rest))((head, b) => getNewChildren(finished, Some(head, b :+ n), rest))
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy