summaryrefslogtreecommitdiff
path: root/tools/rst2script.sed
blob: d34bab7aadd54bd9c325700592e0bf56b6d27e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sed -nrf

# Skip over the ".." line that starts a comment block.
/^\.{2}[[:space:]]*$/ n

# Loop through the block until a non-indented line is found.
# Append indented lines to the hold space.
: indent
/^ {4}/ {
    s/^ {4}//
    H
    $ b endblock
    n
    b indent
}

# Loop through to the end of the block.
# Clear the hold space if unindented lines are present.
:nonindent
/^[[:space:]]*$/! {
    x
    s/.*//
    x
    $ d
    n
    b nonindent
}

# Print the contents of the hold space (if any) and clear it.
: endblock
s/.*//
x
s/^\n//
/./ {
p
a \

}