Wednesday, November 25, 2015

Command line tool to create and parse text outlines - revisited


A while back I posted a quick script for creating text outlines on the command line (for example, in Vim).  I like keeping all my documentation as plain text.  I updated it so that it can now parse and repair outlines if you edit them.

Source code is here:

        https://github.com/sevkeifert/text-utils/blob/master/outline


Description of the `outline` utility:

This is a command line tool for creating text outlines from space-delimited
markup.  This program transforms a stream of data, either rendering markup or
decoding an already rendered outline back into markup.

                                                    Kevin Seifert - 2015 GPLv2
USAGE

    Pipe space-delimited (or space-delimited) text into this script to create a
    text outline.  For example:

        cat your_markup_file | $0

OPTIONS

    -d    decode outline
    -e    encode outline (default)
    -h    help
    -n    use numeric style: 1  1.1  1.2 ...
    -r    re-encode existing outline (repair)
    -w   set word wrap width
    -0    mix single/double space (add break after continued lines)
    -1    single space
    -2    double space

EXAMPLE USAGE

    cat yourfile | outline       # for roman numeral format
    cat yourfile | outline -n    # for decimal format
    cat yourfile | outline -d    # decode rendered outline back into markup
    cat yourfile | outline -r    # repair (re-encode) rendered outline

    Or in vim, visually select text and run selection markup through pipe

        :'<,'> ! outline
        :'<,'> ! outline -d
        :'<,'> ! outline -r

MARKUP EXAMPLE

    INPUT EXAMPLE (WHITESPACE DETERMINES LEVEL)

        some heading
            more text
                a sub point
                another sub point
            more text
                a sub point
                another sub point

    OUTPUT EXAMPLE (RENDERED INTO OUTLINE)

        I. some heading
            A. more text
                1. a sub point
                2. another sub point
            B. more text
                1. a sub point
                2. another sub point

    ALSO, YOU CAN USE DECIMAL FORMAT USING THE -n FLAG

        1. some heading
            1.1 more text
                1.1.1 a sub point
                1.1.2 another sub point
            1.2 more text
                1.2.1 a sub point
                1.2.2 another sub point

No comments: