Markdown: render pages under /+doc/ Parse and render any file ending with ".md" as markdown using the pegdown processor. This allows a repository to be used as a documentation source. If "navbar.md" is found in the top level directory it is rendered as a horizontal bar across the top of the page. A navbar.md is an outline: * [Home](/index.md) * [APIs](/api/index.md) * [Source](/src/main/java/index.md) Any links starting with "/" and ending in ".md" are resolved as relative to the top of the Git repository. As an extension to Markdown the special block [TOC] is replaced with a table of contents from the headers of the text. Markdown support can be optionally disabled by setting the config variable markdown.render to false. Change-Id: Ic111628c59cfadfdca37bf0cc637ee8a14d54c37
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownHelper.java b/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownHelper.java index 6d67505..e7566f5 100644 --- a/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownHelper.java +++ b/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownHelper.java
@@ -16,6 +16,7 @@ import com.google.common.base.Strings; +import org.pegdown.ast.HeaderNode; import org.pegdown.ast.Node; import org.pegdown.ast.TextNode; @@ -48,6 +49,23 @@ } } + static String getTitle(Node node) { + if (node instanceof HeaderNode) { + if (((HeaderNode) node).getLevel() == 1) { + return getInnerText(node); + } + return null; + } + + for (Node child : node.getChildren()) { + String title = getTitle(child); + if (title != null) { + return title; + } + } + return null; + } + private MarkdownHelper() { } }