]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add support for metadata variables
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 29 Jan 2017 00:42:36 +0000 (19:42 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 29 Jan 2017 00:42:36 +0000 (19:42 -0500)
src/html.c
src/writer.c
src/writer.h
tests/MMD6Tests/Variables.html [new file with mode: 0644]
tests/MMD6Tests/Variables.htmlc [new file with mode: 0644]
tests/MMD6Tests/Variables.text [new file with mode: 0644]

index 9fb9a6fb4a53d033ad0b327e8552bab3bad6f381..b56eac86d9ac1b38ad208b6c1b8c07775534f95c 100644 (file)
@@ -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
index 0d11873e96d755e328aa8ba606aa8e56db29fcd3..13d4758ea860ffb29d06cee552a109e6bd017d67 100644 (file)
@@ -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;
index f02c28c06109e52e1c27fc7f9cec5a7d61793031..a1037d2c16d5132f3c77a751da9c3e2501116b39 100644 (file)
@@ -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 (file)
index 0000000..62962d9
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+       <meta charset="utf-8"/>
+       <title>*foo* &quot;bar&quot;</title>
+       <meta name="foo" content="bar foo bar foo bar"/>
+       <meta name="bat" content="**foo**"/>
+</head>
+<body>
+
+<p>foo:        bar</p>
+
+<p>bar foo bar foo bar</p>
+
+<p>[%bar]</p>
+
+<p>**foo**</p>
+
+</body>
+</html>
diff --git a/tests/MMD6Tests/Variables.htmlc b/tests/MMD6Tests/Variables.htmlc
new file mode 100644 (file)
index 0000000..1baf610
--- /dev/null
@@ -0,0 +1,14 @@
+<p>title:      <em>foo</em> &quot;bar&quot;
+foo:   bar
+foo bar
+foo bar
+foo:   <em>bar</em>
+bat:   <strong>foo</strong></p>
+
+<p>foo:        bar</p>
+
+<p>[%foo]</p>
+
+<p>[%bar]</p>
+
+<p>[%bat]</p>
diff --git a/tests/MMD6Tests/Variables.text b/tests/MMD6Tests/Variables.text
new file mode 100644 (file)
index 0000000..b63ffaa
--- /dev/null
@@ -0,0 +1,14 @@
+title: *foo* "bar"
+foo:   bar
+foo bar
+       foo bar
+foo:   *bar*
+bat:   **foo**
+
+foo:   bar
+
+[%foo]
+
+[%bar]
+
+[%bat]