예제 #1
0
/* has_metadata - parse document and report whether metadata is present */
gboolean has_metadata(char *text, int extensions) {
    gboolean hasMeta;
    element *result;
    element *references;
    element *notes;
    element *labels;
    GString *formatted_text;
    
    formatted_text = preformat_text(text);

    references = parse_references(formatted_text->str, extensions);
    notes = parse_notes(formatted_text->str, extensions, references);
    labels = parse_labels(formatted_text->str, extensions, references, notes);
    
    result = parse_metadata_only(formatted_text->str, extensions);

    hasMeta = FALSE;
    
    if (result != NULL) {
        if (result->children != NULL) {
            hasMeta = TRUE;
            free_element_list(result);
        } else {
            free_element(result);
        }
    }

    free_element_list(references);
    free_element_list(labels);
    return hasMeta;
}
/* markdown_to_gstring - convert markdown text to the output format specified.
 * Returns a GString, which must be freed after use using g_string_free(). */
GString * markdown_to_g_string(char *text, int extensions, int output_format) {
    element *result;
    element *references;
    element *notes;
    element *labels;
    GString *formatted_text;
    GString *out;
    out = g_string_new("");

    formatted_text = preformat_text(text);

    if (output_format == OPML_FORMAT) {
        result = parse_markdown_for_opml(formatted_text->str, extensions);
    } else {
        references = parse_references(formatted_text->str, extensions);
        notes = parse_notes(formatted_text->str, extensions, references);
        labels = parse_labels(formatted_text->str, extensions, references, notes);
        result = parse_markdown_with_metadata(formatted_text->str, extensions, references, notes, labels);

        result = process_raw_blocks(result, extensions, references, notes, labels);
    }

    g_string_free(formatted_text, TRUE);

    print_element_list(out, result, output_format, extensions);

    free_element_list(result);

    if (output_format != OPML_FORMAT) {
        free_element_list(references);
        free_element_list(labels);
    }
    return out;
}
예제 #3
0
/* extract_metadata_value - parse document and return value of specified
   metadata key (e.g. "LateX Mode")/
   Returns a null-terminated string, which must be freed after use. */
char * extract_metadata_value(char *text, int extensions, char *key) {
    char *value;
    element *result;
    element *references;
    element *notes;
    element *labels;
    GString *formatted_text;

    formatted_text = preformat_text(text);

    references = parse_references(formatted_text->str, extensions);
    notes = parse_notes(formatted_text->str, extensions, references);
    labels = parse_labels(formatted_text->str, extensions, references, notes);

    result = parse_metadata_only(formatted_text->str, extensions);

    value = metavalue_for_key(key, result);
    free_element_list(result);
    free_element_list(references);
    free_element_list(labels);

    return value;
}
예제 #4
0
/* markdown_to_gstring - convert markdown text to the output format specified.
 * Returns a GString, which must be freed after use using g_string_free(). */
GString * markdown_to_g_string(char *text, int extensions, int output_format) {
    element *result;
    element *references;
    element *notes;
    element *labels;
    GString *formatted_text;
    GString *out;
    out = g_string_new("");

    formatted_text = preformat_text(text);

    references = parse_references(formatted_text->str, extensions);
    notes = parse_notes(formatted_text->str, extensions, references);
    labels = parse_labels(formatted_text->str, extensions, references, notes);

    if (output_format == OPML_FORMAT) {
        result = parse_markdown_for_opml(formatted_text->str, extensions);
    } else {
        result = parse_markdown_with_metadata(formatted_text->str, extensions, references, notes, labels);
        result = process_raw_blocks(result, extensions, references, notes, labels);
    }

    g_string_free(formatted_text, TRUE);

    if (result == NULL) {
        /* The parsing was aborted */
        g_string_append(out,"MultiMarkdown was unable to parse this file.");
    } else {
        print_element_list(out, result, output_format, extensions);
    }
    free_element_list(result);

    free_element_list(references);
    free_element_list(labels);

    return out;
}
예제 #5
0
/* markdown_to_gstring - convert markdown text to the output format specified.
 * Returns a GString, which must be freed after use using g_string_free(). */
GString * markdown_to_g_string(const char *text, int extensions, int output_format) {
    element *result;
    element *references;
    element *notes;
    GString *formatted_text;
    GString *out;
    out = g_string_new("");

    formatted_text = preformat_text(text);

    references = parse_references(formatted_text->str, extensions);
    notes = parse_notes(formatted_text->str, extensions, references);
    result = parse_markdown(formatted_text->str, extensions, references, notes);

    result = process_raw_blocks(result, extensions, references, notes);

    g_string_free(formatted_text, TRUE);

    print_element_list(out, result, output_format, extensions);

    free_element_list(result);
    free_element_list(references);
    return out;
}