From: Fletcher T. Penney Date: Sun, 29 Jan 2017 00:42:36 +0000 (-0500) Subject: ADDED: Add support for metadata variables X-Git-Tag: 0.1.1a^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32ad9f8b5526027a9da202676ad6f360f323b34e;p=multimarkdown ADDED: Add support for metadata variables --- diff --git a/src/html.c b/src/html.c index 9fb9a6f..b56eac8 100644 --- a/src/html.c +++ b/src/html.c @@ -271,11 +271,12 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t if (t == NULL) return; - short temp_short; - link * temp_link = NULL; - char * temp_char = NULL; - bool temp_bool = 0; - token * temp_token = NULL; + short temp_short; + link * temp_link = NULL; + char * temp_char = NULL; + char * temp_char2 = NULL; + bool temp_bool = 0; + token * temp_token = NULL; switch (t->type) { case AMPERSAND: @@ -742,7 +743,16 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t } break; case PAIR_BRACKET_VARIABLE: - print_token(t); + temp_char = text_inside_pair(source, t); + temp_char2 = extract_metadata(scratch, temp_char); + + if (temp_char2) + mmd_print_string_html(out, temp_char2, false); + else + mmd_export_token_tree_html(out, source, t->child, offset, scratch); + + // Don't free temp_char2 (it belongs to meta *) + free(temp_char); break; case PAIR_CRITIC_ADD: // Ignore if we're rejecting diff --git a/src/writer.c b/src/writer.c index 0d11873..13d4758 100644 --- a/src/writer.c +++ b/src/writer.c @@ -844,6 +844,18 @@ meta * extract_meta_from_stack(scratch_pad * scratch, const char * target) { } +char * extract_metadata(scratch_pad * scratch, const char * target) { + char * clean = label_from_string(target); + + meta * m = extract_meta_from_stack(scratch, clean); + free(clean); + if (m) + return m->value; + + return NULL; +} + + bool definition_extract(mmd_engine * e, token ** remainder) { char * source = e->dstr->str; token * label = NULL; diff --git a/src/writer.h b/src/writer.h index f02c28c..a1037d2 100644 --- a/src/writer.h +++ b/src/writer.h @@ -180,6 +180,7 @@ void citation_from_bracket(const char * source, scratch_pad * scratch, token * t meta * meta_new(const char * source, size_t start, size_t len); void meta_set_value(meta * m, const char * value); void meta_free(meta * m); +char * extract_metadata(scratch_pad * scratch, const char * target); #endif diff --git a/tests/MMD6Tests/Variables.html b/tests/MMD6Tests/Variables.html new file mode 100644 index 0000000..62962d9 --- /dev/null +++ b/tests/MMD6Tests/Variables.html @@ -0,0 +1,20 @@ + + + + + *foo* "bar" + + + + + +

foo: bar

+ +

bar foo bar foo bar

+ +

[%bar]

+ +

**foo**

+ + + diff --git a/tests/MMD6Tests/Variables.htmlc b/tests/MMD6Tests/Variables.htmlc new file mode 100644 index 0000000..1baf610 --- /dev/null +++ b/tests/MMD6Tests/Variables.htmlc @@ -0,0 +1,14 @@ +

title: foo "bar" +foo: bar +foo bar +foo bar +foo: bar +bat: foo

+ +

foo: bar

+ +

[%foo]

+ +

[%bar]

+ +

[%bat]

diff --git a/tests/MMD6Tests/Variables.text b/tests/MMD6Tests/Variables.text new file mode 100644 index 0000000..b63ffaa --- /dev/null +++ b/tests/MMD6Tests/Variables.text @@ -0,0 +1,14 @@ +title: *foo* "bar" +foo: bar +foo bar + foo bar +foo: *bar* +bat: **foo** + +foo: bar + +[%foo] + +[%bar] + +[%bat]