#include "token.h"
+// Convert MMD text to specified format, with specified extensions, and language
+// Returned char * must be freed
+char * mmd_convert_string(const char * source, unsigned long extensions, short format, short language);
+
+
+// Convert MMD text to specified format, with specified extensions, and language
+// Returned char * must be freed
+char * mmd_convert_d_string(DString * source, unsigned long extensions, short format, short language);
+
+
/// MMD Engine is used for storing configuration information for MMD parser
typedef struct mmd_engine mmd_engine;
// Pointers to blocks that are freed elsewhere
stack_free(e->definition_stack);
stack_free(e->header_stack);
- stack_free(e->abbreviation_stack);
+
+ // Abbreviations need to be freed
+ while (e->abbreviation_stack->size) {
+ footnote_free(stack_pop(e->abbreviation_stack));
+ }
+ stack_free(e->abbreviation_stack);
// Citations need to be freed
while (e->citation_stack->size) {
return result;
}
+
+// Convert MMD text to specified format, with specified extensions, and language
+// Returned char * must be freed
+char * mmd_convert_string(const char * source, unsigned long extensions, short format, short language) {
+ char * result;
+
+ mmd_engine * e = mmd_engine_create_with_string(source, extensions);
+
+ mmd_engine_set_language(e, language);
+
+ mmd_engine_parse_string(e);
+
+ DString * output = d_string_new("");
+
+ mmd_export_token_tree(output, e, format);
+
+ result = output->str;
+
+ mmd_engine_free(e, true); // The engine has a private copy of source that must be freed
+ d_string_free(output, false);
+
+ return result;
+}
+
+
+// Convert MMD text to specified format, with specified extensions, and language
+// Returned char * must be freed
+char * mmd_convert_d_string(DString * source, unsigned long extensions, short format, short language) {
+ char * result;
+
+ mmd_engine * e = mmd_engine_create_with_dstring(source, extensions);
+
+ mmd_engine_set_language(e, language);
+
+ mmd_engine_parse_string(e);
+
+ DString * output = d_string_new("");
+
+ mmd_export_token_tree(output, e, format);
+
+ result = output->str;
+
+ mmd_engine_free(e, false); // The engine doesn't own the DString, so don't free it.
+ d_string_free(output, false);
+
+ return result;
+}
+
HASH_DEL(scratch->footnote_hash, f); // Remove item from hash
free(f); // Free the fn_holder
}
-
stack_free(scratch->used_footnotes);
while (scratch->inline_footnotes_to_free->size) {
HASH_DEL(scratch->citation_hash, f); // Remove item from hash
free(f); // Free the fn_holder
}
-
stack_free(scratch->used_citations);
while (scratch->inline_citations_to_free->size) {
HASH_DEL(scratch->glossary_hash, f); // Remove item from hash
free(f); // Free the fn_holder
}
-
stack_free(scratch->used_glossaries);
while (scratch->inline_glossaries_to_free->size) {
HASH_DEL(scratch->abbreviation_hash, f); // Remove item from hash
free(f); // Free the fn_holder
}
-
stack_free(scratch->used_abbreviations);
while (scratch->inline_abbreviations_to_free->size) {
}
stack_free(scratch->inline_abbreviations_to_free);
+
// Free metadata hash
meta * m, * m_tmp;
label = label->child;
switch (block->type) {
+ case BLOCK_DEF_ABBREVIATION:
case BLOCK_DEF_CITATION:
case BLOCK_DEF_FOOTNOTE:
case BLOCK_DEF_GLOSSARY:
- case BLOCK_DEF_ABBREVIATION:
switch (block->type) {
case BLOCK_DEF_ABBREVIATION:
// Strip leading '>'' from term
}
-char * mmd_process(DString * buffer, unsigned long extensions, short format, short language) {
- char * result;
-
- mmd_engine * e = mmd_engine_create_with_dstring(buffer, extensions);
-
- mmd_engine_set_language(e, language);
-
- mmd_engine_parse_string(e);
-
- DString * output = d_string_new("");
-
- mmd_export_token_tree(output, e, format);
-
- result = output->str;
-
- mmd_engine_free(e, false);
- d_string_free(output, false);
-
- return result;
-}
-
-
int main(int argc, char** argv) {
int exitcode = EXIT_SUCCESS;
char * binname = "multimarkdown";
if (FORMAT_MMD == format) {
result = buffer->str;
} else {
- result = mmd_process(buffer, extensions, format, language);
+ result = mmd_convert_d_string(buffer, extensions, format, language);
}
if (!(output_stream = fopen(output_filename, "w"))) {
if (FORMAT_MMD == format) {
result = buffer->str;
} else {
- result = mmd_process(buffer, extensions, format, language);
+ result = mmd_convert_d_string(buffer, extensions, format, language);
}
// Where does output go?