-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support "Captioned titles" in asciidoctor-parser-doxia-module (#938)
* Add support for Example (inline and blocks) * Add support for captioned titles in appendixes, tables, listing, figure, and examples. * Fix empty table generating <table> element * Refactor Section tests for readability Fixes #749
- Loading branch information
1 parent
912de34
commit e870c8c
Showing
26 changed files
with
685 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...dule/src/main/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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.NodeProcessor; | ||
import org.asciidoctor.maven.site.parser.NodeSinker; | ||
|
||
import static javax.swing.text.html.HTML.Attribute.STYLE; | ||
import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; | ||
|
||
/** | ||
* Inline images are processed as paragraphs. | ||
* | ||
* @author abelsromero | ||
* @since 3.1.0 | ||
*/ | ||
public class ExampleNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor { | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param sink Doxia {@link Sink} | ||
* @param nodeSinker | ||
*/ | ||
public ExampleNodeProcessor(Sink sink, NodeSinker nodeSinker) { | ||
super(sink, nodeSinker); | ||
} | ||
|
||
@Override | ||
public boolean applies(StructuralNode node) { | ||
return "example".equals(node.getNodeName()); | ||
} | ||
|
||
@Override | ||
public void process(StructuralNode node) { | ||
// Add caption as a div (same as Asciidoctor): | ||
// - For consistency | ||
// - Using `figureCaption` requires wrapping the image in <figure> which adds indentation | ||
final Sink sink = getSink(); | ||
|
||
sink.division(); | ||
final String title = TitleCaptionExtractor.getText(node); | ||
if (isNotBlank(title)) { | ||
sink.division(SinkAttributes.of(STYLE, Styles.CAPTION)); | ||
sink.text(title); | ||
sink.division_(); | ||
} | ||
|
||
final List<StructuralNode> blocks = node.getBlocks(); | ||
if (!blocks.isEmpty()) { | ||
divWrap(sink, node, () -> blocks.forEach(this::sink)); | ||
} else { | ||
// For :content_model: simple (inline) | ||
// https://docs.asciidoctor.org/asciidoc/latest/blocks/example-blocks/#example-style-syntax | ||
final String content = (String) node.getContent(); | ||
if (isNotBlank(content)) { | ||
divWrap(sink, node, () -> sink.rawText(content)); | ||
} | ||
} | ||
|
||
sink.division_(); | ||
} | ||
|
||
void divWrap(Sink sink, StructuralNode node, Runnable consumer) { | ||
sink.division(SinkAttributes.of(STYLE, Styles.EXAMPLE)); | ||
consumer.run(); | ||
sink.division_(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...xia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SinkAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.asciidoctor.maven.site.parser.processors; | ||
|
||
import javax.swing.text.html.HTML.Attribute; | ||
|
||
import org.apache.maven.doxia.sink.SinkEventAttributes; | ||
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; | ||
|
||
class SinkAttributes { | ||
|
||
static SinkEventAttributes of(Attribute name, String value) { | ||
final var attributes = new SinkEventAttributeSet(); | ||
attributes.addAttribute(name, value); | ||
return attributes; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...arser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/Styles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.asciidoctor.maven.site.parser.processors; | ||
|
||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
class Styles { | ||
|
||
public static final String CAPTION = Stream.of( | ||
"color: #7a2518", | ||
"margin-bottom: .25em" | ||
).collect(Collectors.joining("; ")); | ||
|
||
|
||
public static final String EXAMPLE = Stream.of( | ||
"background: #fffef7", | ||
"border-color: #e0e0dc", | ||
"border: 1px solid #e6e6e6", | ||
"box-shadow: 0 1px 4px #e0e0dc", | ||
"margin-bottom: 1.25em", | ||
"padding: 1.25em" | ||
).collect(Collectors.joining("; ")); | ||
} |
Oops, something went wrong.