1010/**
1111 * Extension for adding auto generated IDs to headings.
1212 * <p>
13- * Create it with {@link #create()} and then configure it on the builder
14- * {@link HtmlRenderer.Builder#extensions(Iterable)}).
13+ * Create it with {@link #create()} or {@link #builder()} and then configure it on the
14+ * renderer builder ( {@link HtmlRenderer.Builder#extensions(Iterable)}).
1515 * <p>
1616 * The heading text will be used to create the id. Multiple headings with the
1717 * same text will result in appending a hyphen and number. For example:
@@ -33,20 +33,22 @@ public class HeadingAnchorExtension implements HtmlRenderer.HtmlRendererExtensio
3333 private final String idPrefix ;
3434 private final String idSuffix ;
3535
36- private HeadingAnchorExtension (String defaultId , String idPrefix , String idSuffix ) {
37- this .defaultId = defaultId ;
38- this .idPrefix = idPrefix ;
39- this .idSuffix = idSuffix ;
36+ private HeadingAnchorExtension (Builder builder ) {
37+ this .defaultId = builder . defaultId ;
38+ this .idPrefix = builder . idPrefix ;
39+ this .idSuffix = builder . idSuffix ;
4040 }
4141
42+ /**
43+ * @return the extension built with default settings
44+ */
4245 public static Extension create () {
43- return create (builder ());
44- }
45-
46- private static Extension create (Builder builder ) {
47- return new HeadingAnchorExtension (builder .defaultId , builder .idPrefix , builder .idSuffix );
46+ return new HeadingAnchorExtension (builder ());
4847 }
4948
49+ /**
50+ * @return a builder to configure the extension settings
51+ */
5052 public static Builder builder () {
5153 return new Builder ();
5254 }
@@ -62,15 +64,9 @@ public AttributeProvider create(AttributeProviderContext context) {
6264 }
6365
6466 public static class Builder {
65- private String defaultId ;
66- private String idPrefix ;
67- private String idSuffix ;
68-
69- public Builder () {
70- defaultId = "id" ;
71- idPrefix = "" ;
72- idSuffix = "" ;
73- }
67+ private String defaultId = "id" ;
68+ private String idPrefix = "" ;
69+ private String idSuffix = "" ;
7470
7571 /**
7672 * @param value Default value for the id to take if no generated id can be extracted. Default "id"
@@ -92,15 +88,18 @@ public Builder idPrefix(String value) {
9288
9389 /**
9490 * @param value Set the value to be appended to every id generated. Default ""
95- * @return
91+ * @return {@code this}
9692 */
9793 public Builder idSuffix (String value ) {
9894 this .idSuffix = value ;
9995 return this ;
10096 }
10197
98+ /**
99+ * @return a configured extension
100+ */
102101 public Extension build () {
103- return HeadingAnchorExtension . create (this );
102+ return new HeadingAnchorExtension (this );
104103 }
105104 }
106105}
0 commit comments