Markdown: table of contents with duplicate section titles

If a document uses the same subsection title underneath multiple sections
(e.g. an H3 section "Examples" repeated under each H2 section) gracefully
support this by prefixing the id with the titles of the parent sections.

If this is still insufficient to get unique id anchors number them using
-1, -2, -3, etc. suffixes based on order within the document.

Bug: issue 75
Change-Id: I6cfa92b0b3ae881a7e4e46f9440dcaaa0b0bb7f3
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownToHtml.java b/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownToHtml.java
index 2ff8aeb..89a2b36 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownToHtml.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/doc/MarkdownToHtml.java
@@ -172,7 +172,10 @@
   public void visit(HeaderNode node) {
     String tag = "h" + node.getLevel();
     html.open(tag);
-    html.attribute("id", toc.idFromHeader(node));
+    String id = toc.idFromHeader(node);
+    if (id != null) {
+      html.attribute("id", id);
+    }
     visitChildren(node);
     html.close(tag);
   }