Fix example extraction

Assumtion was that the first and last lines of examples are always
blank. In 2021/06 the example is only one line. It has no blank line at
the end so the example was deleted by the script.

Changed:
The script will now check if the line is actually blank before deleting
it. Requires that the indentation is removed beforehand.
master
Alfred Melch 3 years ago
parent 639da7d7d8
commit f885b70c9e

@ -26,12 +26,12 @@ echo "Extracting example code blocks..."
# extract example code blocks
cat README.md |
sed -n '/\[code\]/,/\[\/code\]/p' | # extract code blocks
sed '/\[code\]/{n;d}' | # remove (blank) lines after opening bracket
sed 's/^ //' | # remove indentation
sed '/\[code\]/{n;/^$/d}' | # remove blank lines after opening bracket
tac | # reverse line order
sed '/\[\/code\]/{n;d}' | # remove (blank) lines after closing brackets (preceding blank lines in normal order)
sed '/\[\/code\]/{n;/^$/d}' | # remove blank lines after closing brackets (preceding blank lines in normal order)
tac | # reverse line order again
sed '/^\[\/code\]/d' | # remove closing brackets
sed 's/^ //' | # remove indentation
csplit - --suppress-matched --elide-empty-files --prefix='input/example' --suffix='%d' '/\[code\]/' '{*}'
echo "done."

Loading…
Cancel
Save