You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kw...@apache.org on 2023/11/28 19:15:35 UTC

(maven-doxia-site) branch feature/auto-generate-anchors-for-toc created (now 8fd3425)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a change to branch feature/auto-generate-anchors-for-toc
in repository https://gitbox.apache.org/repos/asf/maven-doxia-site.git


      at 8fd3425  [DOXIASITETOOLS-320] Document Sink wrappers and the automatic generation of anchor names for TOC entries

This branch includes the following new commits:

     new 8fd3425  [DOXIASITETOOLS-320] Document Sink wrappers and the automatic generation of anchor names for TOC entries

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-doxia-site) 01/01: [DOXIASITETOOLS-320] Document Sink wrappers and the automatic generation of anchor names for TOC entries

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/auto-generate-anchors-for-toc
in repository https://gitbox.apache.org/repos/asf/maven-doxia-site.git

commit 8fd3425b3e8b38c3ef19a8c07a6fe82fefd04595
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Nov 28 20:15:28 2023 +0100

    [DOXIASITETOOLS-320] Document Sink wrappers and the automatic generation
    of anchor names for TOC entries
---
 content/apt/developers/sink.apt | 43 +++++++++++++++++++++++++++++++++++++++++
 content/apt/macros/index.apt    |  7 ++-----
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/content/apt/developers/sink.apt b/content/apt/developers/sink.apt
index 479f4a8..8eef12b 100644
--- a/content/apt/developers/sink.apt
+++ b/content/apt/developers/sink.apt
@@ -196,6 +196,49 @@ sink.unknown( "cdata", new Object[]{new Integer( HtmlMarkup.CDATA_TYPE ), javasc
 sink.unknown( "script", new Object[]{new Integer( HtmlMarkup.TAG_TYPE_END )}, null );
 +----
 
+* {Using Sink wrappers}
+
+  One or multiple Sink wrappers can be registered with a parser to optionally enrich or modify the output emitted to the sink.
+  Each sink wrapper is responsible for calling its subsequent sink (either again a wrapper or the original sink).
+  The {{{SinkWrapper}}} class automatically just delegates all method calls to its wrapper.
+  A sink wrapper is automatically created by the parser through a dedicated factory.
+  Each JSR303 component implementing a SinkWrapperFactory is automatically registered considering its rank.
+  Other sink wrapper factories can be registered manually via <<<Parser.registerSinkWrapperFactory(...)>>>.
+  
++----
+@Named
+public class MySinkWrapperFactory implements SinkWrapperFactory {
+
+    @Override
+    public Sink createWrapper(Sink sink) {
+        return new MySinkWrapper(sink);
+    }
+
+    @Override
+    public int getRank() {
+        // the higher the rank, the earlier it is called in the processing queue
+        return 0;
+    }
+}
+
++----
+
+  The according SinkWrapper could look like this
+
++----
+public class MySinkWrapper extends SinkWrapper {
+
+    public MySinkWrapper(Sink sink) {
+        super(sink);
+    }
+
+    @Override
+    public void text(String text) {
+        super.text("some prefix emitted in front of every text " + text);
+    }
+
+}
++----
 
 * {References}
 
diff --git a/content/apt/macros/index.apt b/content/apt/macros/index.apt
index 60f0bb2..f73d421 100644
--- a/content/apt/macros/index.apt
+++ b/content/apt/macros/index.apt
@@ -169,11 +169,8 @@ public class MyClass
 +----
 
  This displays a TOC for the second section in the document, including all
- subsections (depth 2) and  sub-subsections (depth 3).
-
-  <<Note>> that in Doxia, apt section titles are not implicit anchors
-  (see {{{../references/doxia-apt.html}Enhancements to the APT format}}), so you need
-  to insert explicit anchors for links to work!
+ subsections (depth 2) and  sub-subsections (depth 3). The macro takes care to
+ automatically generate anchors for each TOC entry.
 
  In a xdoc file, it will be: