Skip to content

Commit

Permalink
More progress
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Oct 16, 2024
1 parent 56439dc commit 5f2da8f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import org.asciidoctor.maven.site.parser.processors.DescriptionListNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.DocumentNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.ImageNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.ListItemNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.ListingNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.LiteralNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.NoOpNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.OrderedListNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.ParagraphNodeProcessor;
import org.asciidoctor.maven.site.parser.processors.PreambleNodeProcessor;
Expand All @@ -25,21 +27,26 @@ public class NodeSinker {

private final List<NodeProcessor> nodeProcessors;

private final NodeProcessor noOpProcessor;

// TODO this should not be public
public NodeSinker(Sink sink) {
nodeProcessors = Arrays.asList(
new DescriptionListNodeProcessor(sink, this),
new DocumentNodeProcessor(sink, this),
new ImageNodeProcessor(sink, this),
new ListItemNodeProcessor(sink, this),
new ListingNodeProcessor(sink, this),
new ListingNodeProcessor(sink, this),
new LiteralNodeProcessor(sink, this),
new OrderedListNodeProcessor(sink, this),
new ParagraphNodeProcessor(sink, this),
new PreambleNodeProcessor(sink, this),
new SectionNodeProcessor(sink, this),
new TableNodeProcessor(sink, this),
new UnorderedListNodeProcessor(sink, this),
new OrderedListNodeProcessor(sink, this),
new DescriptionListNodeProcessor(sink, this)
new UnorderedListNodeProcessor(sink, this)
);
noOpProcessor = new NoOpNodeProcessor(sink, this);
}

/**
Expand All @@ -49,7 +56,7 @@ private NodeProcessor get(StructuralNode node) {
return nodeProcessors.stream()
.filter(nodeProcessor -> nodeProcessor.applies(node))
.findFirst()
.get();
.orElse(noOpProcessor);
}

public void sink(StructuralNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void process(StructuralNode node) {
if (description.getBlocks().isEmpty()) {
sink.rawText(description.getText());
} else {
sink(node);
super.sink(description);
}
sink.definition_();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.asciidoctor.maven.site.parser.processors;

import java.util.List;

import org.apache.maven.doxia.sink.Sink;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.maven.site.parser.AsciidoctorAstDoxiaParser;
import org.asciidoctor.maven.site.parser.NodeProcessor;
import org.asciidoctor.maven.site.parser.NodeSinker;
import org.slf4j.LoggerFactory;

/**
* Fallback NodeProcessor to collect nodes that have not dedicated processor.
*/
public class NoOpNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor {

private final org.slf4j.Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class);

/**
* Constructor.
*
* @param sink Doxia {@link Sink}
* @param nodeSinker
*/
public NoOpNodeProcessor(Sink sink, NodeSinker nodeSinker) {
super(sink, nodeSinker);
}

@Override
public boolean applies(StructuralNode node) {
return false;
}

@Override
public void process(StructuralNode node) {
final List<StructuralNode> blocks = node.getBlocks();

logger.warn("Fallback behaviour for node: {}", node.getNodeName());
if (!blocks.isEmpty()) {
blocks.forEach(this::sink);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class SectionNodeProcessorTest {
private NodeProcessor nodeProcessor;
private StringWriter sinkWriter;


@Test
void should_convert_document_title() {
String content = documentWithSections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class TableNodeProcessorTest {
private NodeProcessor nodeProcessor;
private StringWriter sinkWriter;


@Test
void should_convert_table_with_header() {
String content = documentWithTable(true, noCaption, emptyList());
Expand Down

0 comments on commit 5f2da8f

Please sign in to comment.