docheader.c 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * docheader -- get values from the document header
  3. *
  4. * Copyright (C) 2007 David L Parsons.
  5. * The redistribution terms are provided in the COPYRIGHT file that must
  6. * be distributed with this source code.
  7. */
  8. #include "config.h"
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <ctype.h>
  12. #include "cstring.h"
  13. #include "markdown.h"
  14. #include "amalloc.h"
  15. static char *
  16. onlyifset(Line *l)
  17. {
  18. char *ret;
  19. if ( l->dle < 0 || l->dle >= S(l->text) )
  20. return 0;
  21. ret = T(l->text) + l->dle;
  22. return ret[0] ? ret : 0;
  23. }
  24. char *
  25. mkd_doc_title(Document *doc)
  26. {
  27. if ( doc && doc->title )
  28. return onlyifset(doc->title);
  29. return 0;
  30. }
  31. char *
  32. mkd_doc_author(Document *doc)
  33. {
  34. if ( doc && doc->author )
  35. return onlyifset(doc->author);
  36. return 0;
  37. }
  38. char *
  39. mkd_doc_date(Document *doc)
  40. {
  41. if ( doc && doc->date )
  42. return onlyifset(doc->date);
  43. return 0;
  44. }