From 935df35140d6731e2c44033ca75d0e0dafa04c71 Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Mon, 1 May 2017 08:40:24 -0400 Subject: [PATCH] Sync up with MMD upstream. --- doc/mxml.man | 2 +- mmd.c | 37 ++++++++++++++++++++++++++++--------- mmd.h | 10 ++++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/doc/mxml.man b/doc/mxml.man index d5a7a5d..9365d16 100644 --- a/doc/mxml.man +++ b/doc/mxml.man @@ -1,4 +1,4 @@ -.TH mxml 3 "Mini-XML API" "04/30/17" "Mini-XML API" +.TH mxml 3 "Mini-XML API" "05/01/17" "Mini-XML API" .SH NAME mxml \- Mini-XML API .SH INCLUDE FILE diff --git a/mmd.c b/mmd.c index d6bb113..4d63b59 100644 --- a/mmd.c +++ b/mmd.c @@ -32,7 +32,6 @@ */ #include "mmd.h" -#include #include #include #include @@ -277,6 +276,31 @@ mmd_t * /* O - First node in markdown */ mmdLoad(const char *filename) /* I - File to load */ { FILE *fp; /* File */ + mmd_t *doc; /* Document */ + + + /* + * Open the file and create an empty document... + */ + + if ((fp = fopen(filename, "r")) == NULL) + return (NULL); + + doc = mmdLoadFile(fp); + + fclose(fp); + + return (doc); +} + + +/* + * 'mmdLoadFile()' - Load a markdown file into nodes from a stdio file. + */ + +mmd_t * /* O - First node in markdown */ +mmdLoadFile(FILE *fp) /* I - File to load */ +{ mmd_t *doc, /* Document */ *current, /* Current parent block */ *block = NULL; /* Current block */ @@ -288,12 +312,9 @@ mmdLoad(const char *filename) /* I - File to load */ /* - * Open the file and create an empty document... + * Create an empty document... */ - if ((fp = fopen(filename, "r")) == NULL) - return (NULL); - doc = current = mmd_add(NULL, MMD_TYPE_DOCUMENT, 0, NULL, NULL); if (!doc) @@ -580,8 +601,6 @@ mmdLoad(const char *filename) /* I - File to load */ mmd_parse_inline(block, lineptr); } - fclose(fp); - return (doc); } @@ -782,8 +801,6 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */ else type = MMD_TYPE_NORMAL_TEXT; } - else - type = MMD_TYPE_NORMAL_TEXT; if (!*lineptr) break; @@ -803,6 +820,7 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */ text = NULL; whitespace = 0; + type = MMD_TYPE_NORMAL_TEXT; } else if (*lineptr == '`' && type == MMD_TYPE_CODE_TEXT) { @@ -811,6 +829,7 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */ text = NULL; whitespace = 0; + type = MMD_TYPE_NORMAL_TEXT; } else if (*lineptr == '\\' && lineptr[1]) { diff --git a/mmd.h b/mmd.h index c0f8ef3..d29f045 100644 --- a/mmd.h +++ b/mmd.h @@ -34,6 +34,7 @@ * Include necessary headers... */ +# include /* @@ -82,6 +83,10 @@ typedef struct _mmd_s mmd_t; * Functions... */ +# ifdef __cplusplus +extern "C" { +# endif /* __cplusplus */ + extern void mmdFree(mmd_t *node); extern mmd_t *mmdGetFirstChild(mmd_t *node); extern mmd_t *mmdGetLastChild(mmd_t *node); @@ -95,5 +100,10 @@ extern const char *mmdGetURL(mmd_t *node); extern int mmdGetWhitespace(mmd_t *node); extern int mmdIsBlock(mmd_t *node); extern mmd_t *mmdLoad(const char *filename); +extern mmd_t *mmdLoadFile(FILE *fp); + +# ifdef __cplusplus +} +# endif /* __cplusplus */ #endif /* !MMD_H */