diff --git a/markdown.awk b/markdown.awk
index 7e8708a..9db96c5 100644
--- a/markdown.awk
+++ b/markdown.awk
@@ -3,12 +3,23 @@ BEGIN {
in_code = 0
}
-function parse_header(str) {
- match(str, /#+/);
- hnum = RLENGTH;
+function parse_header(str, hnum, content) {
+ if (substr(str, 1, 1) == "#") {
+ match(str, /#+/);
+ hnum = RLENGTH;
- content = parse_line(substr(str, hnum + 1, length(str) - hnum ));
- return "" content "";
+ content = parse_line(substr(str, hnum + 1, length(str) - hnum ));
+ return "" content "";
+ }
+ if (match(body, /^[^\n]+\n=+$/)) {
+ gsub(/\n=+$/, "", str);
+ return "
" parse_line(str) "
"
+ }
+ if (match(body, /^[^\n]+\n-+$/)) {
+ gsub(/\n-+$/, "", str);
+ return "" parse_line(str) "
"
+ }
+ return "";
}
function read_line(str, pos, res, i) {
@@ -254,7 +265,7 @@ function parse_block(str) {
if (match(str, /^```\n.*```$/) || match(str, /^ /)) {
return parse_code(str);
}
- if (substr(str, 1, 1) == "#") {
+ if (substr(str, 1, 1) == "#" || match(body, /^[^\n]+\n[-=]+$/)) {
return parse_header(str);
}
else if (substr(str, 1, 1) == ">") {
@@ -278,6 +289,9 @@ function line_continues(body, line) {
if (match(body, /^#* /))
return 0;
+ if (match(body, /^[^\n]+\n[-=]+$/))
+ return 0;
+
if (line != "")
return 1;
diff --git a/test.sh b/test.sh
index b1b43a0..9abe49d 100755
--- a/test.sh
+++ b/test.sh
@@ -86,6 +86,17 @@ check <<-EOF
Header3
EOF
+check <<-EOF
+underlined header 1
+===================
+
+underlined header 2
+-------------------
+---
+underlined header 1
+underlined header 2
+EOF
+
check <<-EOF
**bold**
---