Skip to content

Commit

Permalink
[DOXIASITETOOLS-320] Document Sink wrappers and the automatic generation
Browse files Browse the repository at this point in the history
of anchor names for TOC entries
  • Loading branch information
kwin authored and slachiewicz committed Dec 30, 2023
1 parent 3764390 commit bede41c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
43 changes: 43 additions & 0 deletions content/apt/developers/sink.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
7 changes: 2 additions & 5 deletions content/apt/macros/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit bede41c

Please sign in to comment.