]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add support for manual labels on Setext Headers
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 10 Feb 2017 03:47:59 +0000 (22:47 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 10 Feb 2017 03:47:59 +0000 (22:47 -0500)
src/html.c
src/mmd.c
src/parser.c
src/parser.y
tests/MMD6Tests/Advanced Headers.html
tests/MMD6Tests/Advanced Headers.htmlc
tests/MMD6Tests/Advanced Headers.text
tests/MMD6Tests/Setext Headers.html
tests/MMD6Tests/Setext Headers.htmlc
tests/MMD6Tests/Setext Headers.text

index 11769a6c7ccb739cfa1249abbe88b34e29d05244..d147153028c7c4cf330de39b9f20262398b05784 100644 (file)
@@ -548,7 +548,12 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t
                        if (scratch->extensions & EXT_NO_LABELS) {
                                printf("<h%1d>", temp_short + scratch->base_header_level - 1);
                        } else {
-                               temp_char = label_from_token(source, t);
+                               temp_token = manual_label_from_header(t, source);
+                               if (temp_token) {
+                                       temp_char = label_from_token(source, temp_token);
+                               } else {
+                                       temp_char = label_from_token(source, t);
+                               }
                                printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
                                free(temp_char);
                        }
@@ -562,7 +567,12 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t
                        if (scratch->extensions & EXT_NO_LABELS) {
                                printf("<h%1d>", temp_short + scratch->base_header_level - 1);
                        } else {
-                               temp_char = label_from_token(source, t);
+                               temp_token = manual_label_from_header(t, source);
+                               if (temp_token) {
+                                       temp_char = label_from_token(source, temp_token);
+                               } else {
+                                       temp_char = label_from_token(source, t);
+                               }
                                printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
                                free(temp_char);
                        }
index 08c1b9c3c0299c1843161738167cee71f794faa6..103baa388241a0af191f0e69cee4cb670c5c2e24 100644 (file)
--- a/src/mmd.c
+++ b/src/mmd.c
@@ -894,6 +894,8 @@ void mmd_pair_tokens_in_block(token * block, token_pair_engine * e, stack * s) {
                case BLOCK_H5:
                case BLOCK_H6:
                case BLOCK_PARA:
+               case BLOCK_SETEXT_1:
+               case BLOCK_SETEXT_2:
                case BLOCK_TERM:
                        token_pairs_match_pairs_inside_token(block, e, s, 0);
                        break;
@@ -966,6 +968,8 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, cons
                        case BLOCK_LIST_ITEM:
                        case BLOCK_LIST_ITEM_TIGHT:
                        case BLOCK_PARA:
+                       case BLOCK_SETEXT_1:
+                       case BLOCK_SETEXT_2:
                        case BLOCK_TABLE:
                        case BLOCK_TERM:
                                // Assign child tokens of blocks
index 716e03831d964d3297f6bd1d3997aaaa64e4ffa5..4ac2a28cdff12cd14c41952d1a1cd811e176b4f1 100644 (file)
@@ -1207,11 +1207,11 @@ static void yy_reduce(
   yymsp[0].minor.yy0 = yylhsminor.yy0;
         break;
       case 24: /* block ::= setext_1 */
-{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_SETEXT_1); }
+{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_SETEXT_1); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, yylhsminor.yy0); }
   yymsp[0].minor.yy0 = yylhsminor.yy0;
         break;
       case 25: /* block ::= setext_2 */
-{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_SETEXT_2); }
+{ yylhsminor.yy0 = token_new_parent(yymsp[0].minor.yy0, BLOCK_SETEXT_2); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, yylhsminor.yy0); }
   yymsp[0].minor.yy0 = yylhsminor.yy0;
         break;
       case 26: /* block ::= table */
index b9ed5ea3999555b2e32217ee78601434ccbc1f9b..cfbc249d3f39ea1aa7a845a88e98b940dabe2e2e 100644 (file)
@@ -123,8 +123,8 @@ block(A)                    ::= list_bullet(B).                     { A = token_new_parent(B, BLOCK_LIST_BULLETED);
 block(A)                       ::= list_enum(B).                       { A = token_new_parent(B, BLOCK_LIST_ENUMERATED); is_list_loose(A); }
 block(A)                       ::= meta_block(B).                      { A = token_new_parent(B, BLOCK_META); }
 block(A)                       ::= para(B).                            { A = token_new_parent(B, BLOCK_PARA); is_para_html(engine, A); }
-block(A)                       ::= setext_1(B).                        { A = token_new_parent(B, BLOCK_SETEXT_1); }
-block(A)                       ::= setext_2(B).                        { A = token_new_parent(B, BLOCK_SETEXT_2); }
+block(A)                       ::= setext_1(B).                        { A = token_new_parent(B, BLOCK_SETEXT_1); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, A); }
+block(A)                       ::= setext_2(B).                        { A = token_new_parent(B, BLOCK_SETEXT_2); if (!(engine->extensions & EXT_NO_LABELS)) stack_push(engine->header_stack, A); }
 block(A)                       ::= table(B).                           { A = token_new_parent(B, BLOCK_TABLE); }
 
 
index b3bb99ab17571b1a9db1ed3326f1ae1597c5ee88..c2735d9050bd80b3867d41035d4e521c90317e8a 100644 (file)
@@ -9,3 +9,5 @@
 <h1 id="baz">foo <a href="#bat">bar</a></h1>
 
 <p>5</p>
+
+<h1 id="bar">foo </h1>
index 0a8e69ee6958e258ffbc71d7c88c7993ac76f8b7..40cfe909423354a6f81d373fe205bda4aca426eb 100644 (file)
@@ -9,3 +9,5 @@
 <h1>foo [bar][bat][baz]</h1>
 
 <p>5</p>
+
+<h1>foo [bar]</h1>
index 949dab6938645890610c87c46ba0efe206f0d9dc..c6600bdf611f80ae88fec989ba25f0b23d304b9a 100644 (file)
@@ -9,3 +9,6 @@
 # foo [bar][bat][baz]
 
 5
+
+foo [bar]
+=========
index f01493c5d57476e144cfbadb417810bd6c958d18..f779f164499c7eec45e3d77791a0b28b776a95e3 100644 (file)
@@ -1,6 +1,6 @@
 <h1 id="foobar">foo bar</h1>
 
-<h2 id="foobar">foo bar</h2>
+<h2 id="foobar">foo <em>bar</em></h2>
 
 <h1 id="foobar">foo
 bar</h1>
index 561a4098e129dc81347ae263ab5731b2f0da8a6f..4f4446da46b772ecb3360a3b0a5b5d620f10b77d 100644 (file)
@@ -1,6 +1,6 @@
 <h1>foo bar</h1>
 
-<h2>foo bar</h2>
+<h2>foo <em>bar</em></h2>
 
 <h1>foo
 bar</h1>
index 747dd579f240c0d3901fc65ff728cb384051e86c..1a644b25751a1f0fb00f72748a62f6ec1de28807 100644 (file)
@@ -1,7 +1,7 @@
 foo bar
 =======
 
-foo bar
+foo *bar*
 -------
 
 foo