Skip to content

Commit

Permalink
allow for attribute-free Markdown images
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Jan 6, 2019
1 parent ce1db6b commit 17b85c8
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,27 @@ public void execute(Integer height)
String srcPath = imgSrcPathFromHref(sentinel, href);
final Image image = new Image(srcPath);
image.addStyleName(RES.styles().image());

// parse and inject attributes
Attributes parsedAttributes = HTMLAttributesParser.parseAttributes(attributes);
final Element imgEl = image.getElement();
for (Map.Entry<String, String> entry : parsedAttributes.getAttributes().entrySet())
{
String key = entry.getKey();
String val = entry.getValue();
if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val))
continue;
imgEl.setAttribute(key, val);
}

if (!parsedAttributes.getIdentifier().isEmpty())
imgEl.setId(parsedAttributes.getIdentifier());
// parse and inject attributes, if we have any
if (attributes != null)
{
Attributes parsedAttributes = HTMLAttributesParser.parseAttributes(attributes);
for (Map.Entry<String, String> entry : parsedAttributes.getAttributes().entrySet())
{
String key = entry.getKey();
String val = entry.getValue();
if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val))
continue;
imgEl.setAttribute(key, val);
}

for (String className : parsedAttributes.getClasses())
imgEl.addClassName(className);
if (!parsedAttributes.getIdentifier().isEmpty())
imgEl.setId(parsedAttributes.getIdentifier());

for (String className : parsedAttributes.getClasses())
imgEl.addClassName(className);
}

// add load handlers to image
DOM.sinkEvents(imgEl, Event.ONLOAD | Event.ONERROR);
Expand Down

0 comments on commit 17b85c8

Please sign in to comment.