diff --git a/markdown.awk b/markdown.awk index a916d61..476f16d 100644 --- a/markdown.awk +++ b/markdown.awk @@ -93,23 +93,38 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet) indent = match(str, /[^ ]/); is_bullet = match(str, /^ *\* /) + if (is_bullet) + result = "\n
    \n"; + } + if (is_bullet == 0 && match(line, / *\* /)) { + is_bullet = 1; + result = result "
\n"; else - result = "
    \n" result "\n
"; + result = result "\n"; return result; } @@ -129,9 +144,6 @@ function parse_block(str, result, end, i) { #print "block '" str "'" result = "" - if (substr(str, 1, 2) == "* ") { - return parse_list(str); - } for (i=1; i<=length(str); i++) { if (substr(str, i, 2) == "**") { @@ -176,8 +188,8 @@ function parse_block(str, result, end, i) { } function parse_paragraph(str) { - if (substr(str, 1, 2 ) == "* ") { - return parse_block(str); + if (match(str, /^\* /) || match(str, /^[[:digit:]]\. /)) { + return parse_list(str); } else { return "

" parse_block(str) "

"; diff --git a/test.sh b/test.sh index f8f9e46..d77e956 100755 --- a/test.sh +++ b/test.sh @@ -143,14 +143,38 @@ EOF check <<-"EOF" asdf -* foo -* bar - qux +* bullet 1 +* bullet + 2 ---

asdf

+EOF + +check <<-"EOF" +asdf + +1. number 1 +2. number + 2 +--- +

asdf

+
    +
  1. number 1
  2. +
  3. number 2
  4. +
+EOF + +check <<-"EOF" +* **basic formatting** +* ```in list``` +--- + EOF @@ -177,5 +201,25 @@ level 1 EOF +check <<-"EOF" +* bullet1 +1. number1 +* bullet2 +2. number2 +--- + +
    +
  1. number1
  2. +
+ +
    +
  1. number2
  2. +
+EOF + echo echo "All tests passed"