- } 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) );
- }
+ } else if ( match(block, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n|$)") ) {
+ len = RLENGTH; text = href = title = attrib = substr( block, 1, len);
+
+ sub("^!\\[", "", text);
+ sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", text);
+
+ sub("^!" lix "\\([\n\t ]*", "", href);
+ sub("([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", href);
+
+ sub("^!" lix "\\([\n\t ]*" lid, "", title);
+ sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", title);
+ sub("^[\n\t ]+", "", title);
+
+ sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
+ sub("(\n.*)?$", "", attrib);
+ sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
+
+ if ( match(href, /^<.*>$/) ) { sub(/^</, "", href); sub(/>$/, "", href); }
+ if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
+ else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
+ else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
+
+ gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
+
+ return "<figure data-src=\"" URL(href, 1) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
+ "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
+ (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
+ (title?"<figcaption>" inline(title) "</figcaption>":"") \
+ "</figure>\n\n" \
+ _block( substr( block, len + 1) );