Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. #include "EXTERN.h"
  2. #include "perl.h"
  3. #include "XSUB.h"
  4. #include "ppport.h"
  5. #include <string.h>
  6. #include <mkdio.h>
  7. #include <cstring.h>
  8. typedef struct line {
  9. Cstring text;
  10. struct line *next;
  11. int dle;
  12. } Line;
  13. typedef struct paragraph {
  14. struct paragraph *next; /* next paragraph */
  15. struct paragraph *down; /* recompiled contents of this paragraph */
  16. struct line *text; /* all the text in this paragraph */
  17. char *ident; /* %id% tag for QUOTE */
  18. enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
  19. HTML, STYLE, DL, UL, OL, AL, LISTITEM,
  20. HDR, HR } typ;
  21. enum { IMPLICIT=0, PARA, CENTER} align;
  22. int hnumber; /* <Hn> for typ == HDR */
  23. } Paragraph;
  24. typedef struct document {
  25. Line *headers; /* title -> author(s) -> date */
  26. ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
  27. Paragraph *code; /* intermediate code generated by compile() */
  28. int compiled; /* set after mkd_compile() */
  29. int html; /* set after (internal) htmlify() */
  30. int tabstop; /* for properly expanding tabs (ick) */
  31. MMIOT *ctx; /* backend buffers, flags, and structures */
  32. char *base; /* url basename for url fragments */
  33. } Document;
  34. MODULE = Text::Markdown::Discount PACKAGE = Text::Markdown::Discount PREFIX = TextMarkdown_
  35. PROTOTYPES: DISABLE
  36. SV *
  37. TextMarkdown__markdown(text, uflags)
  38. char *text;
  39. int uflags;
  40. PREINIT:
  41. SV* r = &PL_sv_undef;
  42. int flags = MKD_TABSTOP | MKD_NOHEADER;
  43. char *html = NULL;
  44. int szhtml;
  45. Document *doc;
  46. CODE:
  47. if ( uflags ) {
  48. flags |= uflags;
  49. }
  50. if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
  51. croak("failed at mkd_string");
  52. }
  53. if ( !mkd_compile(doc, flags) ) {
  54. mkd_cleanup(doc);
  55. croak("failed at mkd_compile");
  56. }
  57. if ( (szhtml = mkd_document(doc, &html)) == EOF ) {;
  58. mkd_cleanup(doc);
  59. croak("failed at mkd_document");
  60. }
  61. r = newSVpvn(html, szhtml);
  62. sv_catpv(r, "\n");
  63. mkd_cleanup(doc);
  64. RETVAL = r;
  65. OUTPUT:
  66. RETVAL