コード例 #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;
}
コード例 #2
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);

    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
ファイル: parsing_functions.c プロジェクト: 3rdpaw/MdCharm
element * parse_markdown_with_metadata(char *string, int extensions, element *reference_list, element *note_list, element *label_list) {

    char *oldcharbuf;
    syntax_extensions = extensions;
    references = reference_list;
    notes = note_list;
    labels = label_list;

    oldcharbuf = charbuf;
    charbuf = string;

	start_time = clock();

    yyparsefrom(yy_DocWithMetaData);
    charbuf = oldcharbuf;          /* restore charbuf to original value */

    /* reset start_time for subsequent passes */
    start_time = 0;
    
    if (parse_aborted) {
        parse_aborted = 0;
        free_element_list(parse_result);
        return NULL;
    }

    return parse_result;

}
コード例 #4
0
ファイル: parsing_functions.c プロジェクト: BYC/geany-plugins
/* free_element_contents - free element contents depending on type */
static void free_element_contents(element elt) {
    switch (elt.key) {
      case STR:
      case SPACE:
      case RAW:
      case HTMLBLOCK:
      case HTML:
      case VERBATIM:
      case CODE:
      case NOTE:
        free(elt.contents.str);
        elt.contents.str = NULL;
        break;
      case LINK:
      case IMAGE:
      case REFERENCE:
        free(elt.contents.link->url);
        elt.contents.link->url = NULL;
        free(elt.contents.link->title);
        elt.contents.link->title = NULL;
        free_element_list(elt.contents.link->label);
        free(elt.contents.link);
        elt.contents.link = NULL;
        break;
      default:
        ;
    }
}
コード例 #5
0
ファイル: parsing_functions.c プロジェクト: 3rdpaw/MdCharm
/* free_element_list - free list of elements recursively */
void free_element_list(element * elt) {
    element * next = NULL;
    while (elt != NULL) {
        next = elt->next;
        free_element_contents(*elt);
        if (elt->children != NULL) {
            free_element_list(elt->children);
            elt->children = NULL;
        }
        free(elt);
        elt = next;
    }
}
コード例 #6
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;
    GString *formatted_text;

    formatted_text = preformat_text(text);
    
    result = parse_metadata_only(formatted_text->str, extensions);
    
    value = metavalue_for_key(key, result->children);
    free_element_list(result);
    return value;
}
コード例 #7
0
void omadmclient_session_close(dmclt_session sessionH)
{
    internals_t * internP = (internals_t *)sessionH;

    if(!internP)
    {
        return;
    }

    if (internP->dmtreeH)
    {
        dmtree_close(internP->dmtreeH);
    }
    if (internP->smlH)
    {
        smlTerminateInstance(internP->smlH);
    }
    if (internP->elem_first)
    {
        free_element_list(internP->elem_first);
    }
    if (internP->old_elem)
    {
        free_element_list(internP->old_elem);
    }
    if (internP->reply_ref)
    {
        free(internP->reply_ref);
    }
    if (internP->account)
    {
        if (internP->account->id) free(internP->account->id);
        if (internP->account->server_uri) free(internP->account->server_uri);
        if (internP->account->dmtree_uri) free(internP->account->dmtree_uri);
        prvFreeAuth(internP->account->toServerCred);
        prvFreeAuth(internP->account->toClientCred);
    }
    memset(internP, 0, sizeof(internals_t));
}
コード例 #8
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;
}
コード例 #9
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;
}
コード例 #10
0
ファイル: markdown_lib.c プロジェクト: proudzhu/peg-markdown
/* 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;
}
コード例 #11
0
ファイル: parsing_functions.c プロジェクト: 3rdpaw/MdCharm
/* free_element_contents - free element contents depending on type */
static void free_element_contents(element elt) {
    switch (elt.key) {
      case STR:
      case SPACE:
      case RAW:
      case HTMLBLOCK:
      case HTML:
      case VERBATIM:
      case CODE:
      case NOTE:
      case AUTOLABEL:
      case CITATION:
      case TERM:
      case METAKEY:
      case METAVALUE:
      case TABLESEPARATOR:
      case ATTRKEY:
      case GLOSSARY:
      case GLOSSARYTERM:
      case NOTELABEL:
      case CELLSPAN:
      case EMDASH:
      case ENDASH:
      case GLOSSARYSORTKEY:
      case MATHSPAN:
        free(elt.contents.str);
        elt.contents.str = NULL;
        break;
      case LINK:
      case IMAGE:
      case REFERENCE:
        free(elt.contents.link->url);
        elt.contents.link->url = NULL;
        free(elt.contents.link->title);
        elt.contents.link->title = NULL;
        free_element_list(elt.contents.link->label);
        free(elt.contents.link->identifier);
        elt.contents.link->identifier = NULL;
/*        free_element_list(elt.contents.link->attr);*/
        free(elt.contents.link);
        elt.contents.link = NULL;
        break;
      default:
        ;
    }
}
コード例 #12
0
element * parse_markdown_with_metadata(char *string, int extensions, element *reference_list, element *note_list, element *label_list) {

    yycontext *context = create_parsing_context(string, extensions, reference_list, note_list, label_list);
	context->state->start_time = clock();
	
	yyparsefrom(context, yy_DocWithMetaData);
	
	element *parse_result = context->state->parse_result;
	int is_aborted = context->state->parse_aborted;
	
	free_parsing_context(context);
	
    if (is_aborted) {
        free_element_list(parse_result);
        return NULL;
    }

    return parse_result;

}