Sha256: 3e617467e397a588f1fca85ff8a25e578a8f661d684fe1578ebb115586141056

Contents?: true

Size: 1.61 KB

Versions: 99

Compression:

Stored size: 1.61 KB

Contents

/* markdown: a C implementation of John Gruber's Markdown markup language.
 *
 * Copyright (C) 2007 David L Parsons.
 * The redistribution terms are provided in the COPYRIGHT file that must
 * be distributed with this source code.
 */
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>

#include "config.h"

#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"

/* return the xml version of a character
 */
static char *
mkd_xmlchar(unsigned char c)
{
    switch (c) {
    case '<':   return "&lt;";
    case '>':   return "&gt;";
    case '&':   return "&amp;";
    case '"':   return "&quot;";
    case '\'':  return "&apos;";
    default:    if ( isascii(c) || (c & 0x80) )
		    return 0;
		return "";
    }
}


/* write output in XML format
 */
int
mkd_generatexml(char *p, int size, FILE *out)
{
    unsigned char c;
    char *entity;

    while ( size-- > 0 ) {
	c = *p++;

	if ( entity = mkd_xmlchar(c) )
	    fputs(entity, out);
	else
	    fputc(c, out);
    }
    return 0;
}


/* build a xml'ed version of a string
 */
int
mkd_xml(char *p, int size, char **res)
{
    unsigned char c;
    char *entity;
    Cstring f;

    CREATE(f);
    RESERVE(f, 100);

    while ( size-- > 0 ) {
	c = *p++;
	if ( entity = mkd_xmlchar(c) )
	    Cswrite(&f, entity, strlen(entity));
	else
	    Csputc(c, &f);
    }
			/* HACK ALERT! HACK ALERT! HACK ALERT! */
    *res = T(f);	/* we know that a T(Cstring) is a character pointer */
			/* so we can simply pick it up and carry it away, */
    return S(f);	/* leaving the husk of the Ctring on the stack */
			/* END HACK ALERT */
}

Version data entries

99 entries across 93 versions & 11 rubygems

Version Path
rdiscount-2.1.8 ext/xml.c
chaptastic-rdiscount-1.4.1 ext/xml.c
rdiscount_wm-3.1.0.0 ext/xml.c
rdiscount_wm-3.0.0.0 ext/xml.c
rdiscount-2.1.7.1 ext/xml.c
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/bluecloth-2.2.0/ext/xml.c
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/bluecloth-2.1.0/ext/xml.c
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/bluecloth-2.1.0/ext/xml.c
rdiscount-2.1.7 ext/xml.c
challah-1.0.0 vendor/bundle/gems/rdiscount-2.1.6/ext/xml.c
rdiscount-2.1.6 ext/xml.c
challah-1.0.0.beta3 vendor/bundle/gems/rdiscount-2.0.7.3/ext/xml.c
challah-1.0.0.beta3 vendor/bundle/gems/rdiscount-2.0.7.2/ext/xml.c
rdiscount-2.0.7.3 ext/xml.c
challah-1.0.0.beta2 vendor/bundle/gems/rdiscount-2.0.7.2/ext/xml.c
challah-1.0.0.beta vendor/bundle/gems/rdiscount-2.0.7.1/ext/xml.c
challah-1.0.0.beta vendor/bundle/gems/rdiscount-2.0.7.2/ext/xml.c
challah-1.0.0.beta vendor/bundle/gems/rdiscount-1.6.8/ext/xml.c
rdiscount-2.0.7.2 ext/xml.c
rdiscount-2.0.7.1 ext/xml.c