+ # block images (wrapped in <figure>)
+ } else if ( match(block, /^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n|$)/) ) {
+ len = RLENGTH;
+ text = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\1", "g", block);
+ href = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\2", "g", block);
+ title = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\4", "g", block);
+ attrib = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\6", "g", block);
+ if ( title && attrib ) {
+ return "<figure data-src=\"" URL(href, 1) "\" class=\"" HTML(attrib) "\">" \
+ "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\" class=\"" HTML(attrib) "\">" \
+ "<figcaption>" inline(title) "</figcaption>" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ } else if ( title ) {
+ return "<figure data-src=\"" URL(href, 1) "\">" \
+ "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\">" \
+ "<figcaption>" inline(title) "</figcaption>" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ } else if ( attrib ) {
+ return "<figure data-src=\"" URL(href, 1) "\" class=\"" HTML(attrib) "\">" \
+ "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\" class=\"" HTML(attrib) "\">" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ } else {
+ return "<figure data-src=\"" URL(href, 1) "\">" \
+ "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\">" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ }
+
+ # reference style images (block)
+ } else if ( match(line, /^!\[([^]]*)\] ?\[([^]]*)\](\n|$)/ ) ) {
+ len = RLENGTH;
+ text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block);
+ id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
+ if ( ! id ) id = text;
+ if ( rl_href[id] && rl_title[id] ) {
+ return "<figure data-src=\"" URL(rl_href[id], 1) "\">" \
+ "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
+ "<figcaption>" inline(rl_title[id]) "</figcaption>" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ } else if ( rl_href[id] ) {
+ return "<figure data-src=\"" URL(rl_href[id], 1) "\">" \
+ "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );
+ } else {
+ return "<p>" HTML(substr(block, 1, len)) "</p>\n" _block( substr(block, len + 1) );
+ }
+
+ # Macros (standalone <<macro>> calls handled as block, so they are not wrapped in paragraph)
+ } else if ( AllowMacros && match( block, /^<<(([^>]|>[^>])+)>>(\n|$)/) ) {
+ len = RLENGTH;
+ text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
+ return macro(text) _block(substr(block, len + 1) );
+