package org.commonmark.ext.image.attributes.internal;

import org.commonmark.ext.image.attributes.ImageAttributes;
import org.commonmark.node.AbstractVisitor;
import org.commonmark.node.CustomNode;
import org.commonmark.node.Image;
import org.commonmark.node.Node;
import org.commonmark.renderer.html.AttributeProvider;

import java.util.*;

public class ImageAttributesAttributeProvider implements AttributeProvider {

    private ImageAttributesAttributeProvider() {
    }

    public static ImageAttributesAttributeProvider create() {
        return new ImageAttributesAttributeProvider();
    }

    @Override
    public void setAttributes(Node node, String tagName, final Map<String, String> attributes) {
        if (node instanceof Image) {
            node.accept(new AbstractVisitor() {
                @Override
                public void visit(CustomNode node) {
                    if (node instanceof ImageAttributes) {
                        ImageAttributes imageAttributes = (ImageAttributes) node;
                        Map<String, String> attributesMap = imageAttributes.getAttributes();
                        for (String key : attributesMap.keySet()) {
                            attributes.put(key, attributesMap.get(key));
                        }
                        // Now that we have used the image attributes we remove the node.
                        imageAttributes.unlink();
                    }
                }
            });
        }
    }
}

@@ -1033,19 +1033,30 @@
         
-Map
+for (Map.Entry
 %3CString,
@@ -1068,23 +1068,15 @@
 ng%3E 
-attributesMap =
+entry :
  ima
@@ -1107,68 +1107,13 @@
 es()
-;%0A                        for (String key : attributesMap.ke
+.entr
 ySet
@@ -1165,34 +1165,39 @@
 put(
-key, attributesMap.get(key
+entry.getKey(), entry.getValue(
 ));%0A

Update commonmark-ext-image-attributes/src/main/java/org/commonmark/ext/image/attributes/internal/ImageAttributesAttributeProvider.java