diff --git a/markdown.awk b/markdown.awk index 32f1d40..398a415 100755 --- a/markdown.awk +++ b/markdown.awk @@ -2,7 +2,7 @@ BEGIN { body = "" - in_code = 0 + first_paragraph = 1 } function parse_header(str, hnum, content) { @@ -418,6 +418,17 @@ function parse_code(str, i, lines, result) { return ""; } +function is_metadata(str, i, lines, line) { + split(str, lines, "\n"); + for (i=1; i<=length(lines); i++) { + line = lines[i]; + + if (! match(line, /^[^ ]+: .+$/)) + return 0; + } + return 1; +} + function parse_block(str) { if (str == "") return ""; @@ -498,8 +509,11 @@ function line_continues(body, line) { next; } - if (body != "") - print parse_block(body); + if (body != "") { + if (!(first_paragraph && is_metadata(body))) + print parse_block(body); + first_paragraph = 0; + } body = $0; @@ -507,6 +521,8 @@ function line_continues(body, line) { } END { - if (body != "") - print parse_block(body); + if (body != "") { + if (!(first_paragraph && is_metadata(body))) + print parse_block(body); + } } diff --git a/test.sh b/test.sh index 9b527f7..751da04 100755 --- a/test.sh +++ b/test.sh @@ -471,5 +471,20 @@ _ _ _
EOF +check <<-"EOF" +this: 1 +is: 2 +metadata: 3 +--- +EOF + +check <<-"EOF" +this: 1 +is: 2 +not metadata: 3 +--- +

this: 1 is: 2 not metadata: 3

+EOF + echo echo "All tests passed"