diff --git a/markdown.awk b/markdown.awk index b2b8024..260987b 100644 --- a/markdown.awk +++ b/markdown.awk @@ -65,6 +65,10 @@ function lstrip(str) { return str; } +function escape_special() { + +} + function join_lines(first, second, sep) { if (sep == "") sep = " "; @@ -152,13 +156,28 @@ function parse_list(str, buf, result, i, ind, line, lines, indent, is_bullet) return result; } +function is_token(str, i, tok) { + return substr(str, i, length(tok)) == tok; +} + +function escape_char(char) { + if (char == "<") + return "<"; + if (char == ">") + return ">"; + if (char == "&") + return "&"; + + return char; +} + function parse_line(str, result, end, i) { #print "block '" str "'" result = "" for (i=1; i<=length(str); i++) { - if (substr(str, i, 2) == "**") { + if (is_token(str, i, "**")){ end = find(str, "**", i+2); if (end != 0) { @@ -170,7 +189,7 @@ function parse_line(str, result, end, i) { i++; } } - else if (substr(str, i, 3) == "```") { + else if (is_token(str, i, "```")) { end = find(str, "```", i+3); if (end != 0) { result = result "" substr(str, i+3, end - i - 3) ""; @@ -191,7 +210,7 @@ function parse_line(str, result, end, i) { result = result " "; } else { - result = result substr(str, i, 1); + result = result escape_char(substr(str, i, 1)); } } } diff --git a/test.sh b/test.sh index 5dc323a..ff45b32 100755 --- a/test.sh +++ b/test.sh @@ -265,6 +265,20 @@ check <<-"EOF" EOF +check <<-"EOF" +> foo +> +>> bar +>> baz +--- +
+

foo

+
+

bar baz

+
+
+EOF + check <<-"EOF" > code blocks > in blockquotes @@ -275,5 +289,17 @@ in blockquotes EOF +check <<-"EOF" +foo&bar + +1 < 2 + +2 > 1 +--- +

foo&bar

+

1 < 2

+

2 > 1

+EOF + echo echo "All tests passed"