]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Fix whitespace issues with headers with manual labels
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 1 Oct 2018 00:52:55 +0000 (20:52 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 1 Oct 2018 00:52:55 +0000 (20:52 -0400)
Sources/libMultiMarkdown/mmd.c
Sources/libMultiMarkdown/opendocument-content.c
tests/MMD6Tests/Advanced Headers.fodt
tests/MMD6Tests/Advanced Headers.html
tests/MMD6Tests/Advanced Headers.htmlc
tests/MMD6Tests/Advanced Headers.opml
tests/MMD6Tests/Advanced Headers.tex
tests/MMD6Tests/Advanced Headers.text
tests/MMD6Tests/Fenced Code Blocks.htmlc

index 567f1379e09a00d037f1307bb4b0312b1c40f281..6f5fb49d91362f0a55f2450588ad49e98360a508 100644 (file)
@@ -513,18 +513,32 @@ void mmd_assign_line_type(mmd_engine * e, token * line) {
                                line->type = (first_child->type - HASH1) + LINE_ATX_1;
                                first_child->type = (line->type - LINE_ATX_1) + MARKER_H1;
 
+                               t = line->child->tail;
+
                                // Strip trailing '#' sequence if present
-                               if (line->child->tail->type == TEXT_NL) {
-                                       if ((line->child->tail->prev->type >= HASH1) &&
-                                                       (line->child->tail->prev->type <= HASH6)) {
-                                               line->child->tail->prev->type -= HASH1;
-                                               line->child->tail->prev->type += MARKER_H1;
-                                       }
-                               } else {
-                                       if ((line->child->tail->type >= HASH1) &&
-                                                       (line->child->tail->type <= HASH6)) {
-                                               line->child->tail->type -= HASH1;
-                                               line->child->tail->type += MARKER_H1;
+                               while (t) {
+                                       switch (t->type) {
+                                               case INDENT_TAB:
+                                               case INDENT_SPACE:
+                                               case NON_INDENT_SPACE:
+                                               case TEXT_NL:
+                                               case TEXT_LINEBREAK:
+                                               case TEXT_LINEBREAK_SP:
+                                                       t = t->prev;
+                                                       break;
+                                               case HASH1:
+                                               case HASH2:
+                                               case HASH3:
+                                               case HASH4:
+                                               case HASH5:
+                                               case HASH6:
+                                                       t->type -= HASH1;
+                                                       t->type += MARKER_H1;
+                                                       t = NULL;
+                                                       break;
+                                               default:
+                                                       // Break out of loop
+                                                       t = NULL;
                                        }
                                }
                        } else {
index 0e5dfe542df8b83030d956e4c0dcd4872e3ad8e5..37bafd1f90f15d927e592f925db0e3800867e7e5 100644 (file)
@@ -297,6 +297,7 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token
        }
 
        char * temp;
+       char * stop;
 
        switch (t->type) {
                case AMPERSAND:
@@ -353,8 +354,9 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token
                case MARKER_H5:
                case MARKER_H6:
                        temp = (char *) &source[t->start];
+                       stop = (char *) &source[t->start + t->len];
 
-                       while (temp) {
+                       while (temp < stop) {
                                switch (*temp) {
                                        case '#':
                                                print_const("#");
@@ -372,7 +374,7 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token
                                                break;
 
                                        default:
-                                               temp = NULL;
+                                               temp = stop;
                                                break;
                                }
                        }
@@ -700,6 +702,7 @@ void mmd_export_token_opendocument(DString * out, const char * source, token * t
        bool    temp_bool       = 0;
        token * temp_token      = NULL;
        footnote * temp_note = NULL;
+       size_t  temp_size;
 
        switch (t->type) {
                case DOC_START_TOKEN:
@@ -889,7 +892,16 @@ void mmd_export_token_opendocument(DString * out, const char * source, token * t
                                free(temp_char);
                        }
 
-                       trim_trailing_whitespace_d_string(out);
+                       temp_size = 0;
+
+                       while (temp_size != out->currentStringLength) {
+                               temp_size = out->currentStringLength;
+
+                               trim_trailing_whitespace_d_string(out);
+                               if (strcmp(&(out->str[out->currentStringLength - 11]), "<text:tab/>") == 0) {
+                                       d_string_erase(out, out->currentStringLength - 11, 11);
+                               }
+                       }
 
                        print_const("</text:h>");
                        scratch->padded = 0;
index dcdc0b74546536d40f142ccb6a83ef918ec708bd..aa68b49e581ef0fdfa8ba8298dfd5e67729ba86f 100644 (file)
@@ -300,6 +300,14 @@ bar</text:span></text:h>
 <text:p text:style-name="Standard"><text:a xlink:type="simple" xlink:href="#bar">bar</text:a></text:p>
 
 <text:p text:style-name="Standard"><text:a xlink:type="simple" xlink:href="#bar">foo</text:a></text:p>
+
+<text:p text:style-name="Standard">10</text:p>
+
+<text:h text:outline-level="1"><text:bookmark text:name="bar"/>foo</text:h>
+
+<text:h text:outline-level="1"><text:bookmark text:name="bar"/>foo</text:h>
+
+<text:h text:outline-level="1"><text:bookmark text:name="bar"/>foo</text:h>
 </office:text>
 </office:body>
 </office:document>
index fec207babdfde69ac8eac0ea2cc830388e63bd59..479f95d25287f54cec1292e74cb57fd7bc09de5c 100644 (file)
@@ -29,6 +29,14 @@ bar</em></h1>
 
 <p><a href="#bar">foo</a></p>
 
+<p>10</p>
+
+<h1 id="bar">foo</h1>
+
+<h1 id="bar">foo</h1>
+
+<h1 id="bar">foo</h1>
+
 </body>
 </html>
 
index 6256779398b613f9161acdf6a8bbe14c3b55abaa..8a1955ffd315fe5c9116e84c0b5780904d41a414 100644 (file)
@@ -23,3 +23,11 @@ bar</em></h1>
 <p>[bar]</p>
 
 <p>[foo][bar]</p>
+
+<p>10</p>
+
+<h1>foo [bar]</h1>
+
+<h1>foo [bar]</h1>
+
+<h1>foo [bar]</h1>
index ac9a51e14a69fead26895d4238b75933f8c7a0be..8911484ecf05623af34c9542cb1a70271e58179c 100644 (file)
 <outline text="foo [bar][bat][baz]" _note="&#10;5&#10;&#10;"></outline>
 <outline text="foo [bar]" _note="&#10;"></outline>
 <outline text="*foo* bar" _note="&#10;"></outline>
-<outline text="*foo&#10;bar*" _note="&#10;[bar]&#10;&#10;[foo][bar]&#10;"></outline>
+<outline text="*foo&#10;bar*" _note="&#10;[bar]&#10;&#10;[foo][bar]&#10;&#10;10&#10;&#10;"></outline>
+<outline text="foo [bar]" _note="&#10;"></outline>
+<outline text="foo [bar]" _note="&#10;"></outline>
+<outline text="foo [bar]" _note=""></outline>
 <outline text="&gt;&gt;Metadata&lt;&lt;">
 <outline text="title" _note="Advanced Headers"/>
 <outline text="latexconfig" _note="article"/>
index 6672ccfd0f1638977bd486e32f939c223218eaf7..569164eea081adad24f03ff8f6e3ef13d22384d0 100644 (file)
@@ -33,5 +33,16 @@ bar (\autoref{bar})
 
 foo (\autoref{bar})
 
+10
+
+\part{foo}
+\label{bar}
+
+\part{foo}
+\label{bar}
+
+\part{foo}
+\label{bar}
+
 \input{mmd6-article-footer}
 \end{document}
index fe5ed90d53e58519f708702b370b7930160b79c6..588f248ea72df20d2949f0f545955656a2145086 100644 (file)
@@ -25,3 +25,11 @@ bar*
 [bar]
 
 [foo][bar]
+
+10
+
+# foo [bar] # 
+
+# foo [bar] #  
+
+# foo [bar] #    
\ No newline at end of file
index 4223f29de017548f73171646fd3721405bc19174..0b09e470b33c8673be8e1aa1d79d3f3134d3ba60 100644 (file)
@@ -73,9 +73,9 @@ foo</p>
 
 <h3>baz</h3>
 
-<h4>foo        ##</h4>
+<h4>foo</h4>
 
-<h5>bar                ##</h5>
+<h5>bar</h5>
 
 <h6>baz</h6>