@Test public void computeHeadingId() { assertEquals("", AsciiDocIdGenerationStrategy.computeHeadingId("", "", "_")); assertEquals("lorem ipsum", AsciiDocIdGenerationStrategy.computeHeadingId("lorem ipsum", null, null)); assertEquals("some_h2", AsciiDocIdGenerationStrategy.computeHeadingId("SOME H2", "", "_")); assertEquals("_this-is-an-h2", AsciiDocIdGenerationStrategy.computeHeadingId("This is an H2", "_", "-")); assertEquals("_test_2", AsciiDocIdGenerationStrategy.computeHeadingId("test 2", "_", "_")); }
static String computeHeadingId(String text, String idprefix, String idseparator) { StringBuilder sb = new StringBuilder(); if (idprefix != null) { sb.append(idprefix); } String anchor = parseToHtml(text); anchor = anchor.trim(); if (anchor.startsWith("<p>")) { anchor = anchor.substring(3); } if (anchor.endsWith("</p>")) { anchor = anchor.substring(0, anchor.length() - 4); } anchor = anchor.replaceAll("[^\\w]", " "); anchor = anchor.trim(); anchor = anchor.toLowerCase(); if (idseparator != null) { anchor = anchor.replaceAll("\\s+", idseparator); } sb.append(anchor); return sb.toString(); }
AsciiDocIdGenerationStrategy extends IdGenerationStrategy { static String computeHeadingId(String text, String idprefix, String idseparator) { StringBuilder sb = new StringBuilder(); if (idprefix != null) { sb.append(idprefix); } String anchor = parseToHtml(text); anchor = anchor.trim(); if (anchor.startsWith("<p>")) { anchor = anchor.substring(3); } if (anchor.endsWith("</p>")) { anchor = anchor.substring(0, anchor.length() - 4); } anchor = anchor.replaceAll("[^\\w]", " "); anchor = anchor.trim(); anchor = anchor.toLowerCase(); if (idseparator != null) { anchor = anchor.replaceAll("\\s+", idseparator); } sb.append(anchor); return sb.toString(); } }
AsciiDocIdGenerationStrategy extends IdGenerationStrategy { static String computeHeadingId(String text, String idprefix, String idseparator) { StringBuilder sb = new StringBuilder(); if (idprefix != null) { sb.append(idprefix); } String anchor = parseToHtml(text); anchor = anchor.trim(); if (anchor.startsWith("<p>")) { anchor = anchor.substring(3); } if (anchor.endsWith("</p>")) { anchor = anchor.substring(0, anchor.length() - 4); } anchor = anchor.replaceAll("[^\\w]", " "); anchor = anchor.trim(); anchor = anchor.toLowerCase(); if (idseparator != null) { anchor = anchor.replaceAll("\\s+", idseparator); } sb.append(anchor); return sb.toString(); }  }
AsciiDocIdGenerationStrategy extends IdGenerationStrategy { static String computeHeadingId(String text, String idprefix, String idseparator) { StringBuilder sb = new StringBuilder(); if (idprefix != null) { sb.append(idprefix); } String anchor = parseToHtml(text); anchor = anchor.trim(); if (anchor.startsWith("<p>")) { anchor = anchor.substring(3); } if (anchor.endsWith("</p>")) { anchor = anchor.substring(0, anchor.length() - 4); } anchor = anchor.replaceAll("[^\\w]", " "); anchor = anchor.trim(); anchor = anchor.toLowerCase(); if (idseparator != null) { anchor = anchor.replaceAll("\\s+", idseparator); } sb.append(anchor); return sb.toString(); }  void setIdPrefix(String idPrefix); void setIdSeparator(String idSeparator); @Override String generateId(String headingText); }
AsciiDocIdGenerationStrategy extends IdGenerationStrategy { static String computeHeadingId(String text, String idprefix, String idseparator) { StringBuilder sb = new StringBuilder(); if (idprefix != null) { sb.append(idprefix); } String anchor = parseToHtml(text); anchor = anchor.trim(); if (anchor.startsWith("<p>")) { anchor = anchor.substring(3); } if (anchor.endsWith("</p>")) { anchor = anchor.substring(0, anchor.length() - 4); } anchor = anchor.replaceAll("[^\\w]", " "); anchor = anchor.trim(); anchor = anchor.toLowerCase(); if (idseparator != null) { anchor = anchor.replaceAll("\\s+", idseparator); } sb.append(anchor); return sb.toString(); }  void setIdPrefix(String idPrefix); void setIdSeparator(String idSeparator); @Override String generateId(String headingText);  }