Created
July 20, 2015 11:00
-
-
Save Caerbannog/9714617f3879ddcc741d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Convert AsciiDoc from "Two line titles" to "One line titles" | |
# http://asciidoctor.org/docs/asciidoc-recommended-practices/#section-titles | |
set -e | |
find src -name '*.adoc' | | |
while read file | |
do | |
awk '{ | |
if ($0 ~ /^[=~^+-]{3,}$/ \ | |
&& length($0) - 2 <= length(buffer) \ | |
&& length(buffer) <= length($0) + 2 \ | |
&& buffer !~ /ID_LANGUAGE_PORTUGUESE/ \ | |
&& buffer !~ /\[NOTE\]/ \ | |
&& buffer !~ /radial leads/ \ | |
&& buffer !~ /netlist_form_pads/ ) { | |
# This matches underlines of the right size (+/-2) and skips | |
# callouts that should not change in GUI_Translation_HOWTO.adoc:170, | |
# GUI_Translation_HOWTO.adoc:430, IDF_Exporter.adoc:380, | |
# and Eeschema_creating_customized_netlists_and_bom_files.adoc:372 | |
if ($0 ~ /=/) | |
pre = "= " | |
else if ($0 ~ /-/) | |
pre = "== " | |
else if ($0 ~ /~/) | |
pre = "=== " | |
else if ($0 ~ /\^/) | |
pre = "==== " | |
else | |
pre = "===== " | |
buffer = pre buffer # Prepend to the title | |
} else { | |
if (NR > 1) # (this condition avoids creating an empty first line) | |
print buffer | |
buffer = $0 | |
} | |
} | |
END { | |
print buffer | |
} | |
' $file > tmp | |
mv tmp $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment