Example #1
0
static void
htmlify(Paragraph *p, char *block, MMIOT *f)
{
    emblock(f);
    if ( block ) Qprintf(f, "<%s>", block);
    emblock(f);

    while (( p = display(p, f) )) {
	emblock(f);
	Qstring("\n\n", f);
    }

    if ( block ) Qprintf(f, "</%s>", block);
    emblock(f);
}
Example #2
0
/*  public interface for reparse()
 */
int
mkd_text(char *bfr, int size, FILE *output, int flags)
{
    MMIOT f;

    ___mkd_initmmiot(&f, 0);
    f.flags = flags & USER_FLAGS;
    
    reparse(bfr, size, 0, &f);
    emblock(&f);
    if ( flags & CDATA_OUTPUT )
	___mkd_xml(T(f.out), S(f.out), output);
    else
	fwrite(T(f.out), S(f.out), 1, output);

    ___mkd_freemmiot(&f, 0);
    return 0;
}
Example #3
0
/* emmatch() -- match emphasis for a single emphasis token.
 */
static void
emmatch(MMIOT *f, int first, int last)
{
    block *start = &T(f->Q)[first];
    int e, e2, match;

    switch (start->b_count) {
    case 2: if ( e = empair(f,first,last,match=2) )
		break;
    case 1: e = empair(f,first,last,match=1);
	    break;
    case 0: return;
    default:
	    e = empair(f,first,last,1);
	    e2= empair(f,first,last,2);

	    if ( e2 >= e ) {
		e = e2;
		match = 2;
	    } 
	    else
		match = 1;
	    break;
    }

    if ( e ) {
	/* if we found emphasis to match, match it, recursively call
	 * emblock to match emphasis inside the new html block, add
	 * the emphasis markers for the block, then (tail) recursively
	 * call ourself to match any remaining emphasis on this token.
	 */
	block *end = &T(f->Q)[e];

	end->b_count -= match;
	start->b_count -= match;

	emblock(f, first, e);

	PREFIX(start->b_text, emtags[match-1].open, emtags[match-1].size-1);
	SUFFIX(end->b_post, emtags[match-1].close, emtags[match-1].size);

	emmatch(f, first, last);
    }
} /* emmatch */
Example #4
0
/* ___mkd_emblock() -- emblock a string of blocks, then concatenate the
 *                     resulting text onto f->out.
 */
void
___mkd_emblock(MMIOT *f)
{
    int i;
    block *p;

    emblock(f, 0, S(f->Q)-1);
    
    for (i=0; i < S(f->Q); i++) {
	p = &T(f->Q)[i];
	emfill(p);
	
	if ( S(p->b_post) ) { SUFFIX(f->out, T(p->b_post), S(p->b_post));
			      DELETE(p->b_post); }
	if ( S(p->b_text) ) { SUFFIX(f->out, T(p->b_text), S(p->b_text));
			      DELETE(p->b_text); }
    }
    
    S(f->Q) = 0;
} /* ___mkd_emblock */
Example #5
0
/* generate html from a markup fragment
 */
static void
reparse(char *bfr, int size, int flags, MMIOT *f)
{
    MMIOT sub;

    ___mkd_initmmiot(&sub, f->footnotes);
    
    sub.flags = f->flags | flags;
    sub.base = f->base;

    push(bfr, size, &sub);
    EXPAND(sub.in) = 0;
    S(sub.in)--;
    
    text(&sub);
    emblock(&sub);
    
    Qwrite(T(sub.out), S(sub.out), f);

    ___mkd_freemmiot(&sub, f->footnotes);
}