Better support for bullet lists

This commit is contained in:
Konstantin Nazarov 2021-07-25 17:10:54 +00:00
parent a4c5c5435e
commit 8171fc9374
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 9 additions and 5 deletions

View file

@ -83,7 +83,7 @@ function join_lines(first, second, sep) {
} }
function strip_list(str) { function strip_list(str) {
gsub(/^ *\* /, "", str); gsub(/^ *[-+*] /, "", str);
gsub(/^ *[[:digit:]]*\. /, "", str); gsub(/^ *[[:digit:]]*\. /, "", str);
return str; return str;
} }
@ -98,7 +98,7 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet)
for (i in lines) { for (i in lines) {
line = lines[i]; line = lines[i];
if (match(line, / *\* /) || match(line, / *[[:digit:]]+\. /)) if (match(line, /^ *[-+*] /) || match(line, /^ *[[:digit:]]+\. /))
str = join_lines(str, line, "\n"); str = join_lines(str, line, "\n");
else else
str = join_lines(rstrip(str), lstrip(line), " "); str = join_lines(rstrip(str), lstrip(line), " ");
@ -107,7 +107,7 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet)
split(str, lines, "\n") split(str, lines, "\n")
indent = match(str, /[^ ]/); indent = match(str, /[^ ]/);
is_bullet = match(str, /^ *\* /) is_bullet = match(str, /^ *[-+*] /)
if (is_bullet) if (is_bullet)
result = "<ul>\n" result = "<ul>\n"
@ -135,7 +135,7 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet)
is_bullet = 0; is_bullet = 0;
result = result "</ul>\n<ol>\n"; result = result "</ul>\n<ol>\n";
} }
if (is_bullet == 0 && match(line, / *\* /)) { if (is_bullet == 0 && match(line, / *[-+*] /)) {
is_bullet = 1; is_bullet = 1;
result = result "</ol>\n<ul>\n"; result = result "</ol>\n<ul>\n";
} }
@ -315,7 +315,7 @@ function parse_block(str) {
else if (substr(str, 1, 1) == ">") { else if (substr(str, 1, 1) == ">") {
return parse_blockquote(str); return parse_blockquote(str);
} }
else if (match(str, /^\* /) || match(str, /^[[:digit:]]\. /)) { else if (match(str, /^[-+*] /) || match(str, /^[[:digit:]]\. /)) {
return parse_list(str); return parse_list(str);
} }
else { else {

View file

@ -153,11 +153,15 @@ asdf
* foo * foo
* bar * bar
- baz
+ qux
--- ---
<p>asdf</p> <p>asdf</p>
<ul> <ul>
<li>foo</li> <li>foo</li>
<li>bar</li> <li>bar</li>
<li>baz</li>
<li>qux</li>
</ul> </ul>
EOF EOF