Repository: lucy-clownfish Updated Branches: refs/heads/master c41b4f2d1 -> 32e2701aa
Fix bug in Markdown to POD converter Links with multiple text children weren't converted correctly. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4df28552 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4df28552 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4df28552 Branch: refs/heads/master Commit: 4df28552a17cb5f851af4faaa1f138329b592502 Parents: c41b4f2 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Mon Feb 22 20:06:46 2016 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Mon Feb 22 20:06:46 2016 +0100 ---------------------------------------------------------------------- compiler/src/CFCPerlPod.c | 22 +++++++++++++++++++++- compiler/src/CFCTestDocuComment.c | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4df28552/compiler/src/CFCPerlPod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlPod.c b/compiler/src/CFCPerlPod.c index 8330007..996b4c2 100644 --- a/compiler/src/CFCPerlPod.c +++ b/compiler/src/CFCPerlPod.c @@ -88,6 +88,9 @@ static char* S_nodes_to_pod(cmark_node *node, CFCClass *klass, int header_level); static char* +S_node_to_pod(cmark_node *node, CFCClass *klass, int header_level); + +static char* S_pod_escape(const char *content); static char* @@ -581,15 +584,32 @@ CFCPerlPod_md_to_pod(const char *md, CFCClass *klass, int header_level) { | CMARK_OPT_VALIDATE_UTF8 | CMARK_OPT_SAFE; cmark_node *doc = cmark_parse_document(md, strlen(md), options); - char *pod = S_nodes_to_pod(doc, klass, header_level); + char *pod = S_node_to_pod(doc, klass, header_level); cmark_node_free(doc); return pod; } +// Convert a node and its siblings. static char* S_nodes_to_pod(cmark_node *node, CFCClass *klass, int header_level) { char *result = CFCUtil_strdup(""); + + while (node != NULL) { + char *pod = S_node_to_pod(node, klass, header_level); + result = CFCUtil_cat(result, pod, NULL); + FREEMEM(pod); + + node = cmark_node_next(node); + } + + return result; +} + +// Convert a single node. +static char* +S_node_to_pod(cmark_node *node, CFCClass *klass, int header_level) { + char *result = CFCUtil_strdup(""); if (node == NULL) { return result; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4df28552/compiler/src/CFCTestDocuComment.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestDocuComment.c b/compiler/src/CFCTestDocuComment.c index dc89f94..69ab177 100644 --- a/compiler/src/CFCTestDocuComment.c +++ b/compiler/src/CFCTestDocuComment.c @@ -38,7 +38,7 @@ S_run_tests(CFCTest *test); const CFCTestBatch CFCTEST_BATCH_DOCU_COMMENT = { "Clownfish::CFC::Model::DocuComment", - 18, + 19, S_run_tests }; @@ -118,6 +118,19 @@ S_test_parser(CFCTest *test) { } static void +S_test_md_to_pod(CFCTest *test) { + const char *md = + "[Link\n" + "with newline](http://example.com/)\n"; + char *pod = CFCPerlPod_md_to_pod(md, NULL, 1); + const char *expect = + "L<Link\n" + "with newline|http://example.com/>\n\n"; + STR_EQ(test, pod, expect, "Markdown link with newline to POD"); + FREEMEM(pod); +} + +static void S_test_generator(CFCTest *test) { CFCHierarchy *hierarchy = CFCHierarchy_new("autogen"); CFCParcel *parcel = CFCParcel_new("Neato", NULL, NULL, NULL); @@ -306,6 +319,7 @@ S_test_generator(CFCTest *test) { static void S_run_tests(CFCTest *test) { S_test_parser(test); + S_test_md_to_pod(test); S_test_generator(test); }