diff options
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala index ac2b6fc6d..e33488e02 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala @@ -3,14 +3,36 @@ package dottydoc package staticsite import com.vladsch.flexmark.ast._ +import com.vladsch.flexmark.util.sequence.CharSubSequence +import model.{ Package, NonEntity, Val, Def, TypeAlias } +import dottydoc.util.MemberLookup object MarkdownLinkVisitor { - def apply(node: Node): Unit = + private val EntityLink = """([^\.]+)(\.[^\.]+)*""".r + def apply(node: Node, docs: Map[String, Package], params: Map[String, AnyRef]): Unit = (new NodeVisitor( - new VisitHandler(classOf[Link], new Visitor[Link] { + new VisitHandler(classOf[Link], new Visitor[Link] with MemberLookup { override def visit(node: Link): Unit = { val url = node.getUrl - if (url.endsWith(".md")) node.setUrl { + if (EntityLink.unapplySeq(url.toString).isDefined) { + lookup(NonEntity, docs, url.toString).foreach { ent => + val (path, suffix) = ent match { + case ent: Val => (ent.path.dropRight(1), ".html#" + ent.signature) + case ent: Def => (ent.path.dropRight(1), ".html#" + ent.signature) + case ent: TypeAlias => (ent.path.dropRight(1), ".html#" + ent.signature) + case ent: Package => (ent.path, "/index.html") + case ent => (ent.path, ".html") + } + + params("site") match { + case map: java.util.Map[String, String] @unchecked => node.setUrl { + CharSubSequence.of(path.mkString(map.get("baseurl") + "/api/", "/", suffix)) + } + case _ => () + } + } + } + else if (url.endsWith(".md")) node.setUrl { url.subSequence(0, url.lastIndexOf('.')).append(".html") } } |