diff --git a/markdown.awk b/markdown.awk index 79c7399..a916d61 100644 --- a/markdown.awk +++ b/markdown.awk @@ -42,55 +42,86 @@ function startswith(str, s, sl, j) { } return 0; } -#function parse_list_item(str, -function fold_lines(arr, i, result) { - for (i in arr) { - if (result != "") - result = result " " arr[i]; - else - result = arr[i]; - } +function rstrip(str) { + gsub(/ *\n*$/, "", str); + return str; } -function parse_list(str, buf, result, i, ind, line, lines, indent) { - result = ""; + result = result ""; + + if (is_bullet) + result = ""; + else + result = "
    \n" result "\n
"; + return result; } @@ -187,21 +218,14 @@ function parse_body(str) { /```/ { if (startswith(body, "```") == 1) { - if (body != "") - body = body "\n"; - - print "" substr(body, 4, length(body)-3) ""; + print "
" substr(body, 4, length(body)-3) "
"; body = ""; next; } } // { - if (body != "") - body = body "\n" $0; - else - body = $0; - + body = join_lines(body, $0, "\n") next; } diff --git a/test.sh b/test.sh index 183e88e..f8f9e46 100755 --- a/test.sh +++ b/test.sh @@ -14,7 +14,7 @@ check() { elif [[ "$current" == "input" ]]; then echo "$line" >> "$input" else - echo $line >> "$expected_output" + echo "$line" >> "$expected_output" fi done @@ -112,11 +112,10 @@ first line of code second line of code ``` --- - +

 first line of code
 
-second line of code
-
+second line of code
EOF check <<-"EOF" @@ -154,5 +153,29 @@ asdf
  • bar qux
  • EOF + +check <<-"EOF" +* first +level 1 + * second + level 1 + * second level 2 + * third level +* first level + 2 +--- + +EOF + echo echo "All tests passed"