h1title.c 689 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include <stdio.h>
#include "markdown.h"

static Paragraph *
mkd_h1(Paragraph *p)
{
    Paragraph *found;

    while ( p ) {
	if ( p->typ == HDR && p->hnumber == 1 )
	     return p;
       if ( p->down && (found = mkd_h1(p->down)) )
	   return found;
	p = p->next;
    }
    return 0;
}

char *
mkd_h1_title(Document *doc, int flags)
{
    Paragraph *title;

    if (doc && (title = mkd_h1(doc->code)) ) {
	  char *generated;
	  int size;

	  /* assert that a H1 header is one line long, so that's
	   * the only thing needed
	    */
	  size = mkd_line(T(title->text->text),
			  S(title->text->text), &generated, flags|MKD_TAGTEXT);
	  if ( size ) return generated;
    }
    return 0;
}