break;
case PAIR_BRACKET_CITATION:
parse_citation:
- temp_bool = true;
+ temp_bool = true; // Track whether this is regular vs 'not cited'
+ temp_token = t; // Remember whether we need to skip ahead
- if (t->type == PAIR_BRACKET) {
- // This is a locator for subsequent citation
- temp_char = text_inside_pair(source, t);
- temp_char2 = label_from_string(temp_char);
+ if (scratch->extensions & EXT_NOTES) {
+ // Note-based syntax enabled
+
+ if (t->type == PAIR_BRACKET) {
+ // This is a locator for a subsequent citation (e.g. `[foo][#bar]`)
+ temp_char = text_inside_pair(source, t);
+ temp_char2 = label_from_string(temp_char);
+
+ if (strcmp(temp_char2, "notcited") == 0) {
+ free(temp_char);
+ temp_char = strdup("");
+ temp_bool = false;
+ }
- if (strcmp(temp_char2, "notcited") == 0) {
free(temp_char2);
- free(temp_char);
+
+ // Move ahead to actual citation
+ t = t->next;
+ } else {
+ // This is the actual citation (e.g. `[#foo]`)
+ // No locator
temp_char = strdup("");
- temp_bool = false;
}
- if (temp_char[0] == '\0')
- temp_char2 = strdup("");
- else
- temp_char2 = strdup(", ");
-
+ // Classify this use
+ temp_short2 = scratch->used_citations->size;
+ temp_short3 = scratch->inline_citations_to_free->size;
+ citation_from_bracket(source, scratch, t, &temp_short);
- // Process the actual citation
- t = t->next;
- } else {
- temp_char = strdup("");
- temp_char2 = strdup("");
- }
+ if (temp_short == -1) {
+ // This instance is not properly formed
+ print_const("[#");
+ mmd_export_token_tree_html(out, source, t->child->next, scratch);
+ print_const("]");
- if (scratch->extensions & EXT_NOTES) {
- temp_short2 = scratch->used_citations->size;
+ free(temp_char);
+ break;
+ }
- citation_from_bracket(source, scratch, t, &temp_short);
+ // Get instance of the note used
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
if (temp_bool) {
- if (temp_short2 == scratch->used_citations->size) {
- // Repeat of earlier citation
- printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
- temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
+ // This is a regular citation
+
+ if (temp_char[0] == '\0') {
+ // No locator
+
+ if (temp_short2 == scratch->used_citations->size) {
+ // This is a re-use of a previously used note
+ printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%d]</a>",
+ temp_short, LC("see citation"), temp_short);
+ } else {
+ // This is the first time this note was used
+ printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%d]</a>",
+ temp_short, temp_short, LC("see citation"), temp_short);
+ }
} else {
- // New citation
- printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
- temp_short, temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
+ // Locator present
+
+ if (temp_short2 == scratch->used_citations->size) {
+ // This is a re-use of a previously used note
+ printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%s, %d]</a>",
+ temp_short, LC("see citation"), temp_char, temp_short);
+ } else {
+ // This is the first time this note was used
+ printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%s, %d]</a>",
+ temp_short, temp_short, LC("see citation"), temp_char, temp_short);
+ }
}
+ } else {
+ // This is a "nocite"
}
- if (t->prev && (t->prev->type == PAIR_BRACKET)) {
+ if (temp_token != t) {
// Skip citation on next pass
scratch->skip_token = 1;
}
+
+ free(temp_char);
} else {
- // Footnotes disabled
+ // Note-based syntax disabled
mmd_export_token_tree_html(out, source, t->child, scratch);
}
-
- free(temp_char);
- free(temp_char2);
break;
+
case PAIR_BRACKET_FOOTNOTE:
if (scratch->extensions & EXT_NOTES) {
// Note-based syntax enabled
break;
case PAIR_BRACKET_CITATION:
parse_citation:
- temp_bool = true; // Track whether this is a 'not cited'
- temp_token = t; // Remember whether we need to skip ahead
-
+ temp_bool = true; // Track whether this is regular vs 'not cited'
+ temp_token = t; // Remember whether we need to skip ahead
+
if (scratch->extensions & EXT_NOTES) {
+ // Note-based syntax enabled
+
if (t->type == PAIR_BRACKET) {
- // This is a locator for subsequent citation (e.g. `[foo][#bar]`
+ // This is a locator for a subsequent citation (e.g. `[foo][#bar]`)
temp_char = text_inside_pair(source, t);
temp_char2 = label_from_string(temp_char);
free(temp_char2);
- // Process the actual citation
+ // Move ahead to actual citation
t = t->next;
} else {
- // This is just a citation (e.g. `[#foo]`)
+ // This is the actual citation (e.g. `[#foo]`)
+ // No locator
temp_char = strdup("");
}
- // See if we're a citep or cite
- temp_char2 = clean_inside_pair(source, t, false);
-
+ // Classify this use
+ temp_short2 = scratch->used_citations->size;
+ temp_short3 = scratch->inline_citations_to_free->size;
citation_from_bracket(source, scratch, t, &temp_short);
+ if (temp_short == -1) {
+ // This instance is not properly formed
+ print_const("[#");
+ mmd_export_token_tree_latex(out, source, t->child->next, scratch);
+ print_const("]");
+
+ free(temp_char);
+ break;
+ }
+
+ // Get instance of the note used
temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
if (temp_bool) {
- // This is not a "not cited"
+ // This is a regular citation
+
+ // Are we citep vs citet?
+ temp_char2 = clean_inside_pair(source, t, false);
+ if (temp_char2[strlen(temp_char2) - 1] == ';') {
+ temp_bool = true; // citet
+ } else {
+ temp_bool = false; // citep
+ }
+
if (temp_char[0] == '\0') {
// No locator
- if (temp_char2[strlen(temp_char2) - 1] == ';') {
+ if (temp_bool) {
print_const("\\citet");
} else {
print_const("~\\citep");
} else {
// Locator present
- // Does the locator contain two options?
+ // Are there two arguments in the locator?
// e.g. `[foo\]\[bar]`
temp_char3 = strstr(temp_char, "\\]\\[");
if (temp_char3) {
memmove(temp_char3 + 1, temp_char3 + 3, strlen(temp_char3 - 3));
}
- if (temp_char2[strlen(temp_char2) - 1] == ';') {
+ if (temp_bool) {
printf("\\citet[%s]", temp_char);
} else {
printf("~\\citep[%s]", temp_char);
}
printf("{%s}", temp_note->label_text);
+ free(temp_char2);
} else {
// This is a "nocite"
- printf("~\\nocite{%s}",temp_note->label_text);
+ printf("~\\nocite{%s}", temp_note->label_text);
}
if (temp_token != t) {
// Skip citation on next pass
scratch->skip_token = 1;
}
+
+ free(temp_char);
} else {
- // Footnotes disabled
+ // Note-based syntax disabled
mmd_export_token_tree_latex(out, source, t->child, scratch);
}
-
- free(temp_char);
- free(temp_char2);
break;
case PAIR_BRACKET_FOOTNOTE:
if (scratch->extensions & EXT_NOTES) {
break;
case PAIR_BRACKET_CITATION:
parse_citation:
- temp_bool = true; // Track whether this is a 'not cited'
- temp_token = t; // Remember whether we need to skip ahead
-
+ temp_bool = true; // Track whether this is regular vs 'not cited'
+ temp_token = t; // Remember whether we need to skip ahead
+
if (scratch->extensions & EXT_NOTES) {
+ // Note-based syntax enabled
+
if (t->type == PAIR_BRACKET) {
- // This is a locator for subsequent citation (e.g. `[foo][#bar]`
+ // This is a locator for a subsequent citation (e.g. `[foo][#bar]`)
temp_char = text_inside_pair(source, t);
temp_char2 = label_from_string(temp_char);
free(temp_char2);
- // Process the actual citation
+ // Move ahead to actual citation
t = t->next;
} else {
- // This is just a citation (e.g. `[#foo]`)
+ // This is the actual citation (e.g. `[#foo]`)
+ // No locator
temp_char = strdup("");
}
- temp_short3 = scratch->used_citations->size;
-
+ // Classify this use
+ temp_short2 = scratch->used_citations->size;
+ temp_short3 = scratch->inline_citations_to_free->size;
citation_from_bracket(source, scratch, t, &temp_short);
- temp_short2 = scratch->odf_para_type;
- scratch->odf_para_type = PAIR_BRACKET_CITATION;
-
- if (temp_short3 == scratch->used_citations->size) {
- // Re-using previous citation
- print_const("<text:span text:style-name=\"Footnote_20_anchor\"><text:note-ref text:note-class=\"endnote\" text:reference-format=\"text\" ");
- printf("text:ref-name=\"cite%d\">%d</text:note-ref></text:span>", temp_short, temp_short);
- } else {
- // New citation
- printf("<text:note text:id=\"cite%d\" text:note-class=\"endnote\"><text:note-body>", temp_short);
- temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
+ if (temp_short == -1) {
+ // This instance is not properly formed
+ print_const("[#");
+ mmd_export_token_tree_odf(out, source, t->child->next, scratch);
+ print_const("]");
- mmd_export_token_tree_odf(out, source, temp_note->content, scratch);
- print_const("</text:note-body></text:note>");
+ free(temp_char);
+ break;
}
- scratch->odf_para_type = temp_short2;
+ // Get instance of the note used
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
+
+ temp_short3 = scratch->odf_para_type;
+ scratch->odf_para_type = PAIR_BRACKET_FOOTNOTE;
+
+ if (temp_bool) {
+ // This is a regular citation
+
+ if (temp_char[0] == '\0') {
+ // No locator
+
+ if (temp_short2 == scratch->used_citations->size) {
+ // This is a re-use of a previously used note
+ print_const("<text:span text:style-name=\"Footnote_20_anchor\"><text:note-ref text:note-class=\"endnote\" text:reference-format=\"text\" ");
+ printf("text:ref-name=\"cite%d\">%d</text:note-ref></text:span>", temp_short, temp_short);
+ } else {
+ // This is the first time this note was used
+ printf("<text:note text:id=\"cite%d\" text:note-class=\"endnote\"><text:note-body>", temp_short);
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
+
+ mmd_export_token_tree_odf(out, source, temp_note->content, scratch);
+ print_const("</text:note-body></text:note>");
+ }
+ } else {
+ // Locator present
+
+ if (temp_short2 == scratch->used_citations->size) {
+ // This is a re-use of a previously used note
+ print_const("<text:span text:style-name=\"Footnote_20_anchor\"><text:note-ref text:note-class=\"endnote\" text:reference-format=\"text\" ");
+ printf("text:ref-name=\"cite%d\">%d</text:note-ref></text:span>", temp_short, temp_short);
+ } else {
+ // This is the first time this note was used
+ printf("<text:note text:id=\"cite%d\" text:note-class=\"endnote\"><text:note-body>", temp_short);
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
+
+ mmd_export_token_tree_odf(out, source, temp_note->content, scratch);
+ print_const("</text:note-body></text:note>");
+ }
+ }
+ } else {
+ if (temp_short2 == scratch->used_citations->size) {
+ // This is a re-use of a previously used note
+ } else {
+ // This is the first time this note was used
+ // TODO: Not sure how to add an endnote without inserting a marker in the text
+ printf("<text:note text:id=\"cite%d\" text:note-class=\"endnote\"><text:note-body>", temp_short);
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
+
+ mmd_export_token_tree_odf(out, source, temp_note->content, scratch);
+ print_const("</text:note-body></text:note>");
+ }
+ }
if (temp_token != t) {
// Skip citation on next pass
scratch->skip_token = 1;
}
+
+ scratch->odf_para_type = temp_short3;
+
+ free(temp_char);
} else {
- // Footnotes disabled
+ // Note-based syntax disabled
mmd_export_token_tree_odf(out, source, t->child, scratch);
}
-
- free(temp_char);
break;
case PAIR_BRACKET_FOOTNOTE:
if (scratch->extensions & EXT_NOTES) {
<office:text>
<text:h text:outline-level="1"><text:bookmark text:name="citep"/>citep <text:bookmark-end text:name="citep"/></text:h>
-<text:p text:style-name="Standard"><text:note text:id="cite1" text:note-class="endnote"><text:note-body><text:p text:style-name="Footnote">John Doe. <text:span text:style-name="MMD-Italic">A Totally Fake Book</text:span>. Vanity Press, 2006.
+<text:p text:style-name="Standard"><text:note text:id="cite1" text:note-class="endnote"><text:note-body><text:p text:style-name="Footnote">John Doe. <text:span text:style-name="MMD-Italic">A Totally Fake Book 1</text:span>. Vanity Press, 2006.
</text:p></text:note-body></text:note></text:p>
<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite1">1</text:note-ref></text:span>[]</text:p>
<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite1">1</text:note-ref></text:span></text:p>
-<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite1">1</text:note-ref></text:span><text:note text:id="cite2" text:note-class="endnote"><text:note-body><text:p text:style-name="Footnote">John Doe. <text:span text:style-name="MMD-Italic">A Totally Fake Book</text:span>. Vanity Press, 2006.
+<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite1">1</text:note-ref></text:span><text:note text:id="cite2" text:note-class="endnote"><text:note-body><text:p text:style-name="Footnote">John Doe. <text:span text:style-name="MMD-Italic">A Totally Fake Book 2</text:span>. Vanity Press, 2006.
</text:p></text:note-body></text:note></text:p>
<text:h text:outline-level="1"><text:bookmark text:name="citet"/>citet <text:bookmark-end text:name="citet"/></text:h>
<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite1">1</text:note-ref></text:span><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite2">2</text:note-ref></text:span></text:p>
-<text:p text:style-name="Standard"><text:span text:style-name="Footnote_20_anchor"><text:note-ref text:note-class="endnote" text:reference-format="text" text:ref-name="cite2">2</text:note-ref></text:span></text:p>
+<text:p text:style-name="Standard"><text:note text:id="cite3" text:note-class="endnote"><text:note-body><text:p text:style-name="Footnote">John Doe. <text:span text:style-name="MMD-Italic">A Totally Fake Book 3</text:span>. Vanity Press, 2006.</text:p></text:note-body></text:note></text:p>
</office:text>
</office:body>
</office:document>
<ol>
<li id="cn:1">
-<p>John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.
+<p>John Doe. <em>A Totally Fake Book 1</em>. Vanity Press, 2006.
<a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
<li id="cn:2">
-<p>John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.
+<p>John Doe. <em>A Totally Fake Book 2</em>. Vanity Press, 2006.
<a href="#cnref:2" title="return to body" class="reversecitation"> ↩</a></p>
</li>
+<li id="cn:3">
+<p>John Doe. <em>A Totally Fake Book 3</em>. Vanity Press, 2006. <a href="#cnref:3" title="return to body" class="reversecitation"> ↩</a></p>
+</li>
+
</ol>
</div>
<p>[#foo1;][#foo2;]</p>
-<p>[Not Cited][#foo2]</p>
+<p>[Not Cited][#foo3]</p>
-<p>[#foo1]: John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.</p>
+<p>[#foo1]: John Doe. <em>A Totally Fake Book 1</em>. Vanity Press, 2006.</p>
-<p>[#foo2]: John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.</p>
+<p>[#foo2]: John Doe. <em>A Totally Fake Book 2</em>. Vanity Press, 2006.</p>
-<p>[#foo3]: John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.</p>
+<p>[#foo3]: John Doe. <em>A Totally Fake Book 3</em>. Vanity Press, 2006.</p>
\citet{foo1}\citet{foo2}
-~\nocite{foo2}
+~\nocite{foo3}
\begin{thebibliography}{0}
\bibitem{foo1}
-John Doe. \emph{A Totally Fake Book}. Vanity Press, 2006.
+John Doe. \emph{A Totally Fake Book 1}. Vanity Press, 2006.
\bibitem{foo2}
-John Doe. \emph{A Totally Fake Book}. Vanity Press, 2006.
+John Doe. \emph{A Totally Fake Book 2}. Vanity Press, 2006.
+
+\bibitem{foo3}
+John Doe. \emph{A Totally Fake Book 3}. Vanity Press, 2006.
\end{thebibliography}
\input{mmd6-article-footer}
[#foo1;][#foo2;]
-[Not Cited][#foo2]
+[Not Cited][#foo3]
-[#foo1]: John Doe. *A Totally Fake Book*. Vanity Press, 2006.
-[#foo2]: John Doe. *A Totally Fake Book*. Vanity Press, 2006.
+[#foo1]: John Doe. *A Totally Fake Book 1*. Vanity Press, 2006.
-[#foo3]: John Doe. *A Totally Fake Book*. Vanity Press, 2006.
+[#foo2]: John Doe. *A Totally Fake Book 2*. Vanity Press, 2006.
+
+[#foo3]: John Doe. *A Totally Fake Book 3*. Vanity Press, 2006.