From 57932bdfd5b9e733773593583980bf5ab3b58fbd Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Thu, 9 Feb 2017 22:47:59 -0500 Subject: [PATCH] ADDED: Add support for manual labels on Setext Headers --- src/html.c | 14 ++++++++++++-- src/mmd.c | 4 ++++ src/parser.c | 4 ++-- src/parser.y | 4 ++-- tests/MMD6Tests/Advanced Headers.html | 2 ++ tests/MMD6Tests/Advanced Headers.htmlc | 2 ++ tests/MMD6Tests/Advanced Headers.text | 3 +++ tests/MMD6Tests/Setext Headers.html | 2 +- tests/MMD6Tests/Setext Headers.htmlc | 2 +- tests/MMD6Tests/Setext Headers.text | 2 +- 10 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/html.c b/src/html.c index 11769a6..d147153 100644 --- a/src/html.c +++ b/src/html.c @@ -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("", 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("", 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("", 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("", temp_short + scratch->base_header_level - 1, temp_char); free(temp_char); } diff --git a/src/mmd.c b/src/mmd.c index 08c1b9c..103baa3 100644 --- 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 diff --git a/src/parser.c b/src/parser.c index 716e038..4ac2a28 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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 */ diff --git a/src/parser.y b/src/parser.y index b9ed5ea..cfbc249 100644 --- a/src/parser.y +++ b/src/parser.y @@ -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); } diff --git a/tests/MMD6Tests/Advanced Headers.html b/tests/MMD6Tests/Advanced Headers.html index b3bb99a..c2735d9 100644 --- a/tests/MMD6Tests/Advanced Headers.html +++ b/tests/MMD6Tests/Advanced Headers.html @@ -9,3 +9,5 @@

foo bar

5

+ +

foo

diff --git a/tests/MMD6Tests/Advanced Headers.htmlc b/tests/MMD6Tests/Advanced Headers.htmlc index 0a8e69e..40cfe90 100644 --- a/tests/MMD6Tests/Advanced Headers.htmlc +++ b/tests/MMD6Tests/Advanced Headers.htmlc @@ -9,3 +9,5 @@

foo [bar][bat][baz]

5

+ +

foo [bar]

diff --git a/tests/MMD6Tests/Advanced Headers.text b/tests/MMD6Tests/Advanced Headers.text index 949dab6..c6600bd 100644 --- a/tests/MMD6Tests/Advanced Headers.text +++ b/tests/MMD6Tests/Advanced Headers.text @@ -9,3 +9,6 @@ # foo [bar][bat][baz] 5 + +foo [bar] +========= diff --git a/tests/MMD6Tests/Setext Headers.html b/tests/MMD6Tests/Setext Headers.html index f01493c..f779f16 100644 --- a/tests/MMD6Tests/Setext Headers.html +++ b/tests/MMD6Tests/Setext Headers.html @@ -1,6 +1,6 @@

foo bar

-

foo bar

+

foo bar

foo bar

diff --git a/tests/MMD6Tests/Setext Headers.htmlc b/tests/MMD6Tests/Setext Headers.htmlc index 561a409..4f4446d 100644 --- a/tests/MMD6Tests/Setext Headers.htmlc +++ b/tests/MMD6Tests/Setext Headers.htmlc @@ -1,6 +1,6 @@

foo bar

-

foo bar

+

foo bar

foo bar

diff --git a/tests/MMD6Tests/Setext Headers.text b/tests/MMD6Tests/Setext Headers.text index 747dd57..1a644b2 100644 --- a/tests/MMD6Tests/Setext Headers.text +++ b/tests/MMD6Tests/Setext Headers.text @@ -1,7 +1,7 @@ foo bar ======= -foo bar +foo *bar* ------- foo -- 2.40.0