#!/usr/bin/sed
# Convert unlabelled code
#

# Code output by action=markdown (mostly) ends with two spaces.
# Beginning with non-whitespace and ending with (only) two-spaces.
/^\S.*\S  $/,/\[Get Code]/ {
    # Handle no terminating 'Get Code'
    $ {
        x
        p
        d
    }
    # At the end of the block dump the accumulated lines
    /\[Get Code]/ {
        # clear this line to clear the hold space when exchanging
        s/.*//
        x
        # indent and cleanup
        s/\n/\n    /g
        s/  \n/\n/g
        p
        d
    }

    # accumulate lines within the code block
    H
    d
}
