Automatically skip metadata headers

This commit is contained in:
Konstantin Nazarov 2021-08-22 17:21:47 +01:00
parent 1cc0b977f1
commit 8624cc6871
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 36 additions and 5 deletions

View file

@ -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 != "")
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 != "")
if (body != "") {
if (!(first_paragraph && is_metadata(body)))
print parse_block(body);
}
}

15
test.sh
View file

@ -471,5 +471,20 @@ _ _ _
<hr />
EOF
check <<-"EOF"
this: 1
is: 2
metadata: 3
---
EOF
check <<-"EOF"
this: 1
is: 2
not metadata: 3
---
<p>this: 1 is: 2 not metadata: 3</p>
EOF
echo
echo "All tests passed"