h1title.c 761 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdio.h>
  2. #include "markdown.h"
  3. static Paragraph *
  4. mkd_h1(Paragraph *p)
  5. {
  6. Paragraph *found;
  7. while ( p ) {
  8. if ( p->typ == HDR && p->hnumber == 1 )
  9. return p;
  10. if ( p->down && (found = mkd_h1(p->down)) )
  11. return found;
  12. p = p->next;
  13. }
  14. return 0;
  15. }
  16. char *
  17. mkd_h1_title(Document *doc, mkd_flag_t* flags)
  18. {
  19. Paragraph *title;
  20. if (doc && (title = mkd_h1(doc->code)) ) {
  21. char *generated;
  22. int size;
  23. /* assert that a H1 header is one line long, so that's
  24. * the only thing needed
  25. */
  26. set_mkd_flag(flags, MKD_TAGTEXT);
  27. size = mkd_line(T(title->text->text),
  28. S(title->text->text), &generated, flags);
  29. clear_mkd_flag(flags, MKD_TAGTEXT);
  30. if ( size ) return generated;
  31. }
  32. return 0;
  33. }