-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scrollspy. Wrap header and its content into section.
- Loading branch information
1 parent
97d844e
commit 67062aa
Showing
11 changed files
with
142 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
scaladoc/src/dotty/tools/scaladoc/site/FlexmarkSectionWrapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 com.vladsch.flexmark.util.options.MutableDataSet | ||
import collection.JavaConverters._ | ||
|
||
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SectionRenderingExtension.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dotty.tools.scaladoc | ||
package tasty.comments.markdown | ||
|
||
import com.vladsch.flexmark.html._ | ||
import com.vladsch.flexmark.html.renderer._ | ||
import com.vladsch.flexmark.parser._ | ||
import com.vladsch.flexmark.ext.wikilink._ | ||
import com.vladsch.flexmark.ext.wikilink.internal.WikiLinkLinkRefProcessor | ||
import com.vladsch.flexmark.util.ast._ | ||
import com.vladsch.flexmark.util.options._ | ||
import com.vladsch.flexmark.util.sequence.BasedSequence | ||
import com.vladsch.flexmark.util.html.AttributeImpl | ||
import com.vladsch.flexmark._ | ||
import com.vladsch.flexmark.ast.FencedCodeBlock | ||
|
||
|
||
object SectionRenderingExtension extends HtmlRenderer.HtmlRendererExtension: | ||
def rendererOptions(opt: MutableDataHolder): Unit = () | ||
|
||
case class AnchorLink(link: String) extends BlankLine(BasedSequence.EmptyBasedSequence()) | ||
object SectionHandler extends CustomNodeRenderer[Section]: | ||
val idGenerator = new HeaderIdGenerator.Factory().create() | ||
override def render(node: Section, c: NodeRendererContext, html: HtmlWriter): Unit = | ||
val Section(header, body) = node | ||
val id = idGenerator.getId(header.getText) | ||
val anchor = AnchorLink(s"#$id") | ||
header.prependChild(anchor) | ||
html.attr(AttributeImpl.of("id", id)).withAttr.tag("section", false, false, () => { | ||
c.render(header) | ||
body.foreach(c.render) | ||
}) | ||
|
||
object AnchorLinkHandler extends CustomNodeRenderer[AnchorLink]: | ||
override def render(node: AnchorLink, c: NodeRendererContext, html: HtmlWriter): Unit = | ||
html.attr(AttributeImpl.of("href", node.link), AttributeImpl.of("class", "anchor")).withAttr.tag("a", false, false, () => ()) | ||
|
||
|
||
object Render extends NodeRenderer: | ||
override def getNodeRenderingHandlers: JSet[NodeRenderingHandler[_]] = | ||
JSet( | ||
new NodeRenderingHandler(classOf[Section], SectionHandler), | ||
new NodeRenderingHandler(classOf[AnchorLink], AnchorLinkHandler) | ||
) | ||
|
||
object Factory extends NodeRendererFactory: | ||
override def create(options: DataHolder): NodeRenderer = Render | ||
|
||
def extend(htmlRendererBuilder: HtmlRenderer.Builder, tpe: String): Unit = | ||
htmlRendererBuilder.nodeRendererFactory(Factory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters