michael-o commented on code in PR #247:
URL: https://github.com/apache/maven-doxia/pull/247#discussion_r1835021695


##########
doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownSink.java:
##########
@@ -774,13 +778,30 @@ private void writeImage(String alt, String src) {
 
     /** {@inheritDoc} */
     public void anchor(String name, SinkEventAttributes attributes) {
-        // write(ANCHOR_START_MARKUP + name);
-        // TODO get implementation from Xhtml5 base sink
+        // emit html anchor as markdown does not support anchors
+        MutableAttributeSet atts = SinkUtils.filterAttributes(attributes, 
SinkUtils.SINK_BASE_ATTRIBUTES);
+
+        String id = name;
+
+        if (!DoxiaUtils.isValidId(id)) {
+            id = DoxiaUtils.encodeId(name);
+
+            LOGGER.debug("{}Modified invalid anchor name '{}' to '{}'", 
getLocationLogPrefix(), name, id);
+        }
+
+        MutableAttributeSet att = new SinkEventAttributeSet();
+        att.addAttribute(SinkEventAttributes.ID, id);
+        att.addAttributes(atts);
+        StringBuilder htmlAnchor = new StringBuilder("<a");
+        htmlAnchor.append(SinkUtils.getAttributeString(att));
+        htmlAnchor.append(">");
+        htmlAnchor.append("</a>"); // close anchor tag immediately otherwise 
markdown would not be allowed afterwards

Review Comment:
   Interesting,  thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to