From a1d883fc5b7acbf45fdc80a7806b4d4c21fdcd1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michael=20G=C3=B6hler?= Date: Sat, 27 Sep 2014 12:29:00 +0200 Subject: [PATCH] cleanup and small change of list spacing in #38 + shortened sample --- sample.md | 36 ++++++++++++++---------------------- src/parser.c | 9 ++++++--- src/viewer.c | 21 ++++++++++++--------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/sample.md b/sample.md index b8588db..57abf3d 100644 --- a/sample.md +++ b/sample.md @@ -135,31 +135,23 @@ becomes # Supported markdown formatting's -The leading stars or minuses make list. - -TODO list: -\* TODO major 1 -\ \- TODO minor 1.1 -\ \- Detail 1.1.1 -\ \- Detail 1.1.2 -\ \- TODO minor 1.2 -\* TODO major 2 -\* TODO major 3 -\ \* TODO minor 3.1 -\ \* TODO minor 3.2 +Leading *\** or *-* indicate lists. + +TODO list +\* major 1 +\ \- minor 1.1 +\ \- detail 1.1.1 +\ \- detail 1.1.2 +\ \- minor 1.2 becomes -TODO list: -* TODO major 1 - - TODO minor 1.1 - - Detail 1.1.1 - - Detail 1.1.2 - - TODO minor 1.2 -* TODO major 2 -* TODO major 3 - * TODO minor 3.1 - * TODO minor 3.2 +TODO list +* major 1 + - minor 1.1 + - detail 1.1.1 + - detail 1.1.2 + - minor 1.2 ------------------------------------------------- diff --git a/src/parser.c b/src/parser.c index a573106..c04facc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -302,11 +302,12 @@ int markdown_analyse(cstring_t *text) { // strip trailing spaces for(eol = text->size; eol > offset && isspace((unsigned char) text->text[eol - 1]); eol--); + // IS_UNORDERED_LIST_# if(text->size >= offset + 2 && (text->text[offset] == '*' || text->text[offset] == '-') && text->text[offset + 1] == ' ') { - for(i = offset; itext[i] != '*' && text->text[i] != '-' && text->text[i] != ' ') { @@ -328,7 +329,7 @@ int markdown_analyse(cstring_t *text) { if(unordered_list_level == 0) { unordered_list_level = 1; unordered_list_level_offset[1] = offset; - } + } switch(unordered_list_level) { case 1: SET_BIT(bits, IS_UNORDERED_LIST_1); break; @@ -339,6 +340,7 @@ int markdown_analyse(cstring_t *text) { break; } + } } if(!CHECK_BIT(bits, IS_UNORDERED_LIST_1) && @@ -347,9 +349,10 @@ int markdown_analyse(cstring_t *text) { unordered_list_level = 0; + // IS_CODE if(offset >= CODE_INDENT) { - // IS_CODE SET_BIT(bits, IS_CODE); + } else { for(i = offset; i < eol; i++) { diff --git a/src/viewer.c b/src/viewer.c index e3d2651..ee6fc90 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -372,38 +372,41 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo if(line->text->text) { int offset = 0; // text offset + // IS_UNORDERED_LIST_3 if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_3)) { offset = next_nonblank(line->text, 0); char format_s[15]; - strcpy(&format_s[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? "| " : " "); - strcpy(&format_s[4], CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)? "| " : " "); - strcpy(&format_s[8], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_3)? "+-- %s" : "`-- %s"); + strcpy(&format_s[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? " | " : " "); + strcpy(&format_s[4], CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)? " | " : " "); + strcpy(&format_s[8], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_3)? " +- %s" : " `- %s"); mvwprintw(window, y, x, format_s, &line->text->text[offset + 2]); + + // IS_UNORDERED_LIST_2 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) { offset = next_nonblank(line->text, 0); char format_s[11]; - strcpy(&format_s[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? "| " : " "); - strcpy(&format_s[4], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_2)? "+-- %s" : "`-- %s"); + strcpy(&format_s[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? " | " : " "); + strcpy(&format_s[4], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_2)? " +- %s" : " `- %s"); mvwprintw(window, y, x, format_s, &line->text->text[offset + 2]); + + // IS_UNORDERED_LIST_1 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) { offset = next_nonblank(line->text, 0); char format_s[7]; - strcpy(&format_s[0], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_1)? "+-- %s" : "`-- %s"); + strcpy(&format_s[0], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_1)? " +- %s" : " `- %s"); mvwprintw(window, y, x, format_s, &line->text->text[offset + 2]); - } else - // IS_CODE - if(CHECK_BIT(line->bits, IS_CODE)) { + } else if(CHECK_BIT(line->bits, IS_CODE)) { // set static offset for code offset = CODE_INDENT; -- 2.20.1