Skip to content

Instantly share code, notes, and snippets.

@jasongraham
Created January 9, 2011 23:43

Revisions

  1. Jason created this gist Jan 9, 2011.
    37 changes: 37 additions & 0 deletions textilize_cgit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/usr/bin/env python
    #
    # Uses python-textile to convert a textile document to the body
    # of an HTML document to display with cgit (http://hjemli.net/git/cgit/).
    #
    # Install:
    #
    # 1- Install python-textile ( sudo apt-get install python-textile )
    # 2- Copy this script to /usr/local/bin/textilize_cgit.py (with exec rights)
    # 3- Add this statement into the your cgit configuration:
    # # Implement globally
    # about-filter=/usr/local/bin/textilize_cgit.py
    #
    # OR
    #
    # # Implement On a per-repo basis (must use
    # # the enable-filter-overrides=1 option)
    # repo.about-filter=/usr/local/bin/textilize_cgit.py
    #

    import sys
    import textile

    def textilize(in_stream=None, out_stream=None):
    # If not provided in_stream will be read from stdin and out_stream
    # will be written to stdout.
    if in_stream is None:
    in_stream = sys.stdin
    if out_stream is None:
    out_stream = sys.stdout

    out_stream.write(textile.textile(in_stream.read()))

    if __name__ == '__main__':
    if len(sys.argv) != 1:
    sys.exit(1)
    textilize()