]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Metadata support for base header level
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 8 Feb 2017 17:06:57 +0000 (12:06 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 8 Feb 2017 17:06:57 +0000 (12:06 -0500)
README.md
src/html.c
src/libMultiMarkdown.h
src/writer.c
src/writer.h
templates/README.md.in
tests/MMD6Tests/Metadata.html
tests/MMD6Tests/Metadata.htmlc
tests/MMD6Tests/Metadata.text

index 2ce91caba8453378f87bc799b462043dfe5fe264..701f0e2a13135d3d054b51a3c04d4ae328455934 100644 (file)
--- a/README.md
+++ b/README.md
@@ -421,6 +421,7 @@ features have been implemented:
 * Basic Citation support
 * CriticMarkup support
 * Definition lists
+* Figures
 * Footnotes
 * Inline and reference footnotes
 * Image and Link attributes (attributes can now be used with inline links as
@@ -453,7 +454,6 @@ Things yet to be completed:
 * Abbreviations
 * Glossaries
 * File Transclusion
-* Figures
 * Table Captions
 
 
index 8acf7cf28cc5399cbfbbc5e8e7137c46cd961fd6..12cc378ed474f6909e7e02319aac725081a5549d 100644 (file)
@@ -399,14 +399,14 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t
                        pad(out, 2, scratch);
                        temp_short = t->type - BLOCK_H1 + 1;
                        if (scratch->extensions & EXT_NO_LABELS) {
-                               printf("<h%1d>", temp_short);
+                               printf("<h%1d>", temp_short + scratch->base_header_level - 1);
                        } else {
                                temp_char = label_from_token(source, t);
-                               printf("<h%1d id=\"%s\">", temp_short, temp_char);
+                               printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
                                free(temp_char);
                        }
                        mmd_export_token_tree_html(out, source, t->child, t->start + offset, scratch);
-                       printf("</h%1d>", temp_short);
+                       printf("</h%1d>", temp_short + scratch->base_header_level - 1);
                        scratch->padded = 0;
                        break;
                case BLOCK_HR:
index aace3a662c51fe17ab5596905b42e11a2b6342a8..0e70d30a3ed610a3a744261aebaccc251d7410b3 100644 (file)
@@ -282,7 +282,9 @@ enum smart_quotes_language {
 
 
 enum output_format {
-       FORMAT_HTML
+       FORMAT_HTML,
+       FORMAT_LATEX,
+       FORMAT_ODF,
 };
 
 
index 197b8bfda22714c172b3e1ee834f32aa726e5713..5a0ebe3ec6a9f6af5bce365a935b68dd586aa175 100644 (file)
@@ -78,7 +78,7 @@ void store_metadata(scratch_pad * scratch, meta * m);
 
 
 /// Temporary storage while exporting parse tree to output format
-scratch_pad * scratch_pad_new(mmd_engine * e) {
+scratch_pad * scratch_pad_new(mmd_engine * e, short format) {
        scratch_pad * p = malloc(sizeof(scratch_pad));
 
        if (p) {
@@ -88,6 +88,7 @@ scratch_pad * scratch_pad_new(mmd_engine * e) {
                p->close_para = true;
 
                p->extensions = e->extensions;
+               p->output_format = format;
                p->quotes_lang = e->quotes_lang;
                p->language = e->language;
 
@@ -95,6 +96,8 @@ scratch_pad * scratch_pad_new(mmd_engine * e) {
 
                p->recurse_depth = 0;
 
+               p->base_header_level = 1;
+
                // Store links in a hash for rapid retrieval when exporting
                p->link_hash = NULL;
                link * l;
@@ -1143,29 +1146,39 @@ void process_metadata_stack(mmd_engine * e, scratch_pad * scratch) {
                return;
 
        meta * m;
+       short header_level = -10;
 
        for (int i = 0; i < e->metadata_stack->size; ++i)
        {
                // Check for certain metadata keys
                m = stack_peek_index(e->metadata_stack, i);
 
-               // Certain keys do not force complete documents
-               if (!(scratch->extensions & EXT_COMPLETE) &&
-                       !(scratch->extensions & EXT_SNIPPET)) {
-                       if ((strcmp(m->key, "baseheaderlevel")  != 0) &&
-                               (strcmp(m->key, "xhtmlheaderlevel")     != 0) &&
-                               (strcmp(m->key, "htmlheaderlevel")      != 0) &&
-                               (strcmp(m->key, "latexheaderlevel")     != 0) &&
-                               (strcmp(m->key, "odfheaderlevel")       != 0) &&
-                               (strcmp(m->key, "xhtmlheader")          != 0) &&
-                               (strcmp(m->key, "htmlheader")           != 0) &&
-                               (strcmp(m->key, "quoteslanguage")       != 0)) {
-                               // We found a key that is not in the list, so
-                               // Force a complete document
+               if (strcmp(m->key, "baseheaderlevel") == 0) {
+                       if (header_level == -10)
+                               header_level = atoi(m->value);
+               } else if (strcmp(m->key, "htmlheaderlevel") == 0) {
+                       if (scratch->output_format == FORMAT_HTML)
+                               header_level = atoi(m->value);
+               } else if (strcmp(m->key, "xhtmlheaderlevel") == 0) {
+                       if (scratch->output_format == FORMAT_HTML)
+                               header_level = atoi(m->value);
+               } else if (strcmp(m->key, "latexheaderlevel") == 0) {
+                       if (scratch->output_format == FORMAT_LATEX)
+                               header_level = atoi(m->value);
+               } else if (strcmp(m->key, "odfheaderlevel") == 0) {
+                       if (scratch->output_format == FORMAT_ODF)
+                               header_level = atoi(m->value);
+               } else if (strcmp(m->key, "quoteslanguage") == 0) {
+               } else {
+                       // Any other key triggers complete document
+                       if (!(scratch->extensions & EXT_SNIPPET))
                                scratch->extensions |= EXT_COMPLETE;
-                       }
                }
+
        }
+
+       if (header_level != -10)
+               scratch->base_header_level = header_level;
 }
 
 
@@ -1178,7 +1191,7 @@ void mmd_export_token_tree(DString * out, mmd_engine * e, short format) {
        process_header_stack(e);
 
        // Create scratch pad
-       scratch_pad * scratch = scratch_pad_new(e);
+       scratch_pad * scratch = scratch_pad_new(e, format);
 
        // Process metadata
        process_metadata_stack(e, scratch);
index 2e62fa63f7bbb4ffdaf6687dbceee9cd4a226a7e..bc35c2c4e95dfe63ab810948debb0838d0ba211b 100644 (file)
@@ -76,6 +76,7 @@ typedef struct {
        struct meta *           meta_hash;
 
        unsigned long           extensions;
+       short                           output_format;
        short                           padded;                 //!< How many empty lines at end output buffer
        short                           list_is_tight;
        short                           close_para;
@@ -95,6 +96,8 @@ typedef struct {
        short                           language;
        short                           quotes_lang;
 
+       short                           base_header_level;
+
        stack *                         header_stack;
 
        short                           recurse_depth;
@@ -159,7 +162,7 @@ typedef struct meta meta;
 
 
 /// Temporary storage while exporting parse tree to output format
-scratch_pad * scratch_pad_new(mmd_engine * e);
+scratch_pad * scratch_pad_new(mmd_engine * e, short format);
 
 void scratch_pad_free(scratch_pad * scratch);
 
index d6e6a3f8391327f196fff6b0a196fc3263fcebcc..345cd8b3d4f303a38d04295db0197183a2ea9340 100644 (file)
@@ -421,6 +421,7 @@ features have been implemented:
 * Basic Citation support
 * CriticMarkup support
 * Definition lists
+* Figures
 * Footnotes
 * Inline and reference footnotes
 * Image and Link attributes (attributes can now be used with inline links as
@@ -453,7 +454,6 @@ Things yet to be completed:
 * Abbreviations
 * Glossaries
 * File Transclusion
-* Figures
 * Table Captions
 
 
index 1aa81c52e93afd53cedd5373b7e0c862fa7cacb3..8dc807f4b23ea9e722de89dbe836c5c9031580e3 100644 (file)
@@ -11,5 +11,7 @@
 
 <p>foo:        bar</p>
 
+<h2 id="foo">foo </h2>
+
 </body>
 </html>
index c4e621858839716f33f73b6c0394387e234febe2..10041dc24f1b13b106f2468c0c0006543f29696b 100644 (file)
@@ -6,6 +6,10 @@ HTML header:   <script type="text/javascript"
 foo:   bar
 foo bar
 foo bar
-foo:   <em>bar</em></p>
+foo:   <em>bar</em>
+html header level: 2
+base header level: 3</p>
 
 <p>foo:        bar</p>
+
+<h1>foo </h1>
index 44c4bc477d61604835f93d17d228c4a6d35d0f95..bc1786444f4cc9e23c9af05635f143e007b267c7 100644 (file)
@@ -7,5 +7,9 @@ foo:    bar
 foo bar
        foo bar
 foo:   *bar*
+html header level: 2
+base header level: 3
 
 foo:   bar
+
+# foo #