From: Fletcher T. Penney Date: Fri, 18 Aug 2017 21:56:25 +0000 (-0400) Subject: ADDED: Add function to extract transclusion manifest X-Git-Tag: 6.2.1^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70f66c574c335797f4141ab5b7332b984de22345;p=multimarkdown ADDED: Add function to extract transclusion manifest --- diff --git a/Sources/libMultiMarkdown/include/libMultiMarkdown.h b/Sources/libMultiMarkdown/include/libMultiMarkdown.h index 6ee276b..7763f27 100644 --- a/Sources/libMultiMarkdown/include/libMultiMarkdown.h +++ b/Sources/libMultiMarkdown/include/libMultiMarkdown.h @@ -123,6 +123,12 @@ char * mmd_string_metavalue_for_key(char * source, const char * key); char * mmd_string_update_metavalue_for_key(const char * source, const char * key, const char * value); +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +struct stack * mmd_string_transclusion_manifest(const char * source, const char * search_path, const char * source_path); + + /* @@ -163,6 +169,12 @@ char * mmd_d_string_metavalue_for_key(DString * source, const char * key); void mmd_d_string_update_metavalue_for_key(DString * source, const char * key, const char * value); +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +struct stack * mmd_d_string_transclusion_manifest(DString * source, const char * search_path, const char * source_path); + + /* @@ -248,6 +260,12 @@ char * mmd_engine_metavalue_for_key(mmd_engine * e, const char * key); void mmd_engine_update_metavalue_for_key(mmd_engine * e, const char * key, const char * value); +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +struct stack * mmd_engine_transclusion_manifest(mmd_engine * e, const char * search_path, const char * source_path); + + /* diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index e0e3ee1..bc0c0cd 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -2402,6 +2402,56 @@ char * mmd_engine_metavalue_for_key(mmd_engine * e, const char * key) { } +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +stack * mmd_string_transclusion_manifest(const char * source, const char * search_path, const char * source_path) { + stack * result; + + mmd_engine * e = mmd_engine_create_with_string(source, 0); + + result = mmd_engine_transclusion_manifest(e, search_path, source_path); + + mmd_engine_free(e, true); + + return result; +} + + +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +stack * mmd_d_string_transclusion_manifest(DString * source, const char * search_path, const char * source_path) { + stack * result; + + mmd_engine * e = mmd_engine_create_with_dstring(source, 0); + + result = mmd_engine_transclusion_manifest(e, search_path, source_path); + + mmd_engine_free(e, false); + + return result; +} + + +/// Grab list of all transcluded files, but we need to know directory to search, +/// as well as the path to the file +/// Returned stack needs to be freed +stack * mmd_engine_transclusion_manifest(mmd_engine * e, const char * search_path, const char * source_path) { + // Create empty manifest stack + stack * manifest = stack_new(0); + + // Copy source text for temporary buffer + DString * buffer = d_string_new(e->dstr->str); + + mmd_transclude_source(buffer, search_path, source_path, FORMAT_HTML, NULL, manifest); + + d_string_free(buffer, true); + + return manifest; +} + + /// Insert/replace metadata in string, returning new string char * mmd_string_update_metavalue_for_key(const char * source, const char * key, const char * value) { mmd_engine * e = mmd_engine_create_with_string(source, 0);