e->header_stack = stack_new(0);
e->link_stack = stack_new(0);
e->metadata_stack = stack_new(0);
+ e->table_stack = stack_new(0);
e->asset_hash = NULL;
e->pairings1 = token_pair_engine_new();
// Pointers to blocks that are freed elsewhere
stack_free(e->definition_stack);
stack_free(e->header_stack);
+ stack_free(e->table_stack);
// Abbreviations need to be freed
stack * header_stack;
stack * link_stack;
stack * metadata_stack;
+ stack * table_stack;
short language;
short quotes_lang;
yymsp[0].minor.yy0 = yylhsminor.yy0;
break;
case 28: /* block ::= table */
-{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_TABLE); }
+{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_TABLE); stack_push(engine->table_stack, yylhsminor.yy0); }
yymsp[0].minor.yy0 = yylhsminor.yy0;
break;
case 29: /* chunk ::= chunk chunk_line */
block(A) ::= para(B). { A = token_new_parent(B, BLOCK_PARA); is_para_html(engine, A); }
block(A) ::= setext_1(B). { A = token_new_parent(B, BLOCK_SETEXT_1); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, A); }
block(A) ::= setext_2(B). { A = token_new_parent(B, BLOCK_SETEXT_2); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, A); }
-block(A) ::= table(B). { A = token_new_parent(B, BLOCK_TABLE); }
+block(A) ::= table(B). { A = token_new_parent(B, BLOCK_TABLE); stack_push(engine->table_stack, A); }
// Reusable components
}
+void process_table_to_link(mmd_engine * e, token * t) {
+ // Is there a caption
+ if (table_has_caption(t)) {
+ token * temp_token = t->next->child;
+
+ if (temp_token->next &&
+ temp_token->next->type == PAIR_BRACKET) {
+ temp_token = temp_token->next;
+ }
+
+ char * label = label_from_token(e->dstr->str, temp_token);
+
+ DString * url = d_string_new("#");
+ d_string_append(url, label);
+
+ link * l = link_new(e->dstr->str, temp_token, url->str, NULL, NULL);
+
+ stack_push(e->link_stack, l);
+
+ d_string_free(url, true);
+ free(label);
+ }
+}
+
+
+void process_table_stack(mmd_engine * e) {
+ for (int i = 0; i < e->table_stack->size; ++i)
+ {
+ process_table_to_link(e, stack_peek_index(e->table_stack, i));
+ }
+}
+
+
/// Parse metadata
void process_metadata_stack(mmd_engine * e, scratch_pad * scratch) {
if ((scratch->extensions & EXT_NO_METADATA) ||
// Process headers for potential cross-reference targets
process_header_stack(e);
+ // Process tables for potential cross-reference targets
+ process_table_stack(e);
+
// Create scratch pad
scratch_pad * scratch = scratch_pad_new(e, format);
<text:p><text:bookmark text:name="caption"/>Table <text:sequence text:name="Table" text:formula="ooow:Table+1" style:num-format="1"> Update Fields to calculate numbers</text:sequence>:<text:span text:style-name="MMD-Italic">caption</text:span><text:bookmark-end text:name="caption"/></text:p>
-<text:p text:style-name="Standard">[<text:span text:style-name="MMD-Italic">foo</text:span>][bar]
+<text:p text:style-name="Standard"><text:a xlink:type="simple" xlink:href="#bar"><text:span text:style-name="MMD-Italic">foo</text:span></text:a>
| foo | bar |
| — | — |
| foo | bar |</text:p>
</tbody>
</table>
-<p>[<em>foo</em>][bar]
+<p><a href="#bar"><em>foo</em></a>
| foo | bar |
| — | — |
| foo | bar |</p>
\end{minipage}
\end{table}
-[\emph{foo}][bar]
+\emph{foo} (\autoref{bar})
\textbar{} foo \textbar{} bar \textbar{}
\textbar{} --- \textbar{} --- \textbar{}
\textbar{} foo \textbar{} bar \textbar{}