Skip to content

Commit

Permalink
(main) Fix IMG tag closing in parser-doxia-module (asciidoctor#930)
Browse files Browse the repository at this point in the history
* Fix IMG tag closing in parser-doxia-module

Fixes asciidoctor#783
  • Loading branch information
abelsromero authored Oct 8, 2024
1 parent 158f6f6 commit 2e74161
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co

== Unreleased

Bug Fixes::

* Fix open IMG tags in parser-doxia-module (#930)

Build / Infrastructure::

* Fix javadoc check flake in CI (#814)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HtmlAsserter {
}

void containsImage(String value) {
def found = find("<img src=\"$value\" alt=\"Asciidoctor is awesome\">")
def found = find("<img src=\"$value\" alt=\"Asciidoctor is awesome\" />")
assertFound("Image", value, found)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.asciidoctor.maven.site.parser.processors;

import javax.swing.text.html.HTML.Attribute;
import java.nio.file.FileSystems;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.maven.site.parser.NodeProcessor;

Expand Down Expand Up @@ -37,7 +39,9 @@ public void process(StructuralNode node) {

final String imagesdir = (String) node.getAttribute("imagesdir");
String imagePath = isBlank(imagesdir) ? target : formatPath(imagesdir, target);
getSink().rawText(String.format("<img src=\"%s\" alt=\"%s\">", imagePath, alt));
final SinkEventAttributeSet attributes = new SinkEventAttributeSet();
attributes.addAttribute(Attribute.ALT, alt);
getSink().figureGraphics(imagePath, attributes);
}

private String formatPath(String imagesdir, String target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void should_convert_document_with_image() {
String html = process(content, 0);

assertThat(html)
.isEqualTo("<img src=\"images/tiger.png\" alt=\"Kitty\">");
.isEqualTo("<img src=\"images/tiger.png\" alt=\"Kitty\" />");
}

@Test
Expand All @@ -41,7 +41,7 @@ void should_convert_document_with_image_and_imagesdir_attribute() {

final String separator = FileSystems.getDefault().getSeparator();
assertThat(html)
.isEqualTo("<img src=\"prefix-path" + separator + "images/tiger.png\" alt=\"Kitty\">");
.isEqualTo("<img src=\"prefix-path" + separator + "images/tiger.png\" alt=\"Kitty\" />");
}

private String documentWithImage() {
Expand Down

0 comments on commit 2e74161

Please sign in to comment.