package org.commonmark.ext.heading.anchor;

import org.commonmark.Extension;
import org.commonmark.ext.heading.anchor.internal.HeadingIdAttributeProvider;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.renderer.html.AttributeProvider;
import org.commonmark.renderer.html.AttributeProviderContext;
import org.commonmark.renderer.html.AttributeProviderFactory;

/**
 * Extension for adding auto generated IDs to headings.
 * <p>
 * Create it with {@link #create()} and then configure it on the builder
 * {@link HtmlRenderer.Builder#extensions(Iterable)}).
 * </p>
 * <p>
 * The heading text will be used to create the id. Multiple headings with the
 * same text will result in appending a hyphen and number. For example:
 * </p>
 * <code>
 * <pre>
 * # Heading
 * # Heading
 * </pre>
 * </code>
 * will result in
 * <code>
 * <pre>
 * &lt;h1 id="heading"&gt;Heading&lt;/h1&gt;
 * &lt;h1 id="heading-1"&gt;Heading&lt;/h1&gt;
 * </pre>
 * </code>
 *
 * @see IdGenerator the IdGenerator class if just the ID generation part is needed
 */
public class HeadingAnchorExtension implements HtmlRenderer.HtmlRendererExtension {

    private HeadingAnchorExtension() {
    }

    public static Extension create() {
        return new HeadingAnchorExtension();
    }

    @Override
    public void extend(HtmlRenderer.Builder rendererBuilder) {
        rendererBuilder.attributeProviderFactory(new AttributeProviderFactory() {
            @Override
            public AttributeProvider create(AttributeProviderContext context) {
                return HeadingIdAttributeProvider.create();
            }
        });
    }
}

@@ -152,58 +152,8 @@
 er;%0A
-import org.commonmark.renderer.html.HtmlRenderer;%0A
 impo
@@ -326,16 +326,66 @@
 Factory;
+%0Aimport org.commonmark.renderer.html.HtmlRenderer;
 %0A%0A/**%0A *
@@ -573,24 +573,16 @@
 ble)%7D).%0A
- * %3C/p%3E%0A
  * %3Cp%3E%0A 
@@ -738,28 +738,16 @@
  * %3C
-/p%3E%0A * %3Ccode%3E%0A * %3Cpr
+pre%3E%3Ccod
 e%3E%0A 
@@ -772,37 +772,33 @@
 eading%0A * %3C/
-pre%3E%0A * %3C/cod
+code%3E%3C/pr
 e%3E%0A * will r
@@ -814,20 +814,16 @@
  * %3C
-code%3E%0A * %3Cpr
+pre%3E%3Ccod
 e%3E%0A 
@@ -922,21 +922,17 @@
 * %3C/
-pre%3E%0A * %3C/cod
+code%3E%3C/pr
 e%3E%0A 

Fix Javadoc problems