}
-void mmd_export_image_html(DString * out, const char * source, token * text, link * link, size_t offset, scratch_pad * scratch) {
+void mmd_export_image_html(DString * out, const char * source, token * text, link * link, size_t offset, scratch_pad * scratch, bool is_figure) {
attr * a = link->attributes;
+ // Compatibility mode doesn't allow figures
+ if (scratch->extensions & EXT_COMPATIBILITY)
+ is_figure = false;
+
+ if (is_figure) {
+ // Remove wrapping <p> markers
+ d_string_erase(out, out->currentStringLength - 3, 3);
+ print("<figure>\n");
+ scratch->close_para = false;
+ }
+
if (link->url)
printf("<img src=\"%s\"", link->url);
else
print("\"");
}
- if (0 && link->label) {
+ if (link->label && !(scratch->extensions & EXT_COMPATIBILITY)) {
// \todo: Need to decide on approach to id's
char * label = label_from_token(source, link->label);
printf(" id=\"%s\"", label);
}
print(" />");
+
+ if (is_figure) {
+ if (text) {
+ print("\n<figcaption>");
+ mmd_export_token_tree_html(out, source, text->child, offset, scratch);
+ print("</figcaption>");
+ }
+ print("\n</figure>");
+ }
}
scratch->padded = 2;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- if (!scratch->list_is_tight)
- print("</p>");
+ if (scratch->close_para) {
+ if (!scratch->list_is_tight)
+ print("</p>");
+ } else {
+ scratch->close_para = true;
+ }
print("</li>");
scratch->padded = 0;
}
}
- if (!scratch->list_is_tight)
- print("</p>");
+ if (scratch->close_para) {
+ if (!scratch->list_is_tight)
+ print("</p>");
+ } else {
+ scratch->close_para = true;
+ }
scratch->padded = 0;
break;
case BLOCK_TABLE:
// Link
mmd_export_link_html(out, source, t, temp_link, offset, scratch);
} else {
- // Image
- mmd_export_image_html(out, source, t, temp_link, offset, scratch);
+ // Image -- should it be a figure (e.g. image is only thing in paragraph)?
+ temp_token = t->next;
+
+ if (temp_token &&
+ ((temp_token->type == PAIR_BRACKET) ||
+ (temp_token->type == PAIR_PAREN))) {
+ temp_token = temp_token->next;
+ }
+
+ if (temp_token && temp_token->type == TEXT_NL)
+ temp_token = temp_token->next;
+
+ if (temp_token && temp_token->type == TEXT_LINEBREAK)
+ temp_token = temp_token->next;
+
+ if (t->prev || temp_token) {
+ mmd_export_image_html(out, source, t, temp_link, offset, scratch, false);
+ } else {
+ mmd_export_image_html(out, source, t, temp_link, offset, scratch, true);
+ }
}
if (temp_bool) {
p->padded = 2; // Prevent unnecessary leading space
p->list_is_tight = false; // Tight vs Loose list
p->skip_token = 0; // Skip over next n tokens
+ p->close_para = true;
p->extensions = e->extensions;
p->quotes_lang = e->quotes_lang;
if (l) {
l->label = label;
- l->clean_text = clean_inside_pair(source, label, true);
- l->label_text = label_from_token(source, label);
+ if (label) {
+ l->clean_text = clean_inside_pair(source, label, true);
+ l->label_text = label_from_token(source, label);
+ } else {
+ l->clean_text = NULL;
+ l->label_text = NULL;
+ }
l->url = clean_string(url, false);
l->title = (title == NULL) ? NULL : strdup(title);
l->attributes = (attributes == NULL) ? NULL : parse_attributes(attributes);
if (attr_char) {
if (!(scratch->extensions & EXT_COMPATIBILITY))
- l = link_new(source, bracket, url_char, title_char, attr_char);
+ l = link_new(source, NULL, url_char, title_char, attr_char);
} else {
- l = link_new(source, bracket, url_char, title_char, attr_char);
+ l = link_new(source, NULL, url_char, title_char, attr_char);
}
free(url_char);
unsigned long extensions;
short padded; //!< How many empty lines at end output buffer
short list_is_tight;
+ short close_para;
short skip_token;
short footnote_para_counter;
--- /dev/null
+<figure>
+<img src="http://foo.bar/" alt="foo" id="foo" title="foo" width="40px" />
+<figcaption>foo</figcaption>
+</figure>
+
+<figure>
+<img src="http://foo.bar/" alt="bar" id="foo" title="foo" width="40px" />
+<figcaption><em>bar</em></figcaption>
+</figure>
+
+<p><img src="http://foo.bar/" alt="bar" id="foo" title="foo" width="40px" /> bar</p>
+
+<figure>
+<img src="http://foo.bar/" alt="foo" title="foo" width="40px" />
+<figcaption><em>foo</em></figcaption>
+</figure>
--- /dev/null
+<p>![foo]</p>
+
+<p>![<em>bar</em>][foo]</p>
+
+<p>![<em>bar</em>][foo] bar</p>
+
+<p></p>
+
+<p>[foo]: http://foo.bar/ "foo" width="40px"</p>
\ No newline at end of file
--- /dev/null
+![foo]
+
+![*bar*][foo]
+
+![*bar*][foo] bar
+
+
+
+[foo]: http://foo.bar/ "foo" width="40px"
-<p>foo <img src="http://foo.bar/" alt="image" title="title" width="40px" height="400px" /></p>
+<p>foo <img src="http://foo.bar/" alt="image" id="image" title="title" width="40px" height="400px" /></p>
<p>foo <a href="http://foo.bar/1" class="external" style="border: solid black 1px;">link</a></p>
<p>foo <a href="http://foo.bar/3" class="external" style="border: solid black 1px;">link3</a></p>
-<p><img src="http://foo.bar/" alt="test" title="title" width="40px" height="400px" /></p>
+<figure>
+<img src="http://foo.bar/" alt="test" title="title" width="40px" height="400px" />
+<figcaption>test</figcaption>
+</figure>
<p>5</p>
-<p>Test <img src="http://test.1/" alt="foo" />.</p>
+<p>Test <img src="http://test.1/" alt="foo" id="bar" />.</p>
-<p>Test <img src="http://test.1/" alt="foo" />.</p>
+<p>Test <img src="http://test.1/" alt="foo" id="bar" />.</p>
-<p>Test <img src="http://test.3/" alt="foo" title="title" />.</p>
+<p>Test <img src="http://test.3/" alt="foo" id="foobar" title="title" />.</p>
-<p>Test <img src="http://test.4/" alt="foo" />.</p>
+<p>Test <img src="http://test.4/" alt="foo" id="foobar" />.</p>
-<p>Test <img src="http://test.4/" alt="foo" />.</p>
+<p>Test <img src="http://test.4/" alt="foo" id="foobar" />.</p>
<p>5</p>
-<p>Test <img src="http://test.6/" alt="foo" title="title" />.</p>
+<p>Test <img src="http://test.6/" alt="foo" id="long" title="title" />.</p>
-<p>Test <img src="http://test.0/" alt="foo" />.</p>
+<p>Test <img src="http://test.0/" alt="foo" id="foo" />.</p>
-<p>Test <img src="http://test.0/" alt="foo" />.</p>
+<p>Test <img src="http://test.0/" alt="foo" id="foo" />.</p>