Some Markdown processors require a blank line before a bulleted list.
So the list
This is a bulleted list:
- line 1
- line 2
- line 3
Will be incorrectly rendered as
This is a bulleted list: - line 1 - line 2 - line 3
How can I use awk to check that lines starting with "- " are preceded by either a blank line or another line starting with "- "?
(I am using dash-space as the start token to avoid confusion with the document front matter, which uses three dashes as a separator.)
Please note: unlike the first question referenced in the comments, this is a search for an anti-pattern - something not occurring in the file.
Using pcregrep
this is straightforward:
pcregrep -Mc '^[A-Z][a-z].*\n- ' $filename
but it's not clear to me how to do it using awk
.
What I'm doing is:
awkcommand='
/- / {
if(lastLine != "") {
print FILENAME
exit
}
}
{ lastLine = $0 }
'
awk "$awkcommand" data
which catches a single bullet following a non blank line. But when I try to add more conditions (if prior line not blank AND prior line does not start with a bullet), it fails - so for example, this:
if(lastLine != "" && lastline !~/^- /) {
does not work: it gives a false positive on this file
This is a test
- abc
- def