}
+void mmd_export_toc_entry_html(DString * out, const char * source, scratch_pad * scratch, size_t * counter, short level) {
+ token * entry, * next;
+ short entry_level, next_level;
+ char * temp_char;
+
+ print_const("\n<ul>\n");
+
+ // Iterate over tokens
+ while (*counter < scratch->header_stack->size) {
+ // Get token for header
+ entry = stack_peek_index(scratch->header_stack, *counter);
+ entry_level = raw_level_for_header(entry);
+
+ if (entry_level >= level) {
+ // This entry is a direct descendant of the parent
+ temp_char = label_from_header(source, entry);
+ printf("<li><a href=\"#%s\">", temp_char);
+ mmd_export_token_tree_html(out, source, entry->child, 0, scratch);
+ print_const("</a>");
+
+ if (*counter < scratch->header_stack->size - 1) {
+ next = stack_peek_index(scratch->header_stack, *counter + 1);
+ next_level = next->type - BLOCK_H1 + 1;
+ if (next_level > entry_level) {
+ // This entry has children
+ (*counter)++;
+ mmd_export_toc_entry_html(out, source, scratch, counter, entry_level + 1);
+ }
+ }
+
+ print_const("</li>\n");
+ free(temp_char);
+ } else if (entry_level < level ) {
+ // If entry < level, exit this level
+ // Decrement counter first, so that we can test it again later
+ (*counter)--;
+ break;
+ }
+
+ // Increment counter
+ (*counter)++;
+ }
+
+ print_const("</ul>\n");
+}
+
+
+void mmd_export_toc_html(DString * out, const char * source, scratch_pad * scratch) {
+ token * entry;
+ size_t counter = 0;
+
+ mmd_export_toc_entry_html(out, source, scratch, &counter, 0);
+}
+
+
void mmd_export_token_html(DString * out, const char * source, token * t, size_t offset, scratch_pad * scratch) {
if (t == NULL)
return;
temp_short = 0;
temp_short2 = 0;
pad(out, 2, scratch);
- print_const("<div class=\"TOC\">");
+ print_const("<div class=\"TOC\">\n");
+ mmd_export_toc_html(out, source, scratch);
+ print_const("</div>");
+ scratch->padded = 0;
+ break;
for (int i = 0; i < scratch->header_stack->size; ++i)
{
temp_token = stack_peek_index(scratch->header_stack, i);
}
+void mmd_export_toc_entry_latex(DString * out, const char * source, scratch_pad * scratch, size_t * counter, short level) {
+ token * entry, * next;
+ short entry_level, next_level;
+ char * temp_char;
+
+ print_const("\\begin{itemize}\n\n");
+
+ // Iterate over tokens
+ while (*counter < scratch->header_stack->size) {
+ // Get token for header
+ entry = stack_peek_index(scratch->header_stack, *counter);
+ entry_level = raw_level_for_header(entry);
+
+ if (entry_level >= level) {
+ // This entry is a direct descendant of the parent
+ temp_char = label_from_header(source, entry);
+ print_const("\\item ");
+ mmd_export_token_tree_latex(out, source, entry->child, scratch);
+ printf("(\\autoref{%s})\n\n", temp_char);
+
+ if (*counter < scratch->header_stack->size - 1) {
+ next = stack_peek_index(scratch->header_stack, *counter + 1);
+ next_level = next->type - BLOCK_H1 + 1;
+ if (next_level > entry_level) {
+ // This entry has children
+ (*counter)++;
+ mmd_export_toc_entry_latex(out, source, scratch, counter, entry_level + 1);
+ }
+ }
+
+ free(temp_char);
+ } else if (entry_level < level ) {
+ // If entry < level, exit this level
+ // Decrement counter first, so that we can test it again later
+ (*counter)--;
+ break;
+ }
+
+ // Increment counter
+ (*counter)++;
+ }
+
+ print_const("\\end{itemize}\n\n");
+}
+
+
+void mmd_export_toc_latex(DString * out, const char * source, scratch_pad * scratch) {
+ token * entry;
+ size_t counter = 0;
+
+ mmd_export_toc_entry_latex(out, source, scratch, &counter, 0);
+}
+
+
void mmd_export_token_latex(DString * out, const char * source, token * t, scratch_pad * scratch) {
if (t == NULL)
return;
temp_short2 = 0;
pad(out, 2, scratch);
- for (int i = 0; i < scratch->header_stack->size; ++i)
- {
- temp_token = stack_peek_index(scratch->header_stack, i);
-
- if (temp_token->type == temp_short2) {
- // Same level -- close list item
- //pad(out, 2, scratch);
- }
-
- if (temp_short == 0) {
- // First item
- pad(out, 2, scratch);
- print_const("\\begin{itemize}");
- scratch->padded = 0;
- temp_short = temp_token->type;
- temp_short2 = temp_short;
- }
-
- // Indent?
- if (temp_token->type == temp_short2) {
- // Same level -- NTD
- } else if (temp_token->type == temp_short2 + 1) {
- // Indent
- pad(out, 2, scratch);
- print_const("\\begin{itemize}");
- scratch->padded = 0;
- temp_short2++;
- } else if (temp_token->type < temp_short2) {
- // Outdent
- pad(out, 2, scratch);
- while (temp_short2 > temp_token->type) {
- if (temp_short2 > temp_short) {
- pad(out, 2, scratch);
- print_const("\\end{itemize}");
- scratch->padded = 0;
- } else
- temp_short = temp_short2 - 1;
-
- temp_short2--;
- }
- } else {
- // Skipped more than one level -- ignore
- continue;
- }
-
- temp_char = label_from_header(source, temp_token);
- pad(out, 2, scratch);
- print_const("\\item ");
- mmd_export_token_tree_latex(out, source, temp_token->child, scratch);
- printf("(\\autoref{%s})", temp_char);
- scratch->padded = 0;
- free(temp_char);
- }
-
- while (temp_short2 > (temp_short)) {
- pad(out, 2, scratch);
- print_const("\\end{itemize}");
- scratch->padded = 0;
- temp_short2--;
- }
-
- if (temp_short) {
- pad(out, 2, scratch);
- print_const("\\end{itemize}");
- scratch->padded = 0;
- }
+ mmd_export_toc_latex(out, source, scratch);
scratch->padded = 0;
break;
}
+
+void mmd_export_toc_entry_odf(DString * out, const char * source, scratch_pad * scratch, size_t * counter, short level) {
+ token * entry, * next;
+ short entry_level, next_level;
+ char * temp_char;
+
+ print_const("\n<text:list text:style-name=\"L1\">\n");
+
+ // Iterate over tokens
+ while (*counter < scratch->header_stack->size) {
+ // Get token for header
+ entry = stack_peek_index(scratch->header_stack, *counter);
+ entry_level = raw_level_for_header(entry);
+
+ if (entry_level >= level) {
+ // This entry is a direct descendant of the parent
+ temp_char = label_from_header(source, entry);
+ printf("<text:list-item><text:p text:style-name=\"P1\"><text:a xlink:type=\"simple\" xlink:href=\"#%s\">", temp_char);
+ mmd_export_token_tree_odf(out, source, entry->child, scratch);
+ print_const("</text:a></text:p>");
+
+ if (*counter < scratch->header_stack->size - 1) {
+ next = stack_peek_index(scratch->header_stack, *counter + 1);
+ next_level = next->type - BLOCK_H1 + 1;
+ if (next_level > entry_level) {
+ // This entry has children
+ (*counter)++;
+ mmd_export_toc_entry_odf(out, source, scratch, counter, entry_level + 1);
+ }
+ }
+
+ print_const("</text:list-item>\n");
+ free(temp_char);
+ } else if (entry_level < level ) {
+ // If entry < level, exit this level
+ // Decrement counter first, so that we can test it again later
+ (*counter)--;
+ break;
+ }
+
+ // Increment counter
+ (*counter)++;
+ }
+
+ print_const("</text:list>\n");
+}
+
+void mmd_export_toc_odf(DString * out, const char * source, scratch_pad * scratch) {
+ token * entry;
+ size_t counter = 0;
+
+ mmd_export_toc_entry_odf(out, source, scratch, &counter, 0);
+}
+
+
void mmd_export_token_odf(DString * out, const char * source, token * t, scratch_pad * scratch) {
if (t == NULL)
return;
temp_short2 = 0;
pad(out, 2, scratch);
- for (int i = 0; i < scratch->header_stack->size; ++i)
- {
- temp_token = stack_peek_index(scratch->header_stack, i);
-
- if (temp_token->type == temp_short2) {
- // Same level -- close list item
- print_const("</text:list-item>\n");
- }
-
- if (temp_short == 0) {
- // First item
- print_const("\n<text:list text:style-name=\"L1\">\n");
- temp_short = temp_token->type;
- temp_short2 = temp_short;
- }
-
- // Indent?
- if (temp_token->type == temp_short2) {
- // Same level -- NTD
- } else if (temp_token->type == temp_short2 + 1) {
- // Indent
- print_const("\n\n<text:list text:style-name=\"L1\">\n");
- temp_short2++;
- } else if (temp_token->type < temp_short2) {
- // Outdent
- print_const("</text:list-item>\n");
- while (temp_short2 > temp_token->type) {
- if (temp_short2 > temp_short)
- print_const("</text:list></text:list-item>\n");
- else
- temp_short = temp_short2 - 1;
-
- temp_short2--;
- }
- } else {
- // Skipped more than one level -- ignore
- continue;
- }
-
- temp_char = label_from_header(source, temp_token);
-
- printf("<text:list-item><text:p text:style-name=\"P1\"><text:a xlink:type=\"simple\" xlink:href=\"#%s\">", temp_char);
- mmd_export_token_tree_odf(out, source, temp_token->child, scratch);
- print_const("</text:a></text:p>");
- free(temp_char);
- }
-
- while (temp_short2 > (temp_short)) {
- print_const("</text:list>\n");
- temp_short2--;
- }
-
- if (temp_short)
- print_const("</text:list-item>\n</text:list>\n");
+ mmd_export_toc_odf(out, source, scratch);
scratch->padded = 1;
break;
return result;
}
+
+short raw_level_for_header(token * header) {
+ switch (header->type) {
+ case BLOCK_H1:
+ case BLOCK_SETEXT_1:
+ return 1;
+ case BLOCK_H2:
+ case BLOCK_SETEXT_2:
+ return 2;
+ case BLOCK_H3:
+ return 3;
+ case BLOCK_H4:
+ return 4;
+ case BLOCK_H5:
+ return 5;
+ case BLOCK_H6:
+ return 6;
+ }
+
+ return 0;
+}
+
char * clean_string(const char * str, bool lowercase);
+short raw_level_for_header(token * header);
+
#endif
<style:style style:name="MMD-Subscript" style:family="text">
<style:text-properties style:text-position="sub 58%"/>
</style:style>
+ <style:style style:name="Strike" style:family="text">
+ <style:text-properties style:text-line-through-style="solid" />
+ </style:style>
+ <style:style style:name="Underline" style:family="text">
+ <style:text-properties style:text-underline-style="solid" style:text-underline-color="font-color"/>
+ </style:style>
+ <style:style style:name="Highlight" style:family="text">
+ <style:text-properties fo:background-color="#FFFF00" />
+ </style:style>
+ <style:style style:name="Comment" style:family="text">
+ <style:text-properties fo:color="#0000BB" />
+ </style:style>
<style:style style:name="MMD-Table" style:family="paragraph" style:parent-style-name="Standard">
<style:paragraph-properties fo:margin-top="0in" fo:margin-bottom="0.05in"/>
</style:style>
<style:master-page style:name="Footnote" style:page-layout-name="pm2"/>
</office:master-styles>
<office:meta>
-<dc:title>Table of Contents</dc:title>
-<meta:user-defined meta:name="latex config">article</meta:user-defined>
+ <dc:title>Table of Contents</dc:title>
</office:meta>
<office:body>
<office:text>
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevel">Second Level</text:a></text:p></text:list-item>
-<text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevel">First Level</text:a></text:p>
-
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevelb">Second Level b</text:a></text:p>
-
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#thirdlevel">Third Level</text:a></text:p></text:list-item>
-</text:list></text:list-item>
-<text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevelc">Second Level c</text:a></text:p></text:list-item>
-</text:list></text:list-item>
-<text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevelb">First Level b</text:a></text:p>
-
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondleveld">Second level d</text:a></text:p>
-
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#thirdleveld">Third level d</text:a></text:p>
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#fourthleveld">Fourth level d</text:a></text:p></text:list-item>
-</text:list></text:list-item>
-</text:list></text:list-item>
-</text:list></text:list-item>
-<text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevele">First level</text:a></text:p>
-
-<text:list text:style-name="L1"><text:list-item>
-<text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevele">Second level</text:a></text:p></text:list-item>
-</text:list></text:list-item>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevel">Second Level </text:a></text:p></text:list-item>
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevel">First Level </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevelb">Second Level b </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#thirdlevel">Third Level </text:a></text:p></text:list-item>
+</text:list>
+</text:list-item>
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevelc">Second Level c </text:a></text:p></text:list-item>
+</text:list>
+</text:list-item>
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevelb">First Level b </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#thirdlevelb">Third Level b </text:a></text:p></text:list-item>
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondleveld">Second level d </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#thirdleveld">Third level d </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#fourthleveld">Fourth level d </text:a></text:p></text:list-item>
+</text:list>
+</text:list-item>
+</text:list>
+</text:list-item>
+</text:list>
+</text:list-item>
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#firstlevele">First level </text:a></text:p>
+<text:list text:style-name="L1">
+<text:list-item><text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#secondlevele">Second level </text:a></text:p></text:list-item>
+</text:list>
+</text:list-item>
</text:list>
-<text:h text:outline-level="2"><text:bookmark text:name="secondlevel"/>Second Level<text:bookmark-end text:name="secondlevel"/></text:h>
+<text:h text:outline-level="2"><text:bookmark text:name="secondlevel"/>Second Level <text:bookmark-end text:name="secondlevel"/></text:h>
-<text:h text:outline-level="1"><text:bookmark text:name="firstlevel"/>First Level<text:bookmark-end text:name="firstlevel"/></text:h>
+<text:h text:outline-level="1"><text:bookmark text:name="firstlevel"/>First Level <text:bookmark-end text:name="firstlevel"/></text:h>
-<text:h text:outline-level="2"><text:bookmark text:name="secondlevelb"/>Second Level b<text:bookmark-end text:name="secondlevelb"/></text:h>
+<text:h text:outline-level="2"><text:bookmark text:name="secondlevelb"/>Second Level b <text:bookmark-end text:name="secondlevelb"/></text:h>
-<text:h text:outline-level="3"><text:bookmark text:name="thirdlevel"/>Third Level<text:bookmark-end text:name="thirdlevel"/></text:h>
+<text:h text:outline-level="3"><text:bookmark text:name="thirdlevel"/>Third Level <text:bookmark-end text:name="thirdlevel"/></text:h>
-<text:h text:outline-level="2"><text:bookmark text:name="secondlevelc"/>Second Level c<text:bookmark-end text:name="secondlevelc"/></text:h>
+<text:h text:outline-level="2"><text:bookmark text:name="secondlevelc"/>Second Level c <text:bookmark-end text:name="secondlevelc"/></text:h>
-<text:h text:outline-level="1"><text:bookmark text:name="firstlevelb"/>First Level b<text:bookmark-end text:name="firstlevelb"/></text:h>
+<text:h text:outline-level="1"><text:bookmark text:name="firstlevelb"/>First Level b <text:bookmark-end text:name="firstlevelb"/></text:h>
-<text:h text:outline-level="3"><text:bookmark text:name="thirdlevelb"/>Third Level b<text:bookmark-end text:name="thirdlevelb"/></text:h>
+<text:h text:outline-level="3"><text:bookmark text:name="thirdlevelb"/>Third Level b <text:bookmark-end text:name="thirdlevelb"/></text:h>
-<text:h text:outline-level="2"><text:bookmark text:name="secondleveld"/>Second level d<text:bookmark-end text:name="secondleveld"/></text:h>
+<text:h text:outline-level="2"><text:bookmark text:name="secondleveld"/>Second level d <text:bookmark-end text:name="secondleveld"/></text:h>
-<text:h text:outline-level="3"><text:bookmark text:name="thirdleveld"/>Third level d<text:bookmark-end text:name="thirdleveld"/></text:h>
+<text:h text:outline-level="3"><text:bookmark text:name="thirdleveld"/>Third level d <text:bookmark-end text:name="thirdleveld"/></text:h>
-<text:h text:outline-level="4"><text:bookmark text:name="fourthleveld"/>Fourth level d<text:bookmark-end text:name="fourthleveld"/></text:h>
+<text:h text:outline-level="4"><text:bookmark text:name="fourthleveld"/>Fourth level d <text:bookmark-end text:name="fourthleveld"/></text:h>
-<text:h text:outline-level="1"><text:bookmark text:name="firstlevele"/>First level<text:bookmark-end text:name="firstlevele"/></text:h>
+<text:h text:outline-level="1"><text:bookmark text:name="firstlevele"/>First level <text:bookmark-end text:name="firstlevele"/></text:h>
-<text:h text:outline-level="2"><text:bookmark text:name="secondlevele"/>Second level<text:bookmark-end text:name="secondlevele"/></text:h></office:text>
+<text:h text:outline-level="2"><text:bookmark text:name="secondlevele"/>Second level <text:bookmark-end text:name="secondlevele"/></text:h>
+</office:text>
</office:body>
</office:document>
<body>
<div class="TOC">
+
<ul>
<li><a href="#secondlevel">Second Level </a></li>
<li><a href="#firstlevel">First Level </a>
-
<ul>
<li><a href="#secondlevelb">Second Level b </a>
-
<ul>
<li><a href="#thirdlevel">Third Level </a></li>
-</ul></li>
+</ul>
+</li>
<li><a href="#secondlevelc">Second Level c </a></li>
-</ul></li>
+</ul>
+</li>
<li><a href="#firstlevelb">First Level b </a>
-
<ul>
+<li><a href="#thirdlevelb">Third Level b </a></li>
<li><a href="#secondleveld">Second level d </a>
-
<ul>
<li><a href="#thirdleveld">Third level d </a>
-
<ul>
<li><a href="#fourthleveld">Fourth level d </a></li>
-</ul></li>
-</ul></li>
-</ul></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</li>
<li><a href="#firstlevele">First level </a>
-
<ul>
-<li><a href="#secondlevele">Second level </a></ul>
+<li><a href="#secondlevele">Second level </a></li>
+</ul>
</li>
</ul>
</div>
\begin{itemize}
+\item Third Level b (\autoref{thirdlevelb})
+
\item Second level d (\autoref{secondleveld})
\begin{itemize}
\end{itemize}
+
+
\chapter{Second Level }
\label{secondlevel}
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span><text:tab/><text:tab/></text:p>
</table:table-cell>
</table:table-row>
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span> </text:p>
</table:table-cell>
</table:table-row>
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span> </text:p>
</table:table-cell>
</table:table-row>
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span> </text:p>
</table:table-cell>
</table:table-row>
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span> | </text:p>
</table:table-cell>
</table:table-row>
</table:table-cell>
</table:table-row>
<table:table-row>
-<table:table-cell table:numer-columns-spanned="2">
+<table:table-cell table:number-columns-spanned="2">
<text:p text:style-name="MMD-Table"> <text:span text:style-name="MMD-Bold">foo bar</text:span> </text:p>
</table:table-cell>
</table:table-row>