mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-24 11:25:30 +00:00
Update Markdown support.
This commit is contained in:
parent
b06830dc0d
commit
f1f1703050
@ -1,4 +1,4 @@
|
||||
.TH mxml 3 "Mini-XML API" "04/11/17" "Mini-XML API"
|
||||
.TH mxml 3 "Mini-XML API" "04/21/17" "Mini-XML API"
|
||||
.SH NAME
|
||||
mxml \- Mini-XML API
|
||||
.SH INCLUDE FILE
|
||||
|
24
mmd.c
24
mmd.c
@ -296,6 +296,12 @@ mmdLoad(const char *filename) /* I - File to load */
|
||||
|
||||
doc = current = mmd_add(NULL, MMD_TYPE_DOCUMENT, 0, NULL, NULL);
|
||||
|
||||
if (!doc)
|
||||
{
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read lines until end-of-file...
|
||||
*/
|
||||
@ -718,7 +724,17 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
|
||||
|
||||
lineptr = mmd_parse_link(lineptr, &text, &url);
|
||||
|
||||
if (text)
|
||||
if (text && *text == '`')
|
||||
{
|
||||
char *end = text + strlen(text) - 1;
|
||||
|
||||
text ++;
|
||||
if (end > text && *end == '`')
|
||||
*end = '\0';
|
||||
|
||||
mmd_add(parent, MMD_TYPE_CODE_TEXT, whitespace, text, url);
|
||||
}
|
||||
else if (text)
|
||||
mmd_add(parent, MMD_TYPE_LINKED_TEXT, whitespace, text, url);
|
||||
|
||||
if (!*lineptr)
|
||||
@ -816,9 +832,9 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
|
||||
*/
|
||||
|
||||
static char * /* O - End of link text */
|
||||
mmd_parse_link(char *lineptr, /* I - Pointer into line */
|
||||
char **text, /* O - Text */
|
||||
char **url) /* O - URL */
|
||||
mmd_parse_link(char *lineptr, /* I - Pointer into line */
|
||||
char **text, /* O - Text */
|
||||
char **url) /* O - URL */
|
||||
{
|
||||
lineptr ++; /* skip "[" */
|
||||
|
||||
|
25
mxmldoc.c
25
mxmldoc.c
@ -173,7 +173,7 @@ static int is_markdown(const char *filename);
|
||||
static mxml_type_t load_cb(mxml_node_t *node);
|
||||
static const char *markdown_anchor(const char *text);
|
||||
static void markdown_write_block(FILE *out, mmd_t *parent, int mode);
|
||||
static void markdown_write_inline(FILE *out, mmd_t *node, int mode);
|
||||
static void markdown_write_leaf(FILE *out, mmd_t *node, int mode);
|
||||
static mxml_node_t *new_documentation(mxml_node_t **mxmldoc);
|
||||
static int remove_directory(const char *path);
|
||||
static void safe_strcpy(char *dst, const char *src);
|
||||
@ -915,10 +915,7 @@ build_toc(mxml_node_t *doc, /* I - Documentation */
|
||||
}
|
||||
|
||||
add_toc(toc, type - MMD_TYPE_HEADING_1 + 1, markdown_anchor(title), title);
|
||||
next = NULL;
|
||||
}
|
||||
else
|
||||
next = mmdGetFirstChild(node);
|
||||
|
||||
if ((next = mmdGetNextSibling(node)) == NULL)
|
||||
{
|
||||
@ -1518,7 +1515,7 @@ markdown_write_block(FILE *out, /* I - Output file */
|
||||
if (mmdIsBlock(node))
|
||||
markdown_write_block(out, node, mode);
|
||||
else
|
||||
markdown_write_inline(out, node, mode);
|
||||
markdown_write_leaf(out, node, mode);
|
||||
}
|
||||
|
||||
fputs("\n", out);
|
||||
@ -1611,7 +1608,7 @@ markdown_write_block(FILE *out, /* I - Output file */
|
||||
if (mmdIsBlock(node))
|
||||
markdown_write_block(out, node, mode);
|
||||
else
|
||||
markdown_write_inline(out, node, mode);
|
||||
markdown_write_leaf(out, node, mode);
|
||||
}
|
||||
|
||||
if (type >= MMD_TYPE_HEADING_1 && type <= MMD_TYPE_HEADING_6)
|
||||
@ -1623,13 +1620,13 @@ markdown_write_block(FILE *out, /* I - Output file */
|
||||
|
||||
|
||||
/*
|
||||
* 'markdown_write_inline()' - Write an inline markdown node.
|
||||
* 'markdown_write_leaf()' - Write an leaf markdown node.
|
||||
*/
|
||||
|
||||
static void
|
||||
markdown_write_inline(FILE *out, /* I - Output file */
|
||||
mmd_t *node, /* I - Node to write */
|
||||
int mode) /* I - Output mode */
|
||||
markdown_write_leaf(FILE *out, /* I - Output file */
|
||||
mmd_t *node, /* I - Node to write */
|
||||
int mode) /* I - Output mode */
|
||||
{
|
||||
const char *text, /* Text to write */
|
||||
*url; /* URL to write */
|
||||
@ -1704,7 +1701,7 @@ markdown_write_inline(FILE *out, /* I - Output file */
|
||||
break;
|
||||
|
||||
case MMD_TYPE_LINKED_TEXT :
|
||||
element = "a";
|
||||
element = NULL;
|
||||
break;
|
||||
|
||||
case MMD_TYPE_CODE_TEXT :
|
||||
@ -1751,7 +1748,8 @@ markdown_write_inline(FILE *out, /* I - Output file */
|
||||
else
|
||||
fprintf(out, "<a href=\"%s\">", url);
|
||||
}
|
||||
else if (element)
|
||||
|
||||
if (element)
|
||||
fprintf(out, "<%s>", element);
|
||||
|
||||
if (!strcmp(text, "(c)"))
|
||||
@ -1765,6 +1763,9 @@ markdown_write_inline(FILE *out, /* I - Output file */
|
||||
|
||||
if (element)
|
||||
fprintf(out, "</%s>", element);
|
||||
|
||||
if (url)
|
||||
fputs("</a>", out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
/* End PBXAggregateTarget section */
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
271227FF1EAADBE200167F24 /* mmd.c in Sources */ = {isa = PBXBuildFile; fileRef = 271227FD1EAADBE200167F24 /* mmd.c */; };
|
||||
272C00191E8C66C8007EBCAC /* mxml-attr.c in Sources */ = {isa = PBXBuildFile; fileRef = 272C000D1E8C66C8007EBCAC /* mxml-attr.c */; };
|
||||
272C001A1E8C66C8007EBCAC /* mxml-entity.c in Sources */ = {isa = PBXBuildFile; fileRef = 272C000E1E8C66C8007EBCAC /* mxml-entity.c */; };
|
||||
272C001B1E8C66C8007EBCAC /* mxml-file.c in Sources */ = {isa = PBXBuildFile; fileRef = 272C000F1E8C66C8007EBCAC /* mxml-file.c */; };
|
||||
@ -104,6 +105,8 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
271227FD1EAADBE200167F24 /* mmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mmd.c; path = ../mmd.c; sourceTree = "<group>"; };
|
||||
271227FE1EAADBE200167F24 /* mmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mmd.h; path = ../mmd.h; sourceTree = "<group>"; };
|
||||
272C00051E8C6664007EBCAC /* libmxml.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmxml.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
272C000D1E8C66C8007EBCAC /* mxml-attr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "mxml-attr.c"; path = "../mxml-attr.c"; sourceTree = "<group>"; };
|
||||
272C000E1E8C66C8007EBCAC /* mxml-entity.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "mxml-entity.c"; path = "../mxml-entity.c"; sourceTree = "<group>"; };
|
||||
@ -189,6 +192,8 @@
|
||||
272C00321E8C6ABB007EBCAC /* tools */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
271227FD1EAADBE200167F24 /* mmd.c */,
|
||||
271227FE1EAADBE200167F24 /* mmd.h */,
|
||||
272C00331E8C6ADE007EBCAC /* mxmldoc.c */,
|
||||
272C00401E8C6B1B007EBCAC /* testmxml.c */,
|
||||
272C00571E943266007EBCAC /* zipc.c */,
|
||||
@ -358,6 +363,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
271227FF1EAADBE200167F24 /* mmd.c in Sources */,
|
||||
272C00431E8C6B34007EBCAC /* mxmldoc.c in Sources */,
|
||||
272C00591E943266007EBCAC /* zipc.c in Sources */,
|
||||
);
|
||||
@ -601,6 +607,7 @@
|
||||
272C00301E8C6A94007EBCAC /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
272C003D1E8C6AEB007EBCAC /* Build configuration list for PBXNativeTarget "testmxml" */ = {
|
||||
isa = XCConfigurationList;
|
||||
@ -609,6 +616,7 @@
|
||||
272C003F1E8C6AEB007EBCAC /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
272C00451E8C6B5A007EBCAC /* Build configuration list for PBXAggregateTarget "All" */ = {
|
||||
isa = XCConfigurationList;
|
||||
@ -617,6 +625,7 @@
|
||||
272C00471E8C6B5A007EBCAC /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user