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"
+ else
+ result = "\n"
+
for (i in lines) {
line = lines[i];
- if (match(line, "[^ ]") > indent)
+ if (match(line, "[^ ]") > indent) {
buf = join_lines(buf, line, "\n");
- else {
- indent = match(line, "[^ ]");
-
- if (buf != "") {
- result = join_lines(result, parse_list(buf), "\n");
- buf = "";
- }
- if (i > 1)
- result = result "\n"
- result = result "- " strip_list(line)
+ continue
}
-
+
+ indent = match(line, "[^ ]");
+
+ if (buf != "") {
+ result = join_lines(result, parse_list(buf), "\n");
+ buf = "";
+ }
+ if (i > 1)
+ result = result "
\n"
+
+ if (is_bullet && match(line, / *[[:digit:]]+\. /)) {
+ is_bullet = 0;
+ result = result "
\n\n";
+ }
+ if (is_bullet == 0 && match(line, / *\* /)) {
+ is_bullet = 1;
+ result = result "
\n\n";
+ }
+
+ result = result "- " parse_block(strip_list(line))
}
if (buf != "") {
@@ -118,9 +133,9 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet)
result = result "
";
if (is_bullet)
- result = "";
+ 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
-- foo
-- bar qux
+- bullet 1
+- bullet 2
+
+EOF
+
+check <<-"EOF"
+asdf
+
+1. number 1
+2. number
+ 2
+---
+asdf
+
+- number 1
+- number 2
+
+EOF
+
+check <<-"EOF"
+* **basic formatting**
+* ```in list```
+---
+
+- basic formatting
+in list
EOF
@@ -177,5 +201,25 @@ level 1
EOF
+check <<-"EOF"
+* bullet1
+1. number1
+* bullet2
+2. number2
+---
+
+
+- number1
+
+
+
+- number2
+
+EOF
+
echo
echo "All tests passed"