pax_global_header00006660000000000000000000000064127211020000014473gustar00rootroot0000000000000052 comment=574f8f8923be1ae9339a2e189ef9fd08835a04dc python-rst2ansi-0.1.5/000077500000000000000000000000001272110200000145625ustar00rootroot00000000000000python-rst2ansi-0.1.5/.travis.yml000066400000000000000000000022001272110200000166650ustar00rootroot00000000000000language: python sudo: false python: - 2.7 - 3.3 - 3.4 - nightly matrix: include: - python: 3.5 env: DEPLOY: true allow_failures: - python: nightly install: pip install docutils cram script: - make build - make test deploy: provider: pypi skip_cleanup: true user: Snaipe password: secure: CjyhyupM4hDysV9FAjB/CmbimFgoMiyN2JvV4sje3mB+iyFAIUp5imDQlW60mbgplrnROXiFyaUpk1OhKCW/Eu6KKnjhQevz/iY/d+Bfk1TnjvsWTNEKU54QAsWxN9AjL92y+e35hN0emFSDd1ZhzWYj+uTJ39zxBsjFmdJS+2xXkhlAdeAblGQkQ9cFRXr2JFTSYDLKTTqSviCzo1iLddl8uPb8fFlESjAyl8AnxrK2d50RC9GW7yz5umox/McjYPhX+VFQ0ITfG/b+wtJveOOoFIUvPKUMxv55sEWUiuMv1ZZ1PPaeXUGkDyvZ0zSoruo8m9ZZlTqUwJdEFuzxlfopod2h86J9fTYD4NKIhgNssO9sqRcgR2sgvNOWQ9wGmZggt3exluHeyL1iBJLU1z0CHDQQXmI3Au41Ziug+O0GokfSTnmCYkMHEkgZtaHj/UINKE9SyNPqEsa+N6KaclImw7+ZI6KUsl38LB2EOU6xouCMe6wBfwnVOmAzvzNH7BAtvu7VcSzyX9ikG4JQIZz73zOnm7Y28ENnsGM18ItRI33lf+D9wNCeff9whH9NTPA7RBrJ4DDP7PC5Mz3em1AlJdkEe360JI6plXZrVffSrpETN2fRAQp0x5fTUO333x1vbWNOW4/bryZ3EEG0VmOFYKcMxv6hL+78esCJuuI= on: repo: Snaipe/python-rst2ansi tags: true distributions: sdist bdist_wheel condition: $DEPLOY = true python-rst2ansi-0.1.5/LICENSE000066400000000000000000000021321272110200000155650ustar00rootroot00000000000000The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. python-rst2ansi-0.1.5/Makefile000066400000000000000000000003611272110200000162220ustar00rootroot00000000000000PY := python3 export PATH := $(shell pwd)/bin:$(PATH) export PYTHONPATH=$(shell pwd) BUILD = $(PY) setup.py build: $(BUILD) build install: $(BUILD) install test: cram test -v clean: $(BUILD) clean .PHONY: build install test clean python-rst2ansi-0.1.5/README.rst000066400000000000000000000025311272110200000162520ustar00rootroot00000000000000rst2ansi ======== |build| |downloads| |pyversions| |format| A python module dedicated to rendering RST (reStructuredText) documents to ansi-escaped strings suitable for display in a terminal. |asciicast| Installation ------------ Requirements ~~~~~~~~~~~~ Python 3.3+ PyPi package ~~~~~~~~~~~~ .. code:: bash pip install rst2ansi Usage ----- As a CLI utility: ~~~~~~~~~~~~~~~~~ .. code:: bash usage: rst2ansi [-h] [file] Prints a reStructuredText input in an ansi-decorated format suitable for console output. positional arguments: file A path to the file to open optional arguments: -h, --help show this help message and exit As a python module: ~~~~~~~~~~~~~~~~~~~ .. code:: python from rst2ansi import rst2ansi print(rst2ansi('I **love** reStructuredText!')) .. |build| image:: https://api.travis-ci.org/Snaipe/python-rst2ansi.svg :target: https://travis-ci.org/Snaipe/python-rst2ansi .. |downloads| image:: https://img.shields.io/pypi/dm/rst2ansi.svg :target: https://pypi.python.org/pypi/rst2ansi/ .. |pyversions| image:: https://img.shields.io/pypi/pyversions/rst2ansi.svg .. |format| image:: https://img.shields.io/pypi/format/rst2ansi.svg .. |asciicast| image:: https://asciinema.org/a/drykz69gtn557z3hxnbb1jybq.png :target: https://asciinema.org/a/drykz69gtn557z3hxnbb1jybq python-rst2ansi-0.1.5/TODO.md000066400000000000000000000042161272110200000156540ustar00rootroot00000000000000This document describes the TODO list for supporing the full [reStructuredText specification][rstspec]. * [x] Document Structure * [x] Document * [x] Sections * [x] Transitions * [x] Body Elements * [x] Paragraphs * [x] Bullet Lists * [x] Enumerated Lists * [x] Definition Lists * [ ] Field Lists * [x] Option Lists * [x] Literal Blocks * [x] Line Blocks * [ ] Block Quotes * [x] Block Quote * [ ] Attribution * [ ] Doctest Blocks * [x] Tables * [ ] Explicit Markup Blocks * [ ] Footnotes * [ ] Citations * [x] Hyperlink Targets * [ ] Directives * [ ] Admonitions * [x] Images * [x] Image * [x] Figure * [ ] Body Elements * [ ] Topic * [ ] Sidebar * [x] Line Block * [x] Parsed Literal Block * [ ] Code * [ ] Math * [ ] Rubric * [ ] Epigraph * [ ] Highlights * [ ] Pull-Quote * [ ] Compound Paragraph * [ ] Container * [ ] Tables * [ ] Table * [ ] CSV Table * [ ] List Table * [ ] Document Parts * [ ] Table of Contents * [ ] Automatic Section Numbering * [ ] Document Header & Footer * [ ] References * [ ] Target Footnotes * [ ] Footnotes * [ ] Citations * [ ] Directives for Substitution Definitions * [ ] Replacement Text * [ ] Unicode Character Codes * [ ] Date * [ ] Miscellaneous * [x] Including an External Document Fragment * [x] Raw Data Pass-Through * [x] Class * [x] Custom Interpreted Text Roles * [x] Setting the Default Interpreted Text Role * [ ] Metadata Document Title * [x] Substitution Definitions * [x] Comments * [ ] Implicit Hyperlink Targets * [ ] Inline Markup * [x] Emphasis * [x] Strong Emphasis * [x] Interpreted Text * [x] Inline Literals * [x] Hyperlink References * [x] Inline Internal Targets * [ ] Footnote References * [ ] Citation References * [x] Standalone Hyperlinks * [ ] Error messages [rstspec]: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html python-rst2ansi-0.1.5/bin/000077500000000000000000000000001272110200000153325ustar00rootroot00000000000000python-rst2ansi-0.1.5/bin/rst2ansi000077500000000000000000000011761272110200000170320ustar00rootroot00000000000000#!/usr/bin/env python import sys from rst2ansi import rst2ansi import argparse import io parser = argparse.ArgumentParser(description='Prints a reStructuredText input in an ansi-decorated format suitable for console output.') parser.add_argument('file', type=str, nargs='?', help='A path to the file to open') args = parser.parse_args() def process_file(f): out = rst2ansi(f.read()) if out: try: print(out) except UnicodeEncodeError: print(out.encode('ascii', errors='backslashreplace').decode('ascii')) if args.file: with io.open(args.file, 'rb') as f: process_file(f) else: process_file(sys.stdin) python-rst2ansi-0.1.5/demo/000077500000000000000000000000001272110200000155065ustar00rootroot00000000000000python-rst2ansi-0.1.5/demo/README.md000066400000000000000000000001351272110200000167640ustar00rootroot00000000000000## rst2ansi demo files These are the scripts and inputs used to record the demo screencast. python-rst2ansi-0.1.5/demo/autoreload.sh000077500000000000000000000002141272110200000202010ustar00rootroot00000000000000clear export PYTHONPATH=. while true; do inotifywait -e modify out.rst 2>/dev/null >/dev/null clear ./bin/rst2ansi out.rst done python-rst2ansi-0.1.5/demo/demo.sh000077500000000000000000000003411272110200000167670ustar00rootroot00000000000000#!/bin/sh echo "" > out.rst tmux new-session -s demo -n rst2ansi -d 'nvim out.rst -c ":set nobackup" -c ":set noswapfile"' tmux splitw -t demo -h 'zsh ./demo/autoreload.sh' tmux lastp -t demo tmux -2 attach-session -t demo python-rst2ansi-0.1.5/demo/demo.tsq000066400000000000000000000342611272110200000171710ustar00rootroot00000000000000. ESC @ 0.200000 |ggdGi| @ 0.100000 |H| @ 0.100000 |e| @ 0.100000 |l| @ 0.100000 |l| @ 0.100000 |o| @ 0.100000 |,| @ 0.100000 | | @ 0.100000 |w| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |l| @ 0.100000 |d| @ 0.100000 |!| @ 0.000815 . LF/^J @ 0.000815 . ESC @ 0.000815 |:w| @ 0.000815 . LF/^J @ 1.000000 |13i=| @ 0.000815 . ESC @ 0.200000 |o| @ 0.100000 |N| @ 0.100000 |i| @ 0.100000 |c| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |d| @ 0.100000 |a| @ 0.100000 |y| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 |d| @ 0.100000 |a| @ 0.100000 |y| @ 0.100000 |.| @ 0.000815 . LF/^J @ 0.000100 . ESC @ 0.200000 |15i~| @ 0.000815 . ESC @ 0.200000 |:w| @ 0.000815 . LF/^J @ 0.200000 |o| @ 0.100815 . LF/^J @ 0.100000 |I| @ 0.100000 | | @ 0.100000 |*| @ 0.100000 |l| @ 0.100000 |o| @ 0.100000 |v| @ 0.100000 |e| @ 0.100000 |*| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |S| @ 0.100000 |t| @ 0.100000 |r| @ 0.100000 |u| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |u| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 |T| @ 0.100000 |e| @ 0.100000 |x| @ 0.100000 |t| @ 0.100000 |!| @ 0.000815 . LF/^J @ 0.000100 . ESC @ 0.200000 |:w| @ 0.000815 . LF/^J @ 0.200000 |o| @ 0.100000 |B| @ 0.100000 |u| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |I| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |s| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |l| @ 0.100000 |o| @ 0.100000 |v| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |m| @ 0.100000 |y| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 |m| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |.| @ 0.000815 . LF/^J @ 0.000100 . ESC @ 0.200000 |:w| @ 0.000815 . LF/^J @ 0.200000 |o| @ 0.100000 |S| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |I| @ 0.100000 | | @ 0.100000 |m| @ 0.100000 |a| @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |*| @ 0.100000 |*| @ 0.100000 |r| @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |2| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |s| @ 0.100000 |i| @ 0.100000 |*| @ 0.100000 |*| @ 0.100000 |,| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |n| @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |S| @ 0.100000 |t| @ 0.100000 |r| @ 0.100000 |u| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |u| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 |T| @ 0.100000 |e| @ 0.100000 |x| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |o| @ 0.100000 |m| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |A| @ 0.100000 |N| @ 0.100000 |S| @ 0.100000 |I| @ 0.100000 |-| @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 |c| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |o| @ 0.100000 |u| @ 0.100000 |t| @ 0.100000 |p| @ 0.100000 |u| @ 0.100000 |t| @ 0.100000 |,| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 |a| @ 0.100000 |b| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |f| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 |m| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |s| @ 0.100000 |.| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J @ 0.100000 |o| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 . LF/^J @ 0.100000 . LF/^J @ 0.100000 |P| @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |g| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |p| @ 0.100000 |h| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |u| @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 |m| @ 0.100000 |a| @ 0.100000 |t| @ 0.100000 |i| @ 0.100000 |c| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |l| @ 0.100000 |y| @ 0.100000 | | @ 0.100000 |w| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |p| @ 0.100000 |p| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |f| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |c| @ 0.100000 |u| @ 0.100000 |r| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 |m| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 | | @ 0.100000 |w| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |d| @ 0.100000 |o| @ 0.100000 |w| @ 0.100000 |.| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J @ 1.500000 |d| @ 0.100000 |9| @ 0.100000 |k| @ 0.100000 . ESC @ 0.200000 |o| @ 0.100000 |P| @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |g| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |p| @ 0.100000 |h| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |f| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |i| @ 0.100000 |o| @ 0.100000 |n| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |e| @ 0.100000 |y| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |.| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J @ 0.100000 |o| @ 0.100000 |T| @ 0.100000 |h| @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |b| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |i| @ 0.100000 |o| @ 0.100000 |n| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |2| @ 0.100000 |0| @ 0.100000 |i| @ 0.100000 |-| @ 0.100000 . ESC @ 0.200000 |o| @ 0.100000 . LF/^J @ 0.100000 |A| @ 0.100000 |n| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |b| @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |b| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |i| @ 0.100000 |o| @ 0.100000 |n| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.400000 |2| @ 0.100000 |0| @ 0.100000 |i| @ 0.100000 |'| @ 0.100000 . ESC @ 0.400000 |o| @ 0.100000 . LF/^J @ 0.100000 |T| @ 0.100000 |h| @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |v| @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |l| @ 0.100000 |y| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |r| @ 0.100000 |u| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |u| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |d| @ 0.100000 |o| @ 0.100000 |c| @ 0.100000 |u| @ 0.100000 |m| @ 0.100000 |e| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |f| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |b| @ 0.100000 |e| @ 0.100000 |t| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |a| @ 0.100000 |d| @ 0.100000 |a| @ 0.100000 |b| @ 0.100000 |i| @ 0.100000 |l| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 |y| @ 0.100000 |.| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J @ 1.500000 |d| @ 0.100000 |9| @ 0.100000 |k| @ 0.100000 . ESC @ 0.200000 |o| @ 0.100000 |T| @ 0.100000 |a| @ 0.100000 |b| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |p| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |t| @ 0.100000 |t| @ 0.100000 |y| @ 0.100000 |-| @ 0.100000 |p| @ 0.100000 |r| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |w| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 | | @ 0.100000 |b| @ 0.100000 |o| @ 0.100000 |x| @ 0.100000 |-| @ 0.100000 |d| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |w| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |g| @ 0.100000 | | @ 0.100000 |c| @ 0.100000 |h| @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |a| @ 0.100000 |c| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |f| @ 0.100000 | | @ 0.100000 |y| @ 0.100000 |o| @ 0.100000 |u| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 |m| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 | | @ 0.100000 |s| @ 0.100000 |u| @ 0.100000 |p| @ 0.100000 |p| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |t| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |u| @ 0.100000 |n| @ 0.100000 |i| @ 0.100000 |c| @ 0.100000 |o| @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 |,| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |f| @ 0.100000 |a| @ 0.100000 |l| @ 0.100000 |l| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |b| @ 0.100000 |a| @ 0.100000 |c| @ 0.100000 |k| @ 0.100000 | | @ 0.100000 |t| @ 0.100000 |o| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 |c| @ 0.100000 |i| @ 0.100000 |i| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |f| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |d| @ 0.100000 |o| @ 0.100000 |e| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |n| @ 0.100000 |o| @ 0.100000 |t| @ 0.100000 |.| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |p| @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 . LF/^J @ 0.100000 |o===== ===== ======| . LF/^J | Inputs Output| . LF/^J |------------ ------| . LF/^J | A B A or B| . LF/^J |===== ===== ======| . LF/^J |False False False| . LF/^J |True False True| . LF/^J |False True True| . LF/^J |True True True| . LF/^J |===== ===== ======| . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |n| @ 0.100000 |o| @ 0.100000 |p| @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |e| @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J @ 1.500000 |d| @ 0.100000 |1| @ 0.100000 |2| @ 0.100000 |k| @ 0.100000 . ESC @ 0.200000 |o| @ 0.100000 |R| @ 0.100000 |S| @ 0.100000 |T| @ 0.100000 | | @ 0.100000 |c| @ 0.100000 |l| @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |v| @ 0.100000 |a| @ 0.100000 |i| @ 0.100000 |l| @ 0.100000 |a| @ 0.100000 |b| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |f| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |u| @ 0.100000 |s| @ 0.100000 |e| @ 0.100000 |r| @ 0.100000 | | @ 0.100000 |d| @ 0.100000 |e| @ 0.100000 |f| @ 0.100000 |i| @ 0.100000 |n| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |o| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 |s| @ 0.100000 |:| @ 0.100000 . LF/^J @ 0.100000 . LF/^J @ 0.100000 |.| @ 0.100000 |.| @ 0.100000 | | @ 0.100000 |r| @ 0.100000 |o| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 |:| @ 0.100000 |:| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |m| @ 0.100000 |p| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |t| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 . LF/^J @ 0.100000 | | @ 0.100000 | | @ 0.100000 | | @ 0.100000 | | @ 0.100000 |:| @ 0.100000 |c| @ 0.100000 |l| @ 0.100000 |a| @ 0.100000 |s| @ 0.100000 |s| @ 0.100000 |:| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |s| @ 0.100000 |i| @ 0.100000 |-| @ 0.100000 |f| @ 0.100000 |g| @ 0.100000 |-| @ 0.100000 |r| @ 0.100000 |e| @ 0.100000 |d| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |s| @ 0.100000 |i| @ 0.100000 |-| @ 0.100000 |b| @ 0.100000 |o| @ 0.100000 |l| @ 0.100000 |d| @ 0.100000 . LF/^J @ 0.100000 . LF/^J @ 0.100000 |:| @ 0.100000 |i| @ 0.100000 |m| @ 0.100000 |p| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |t| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 |:| @ 0.100000 |`| @ 0.100000 |T| @ 0.100000 |h| @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |m| @ 0.100000 |p| @ 0.100000 |o| @ 0.100000 |r| @ 0.100000 |t| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |t| @ 0.100000 |!| @ 0.100000 |`| @ 0.100000 . LF/^J @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J # Last frame @ 1.000000 |d| @ 0.100000 |6| @ 0.100000 |k| @ 0.100000 . ESC @ 0.200000 |o| @ 0.100000 |r| @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |2| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |s| @ 0.100000 |i| @ 0.100000 | | @ 0.100000 |i| @ 0.100000 |s| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |v| @ 0.100000 |a| @ 0.100000 |i| @ 0.100000 |l| @ 0.100000 |a| @ 0.100000 |b| @ 0.100000 |l| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |o| @ 0.100000 |n| @ 0.100000 | | @ 0.100000 |g| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |u| @ 0.100000 |b| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 |t| @ 0.100000 | | @ 0.100000 |h| @ 0.100000 |t| @ 0.100000 |t| @ 0.100000 |p| @ 0.100000 |s| @ 0.100000 |:| @ 0.100000 |/| @ 0.100000 |/| @ 0.100000 |g| @ 0.100000 |i| @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |u| @ 0.100000 |b| @ 0.100000 |.| @ 0.100000 |c| @ 0.100000 |o| @ 0.100000 |m| @ 0.100000 |/| @ 0.100000 |S| @ 0.100000 |n| @ 0.100000 |a| @ 0.100000 |i| @ 0.100000 |p| @ 0.100000 |e| @ 0.100000 |/| @ 0.100000 |p| @ 0.100000 |y| @ 0.100000 |t| @ 0.100000 |h| @ 0.100000 |o| @ 0.100000 |n| @ 0.100000 |-| @ 0.100000 |r| @ 0.100000 |s| @ 0.100000 |t| @ 0.100000 |2| @ 0.100000 |a| @ 0.100000 |n| @ 0.100000 |s| @ 0.100000 |i| @ 0.100000 . LF/^J @ 0.100000 . LF/^J @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 |-| @ 0.100000 . LF/^J @ 0.100000 . LF/^J @ 0.100000 |H| @ 0.100000 |a| @ 0.100000 |v| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |a| @ 0.100000 | | @ 0.100000 |n| @ 0.100000 |i| @ 0.100000 |c| @ 0.100000 |e| @ 0.100000 | | @ 0.100000 |d| @ 0.100000 |a| @ 0.100000 |y| @ 0.100000 |!| @ 0.100000 . ESC @ 0.200000 |:| @ 0.100000 |w| @ 0.100000 . LF/^J python-rst2ansi-0.1.5/demo/send-inputs.sh000077500000000000000000000001561272110200000203200ustar00rootroot00000000000000#!/bin/sh pts=$1; shift reseq demo/demo.tsq --replay | sudo ttysend -i $pts wait 3 tmux kill-session -t demo python-rst2ansi-0.1.5/rst2ansi/000077500000000000000000000000001272110200000163275ustar00rootroot00000000000000python-rst2ansi-0.1.5/rst2ansi/__init__.py000066400000000000000000000037151272110200000204460ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import unicode_literals from docutils import nodes, core from docutils.parsers.rst import roles from .visitor import Writer from .ansi import COLORS, STYLES def rst2ansi(input_string, output_encoding='utf-8'): overrides = {} overrides['input_encoding'] = 'unicode' def style_role(name, rawtext, text, lineno, inliner, options={}, content=[]): return [nodes.TextElement(rawtext, text, classes=[name])], [] for color in COLORS: roles.register_local_role('ansi-fg-' + color, style_role) roles.register_local_role('ansi-bg-' + color, style_role) for style in STYLES: roles.register_local_role('ansi-' + style, style_role) out = core.publish_string(input_string.decode('utf-8'), settings_overrides=overrides, writer=Writer(unicode=output_encoding.startswith('utf'))) return out.decode(output_encoding) python-rst2ansi-0.1.5/rst2ansi/ansi.py000066400000000000000000000315411272110200000176370ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import unicode_literals from docutils import core, frontend, nodes, utils, writers, languages, io from docutils.utils.error_reporting import SafeString from docutils.transforms import writer_aux from docutils.parsers.rst import roles from copy import deepcopy, copy from .wrap import wrap from .table import TableSizeCalculator, TableWriter from .unicode import ref_to_unicode, u from .get_terminal_size import get_terminal_size import shutil COLORS = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') STYLES = ('bold', 'dim', 'italic', 'underline', 'blink', 'blink-fast', 'inverse', 'conceal', 'strikethrough') class ANSICodes(object): @staticmethod def get_color_code(code, fg): FG = 30 BG = 40 FG_256 = 38 BG_256 = 48 if code in COLORS: shift = FG if fg else BG return str(shift + COLORS.index(code)) elif isinstance(code, int) and 0 <= code <= 255: shift = FG_256 if fg else BG_256 return str(shift) + ';5;%d' % int(code) elif not isinstance(code, str) and hasattr(code, "__len__") and len(code) == 3: for c in code: if not 0 <= c <= 255: raise Exception('Invalid color "%s"' % code) r, g, b = code shift = FG_256 if fg else BG_256 return str(shift) + ';2;%d;%d;%d' % (int(r), int(g), int(b)) raise Exception('Invalid color "%s"' % code) @staticmethod def get_style_code(code): if code in STYLES: return str(1 + STYLES.index(code)) raise Exception('Invalid style "%s"' % code) @staticmethod def to_ansi(codes): return '\x1b[' + ';'.join(codes) + 'm' NONE = '0' RESET = to_ansi.__func__(NONE) from .functional import npartial class ANSITranslator(nodes.NodeVisitor): class Context(object): def __init__(self): self.output = '' self.indent_level = 0 self.in_list = False self.has_title = False self.list_counter = 0 self.node_type = '' class StyleContext(object): def __init__(self): self.styles = set() self.fg = ANSICodes.NONE self.bg = ANSICodes.NONE def __init__(self, document, termsize=None, **options): nodes.NodeVisitor.__init__(self, document) self.document = document self.output = '' self.lines = [''] self.line = 0 self.indent_width = 2 self.termsize = termsize or get_terminal_size((80,20)) self.options = options self.references = [] self.refcount = 0 self.ctx = self.Context() self.ctx_stack = [] self.style = self.StyleContext() self.style_stack = [] def push_ctx(self, **kwargs): self.ctx_stack.append(self.ctx) self.ctx = deepcopy(self.ctx) for k, v in kwargs.items(): setattr(self.ctx, k, v) def pop_ctx(self): self.ctx = self.ctx_stack.pop() def push_style(self, fg=None, bg=None, styles=[]): self.style_stack.append(self.style) self.style = deepcopy(self.style) if fg: self.style.fg = ANSICodes.get_color_code(fg, True) if bg: self.style.bg = ANSICodes.get_color_code(bg, False) self.style.styles |= {ANSICodes.get_style_code(s) for s in styles} self._restyle() def pop_style(self): self.style = self.style_stack.pop() reset = self.style.fg == ANSICodes.NONE and \ self.style.bg == ANSICodes.NONE and \ not self.style.styles self._restyle(reset) def append(self, *args, **kwargs): try: strict = kwargs['strict'] except KeyError: strict = False if len(self.lines[self.line]) == 0 and not strict: self.lines[self.line] += ' ' * self.ctx.indent_level * self.indent_width for a in args: self.lines[self.line] += u(a) def newline(self, n=1): self.lines.extend([''] * n) self.line += n def prevline(self, n=1): self.line -= n def nextline(self, n=1): self.line += n def popline(self): l = self.lines.pop(self.line) self.line -= 1 return l def replaceline(self, newline, strict=True): if strict: self.lines[self.line] = newline else: self.lines[self.line] = '' self.append(newline) def addlines(self, lines, strict=False): if strict: self.lines.extend(lines) self.line += len(lines) self.newline() else: for l in lines: self.append(l) self.newline() def _restyle(self, reset=False): if reset: self.append(ANSICodes.RESET) styles = list(self.style.styles) if self.style.fg != ANSICodes.NONE: styles.append(self.style.fg) if self.style.bg != ANSICodes.NONE: styles.append(self.style.bg) if styles: self.append(ANSICodes.to_ansi(styles)) def strip_empty_lines(self): remove_last_n = 0 for x in self.lines[::-1]: if len(x.strip()) != 0: break remove_last_n += 1 if remove_last_n != 0: self.lines = self.lines[:-remove_last_n] # Structural nodes def visit_document(self, node): self.push_ctx() def _print_references(self): if not self.references: return self.push_style(styles = ['bold']) self.append('References:') self.pop_style() self.newline(2) self.push_ctx(indent_level = self.ctx.indent_level + 1) for ref in self.references: self.append('[%s]: <' % ref[0]) self.push_style(fg = 'cyan', styles = ['underline']) self.append(ref[1]) self.pop_style() self.append('>') self.newline() self.references = [] self.pop_ctx() def depart_document(self, node): self._print_references() self.depart_section(node) self.pop_ctx() self.strip_empty_lines() self.output = '\n'.join(self.lines) def wrap_current_line(self): indent = self.ctx.indent_level * self.indent_width sublines = wrap(self.curline, width = self.termsize[0] - indent, subsequent_indent = ' ' * indent) self.popline() self.addlines(sublines, strict=True) def depart_paragraph(self, node): if self.options.get('wrap_paragraphs', True): self.wrap_current_line() if not self.ctx.in_list: self.newline() def visit_title(self, node): self.push_style(styles=['bold']) def depart_title(self, node): self.pop_style() self.push_ctx(has_title = True, indent_level = self.ctx.indent_level + 1) self.newline(2) def visit_subtitle(self, node): self.prevline(2) self.append(' - ') def depart_subtitle(self, node): self.nextline(2) def visit_Text(self, node): self.append(node.astext()) def depart_section(self, node): if self.ctx.has_title: self.pop_ctx() def depart_transition(self, node): indent = (self.ctx.indent_level + 2) * self.indent_width char = '╌' if self.options['unicode'] else '-' self.append(' ' * indent + char * (self.termsize[0] - 2 * indent) + ' ' * indent, strict=True) self.newline(2) def _get_uri(self, node): uri = node.attributes.get('refuri', '') if not uri: uri = node.attributes.get('uri', '') return uri def visit_reference(self, node): if self._get_uri(node) == node.astext().strip(): self.append('<') self.push_style(fg = 'cyan', styles = ['underline']) def depart_reference(self, node): self.pop_style() if self._get_uri(node) == node.astext().strip(): self.append('>') else: self.references.append((self.refcount, self._get_uri(node))) if self.options['unicode'] and self.options.get('unicode_superscript', False): self.append(ref_to_unicode(self.refcount)) else: self.append(' [%s]' % self.refcount) self.refcount += 1 # Style nodes visit_strong = npartial(push_style, styles=['bold']) depart_strong = npartial(pop_style) visit_emphasis = npartial(push_style, styles=['italic']) depart_emphasis = npartial(pop_style) def visit_TextElement(self, node): ansi_props = [x[5:] for x in node.attributes['classes'] if x.startswith('ansi-')] style = { 'fg': next((x[3:] for x in ansi_props if x.startswith('fg-') and x[3:] in COLORS), None), 'bg': next((x[3:] for x in ansi_props if x.startswith('bg-') and x[3:] in COLORS), None), 'styles': (x for x in ansi_props if x in STYLES) } self.push_style(**style) def depart_TextElement(self, node): self.pop_style() visit_inline = visit_TextElement depart_inline = depart_TextElement # Lists def visit_enumerated_list(self, node): strt = node.attributes.get('start', 1) self.push_ctx(in_list = True, list_counter = strt) def depart_enumerated_list(self, node): self.pop_ctx() if not self.ctx.in_list: self.newline() def visit_bullet_list(self, node): self.push_ctx(in_list = True, list_counter = 0) def depart_bullet_list(self, node): self.pop_ctx() if not self.ctx.in_list: self.newline() def visit_list_item(self, node): if self.ctx.list_counter: self.append(str(self.ctx.list_counter) + '. ') self.ctx.list_counter += 1 else: self.append('• ' if self.options['unicode'] else '* ') self.push_ctx(indent_level = self.ctx.indent_level + 1) def depart_list_item(self, node): self.pop_ctx() visit_definition_list = npartial(push_ctx, in_list=True, list_counter=0) depart_definition_list = npartial(pop_ctx) def visit_definition(self, node): self.newline() self.push_ctx(indent_level = self.ctx.indent_level + 1) def depart_definition(self, node): self.newline() self.pop_ctx() visit_option_list = npartial(push_ctx, in_list=True, list_counter=0) depart_option_list = npartial(pop_ctx) def depart_option(self, node): self.append(' | ') def depart_option_group(self, node): self.replaceline(self.lines[self.line][:-3], strict=True) self.push_ctx(indent_level = self.ctx.indent_level + 2) self.newline() def visit_option_argument(self, node): self.append(' ') def depart_option_list_item(self, node): self.pop_ctx() # Tables def visit_table(self, node): props = TableSizeCalculator(self.document) node.walkabout(props) writer = TableWriter(props, self.document, **self.options) node.walkabout(writer) self.addlines(writer.lines) # Do not recurse raise nodes.SkipChildren def depart_table(self, node): self.newline() # Misc def depart_image(self, node): if type(node.parent) == nodes.figure: self.visit_reference(node) self.append('[' + node.attributes.get('alt', 'Image') + ']') self.depart_reference(node) self.newline() else: self.append('[' + node.attributes.get('alt', 'Image') + ']') def depart_caption(self, node): self.newline(2) def visit_substitution_definition(self, node): raise nodes.SkipChildren def visit_comment(self, node): raise nodes.SkipChildren def depart_admonition(self, node): if self.ctx.has_title: self.pop_ctx() def visit_block_quote(self, node): self.push_ctx(indent_level = self.ctx.indent_level + 1) def depart_block_quote(self, node): self.pop_ctx() def depart_literal_block(self, node): sublines = self.curline.split('\n') self.replaceline(sublines[0]) self.newline() self.addlines(sublines[1:]) self.newline() def depart_line(self, node): if len(self.curline.strip()) == 0: self.newline() else: self.wrap_current_line() def visit_line_block(self, node): indent = self.ctx.indent_level + (1 if self.ctx.node_type == 'line_block' else 0) self.push_ctx(indent_level = indent, node_type = 'line_block') def depart_line_block(self, node): self.pop_ctx() if self.ctx.node_type != 'line_block': self.newline() def __getattr__(self, name): if name.startswith('visit_') or name.startswith('depart_'): def noop(*args, **kwargs): pass return noop if name == 'curline': return self.lines[self.line] raise AttributeError(name) python-rst2ansi-0.1.5/rst2ansi/functional.py000066400000000000000000000024421272110200000210450ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ def npartial(func, *args, **kwargs): """ Returns a partial node visitor function """ def wrapped(self, node): func(self, *args, **kwargs) return wrapped python-rst2ansi-0.1.5/rst2ansi/get_terminal_size.py000066400000000000000000000077721272110200000224220ustar00rootroot00000000000000"""This is a backport of shutil.get_terminal_size from Python 3.3. The original implementation is in C, but here we use the ctypes and fcntl modules to create a pure Python version of os.get_terminal_size. Pulled from https://github.com/chrippa/backports.shutil_get_terminal_size The MIT License (MIT) Copyright (c) 2014 Christopher Rosell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os import struct import sys from collections import namedtuple __all__ = ["get_terminal_size"] terminal_size = namedtuple("terminal_size", "columns lines") try: from ctypes import windll, create_string_buffer, WinError _handle_ids = { 0: -10, 1: -11, 2: -12, } def _get_terminal_size(fd): handle = windll.kernel32.GetStdHandle(_handle_ids[fd]) if handle == 0: raise OSError('handle cannot be retrieved') if handle == -1: raise WinError() csbi = create_string_buffer(22) res = windll.kernel32.GetConsoleScreenBufferInfo(handle, csbi) if res: res = struct.unpack("hhhhHhhhhhh", csbi.raw) left, top, right, bottom = res[5:9] columns = right - left + 1 lines = bottom - top + 1 return terminal_size(columns, lines) else: raise WinError() except ImportError: import fcntl import termios def _get_terminal_size(fd): try: res = fcntl.ioctl(fd, termios.TIOCGWINSZ, b"\x00" * 4) except IOError as e: raise OSError(e) lines, columns = struct.unpack("hh", res) return terminal_size(columns, lines) def get_terminal_size(fallback=(80, 24)): """Get the size of the terminal window. For each of the two dimensions, the environment variable, COLUMNS and LINES respectively, is checked. If the variable is defined and the value is a positive integer, it is used. When COLUMNS or LINES is not defined, which is the common case, the terminal connected to sys.__stdout__ is queried by invoking os.get_terminal_size. If the terminal size cannot be successfully queried, either because the system doesn't support querying, or because we are not connected to a terminal, the value given in fallback parameter is used. Fallback defaults to (80, 24) which is the default size used by many terminal emulators. The value returned is a named tuple of type os.terminal_size. """ # Try the environment first try: columns = int(os.environ["COLUMNS"]) except (KeyError, ValueError): columns = 0 try: lines = int(os.environ["LINES"]) except (KeyError, ValueError): lines = 0 # Only query if necessary if columns <= 0 or lines <= 0: try: size = _get_terminal_size(sys.__stdout__.fileno()) except (NameError, OSError): size = terminal_size(*fallback) if columns <= 0: columns = size.columns if lines <= 0: lines = size.lines return terminal_size(columns, lines) python-rst2ansi-0.1.5/rst2ansi/table.py000066400000000000000000000227261272110200000200010ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import unicode_literals from docutils import nodes from textwrap import wrap from .unicode import u class CellDimCalculator(nodes.NodeVisitor): def __init__(self, document, cols, rows, width): nodes.NodeVisitor.__init__(self, document) self.cols = cols self.rows = rows self.width = width self.height = 0 def visit_paragraph(self, node): first_line = node.astext().split('\n')[0] # handle weird table sizing from simple rst tables # disregard cells spanning multiple columns, as # these don't contribute to the cell width calculation if len(first_line) >= self.width: self.width = len(first_line) + 2 sublines = wrap(node.astext(), width = self.width) self.height = int(len(sublines) / self.rows) raise nodes.StopTraversal def visit_table(self, node): c = TableSizeCalculator(self.document) node.walkabout(c) self.height = int(c.height / self.rows) raise nodes.StopTraversal def visit_literal_block(self, node): self.height = int(len(node.astext().split('\n')) / self.rows) raise nodes.StopTraversal visit_Text = visit_literal_block def __getattr__(self, name): if name.startswith('visit_') or name.startswith('depart_'): def noop(*args, **kwargs): pass return noop raise AttributeError(name) class TableSizeCalculator(nodes.NodeVisitor): def __init__(self, document): nodes.NodeVisitor.__init__(self, document) self.level = 0 self.widths = [] self.heights = [] self.rows = 0 def __getattr__(self, name): if name.startswith('visit_') or name.startswith('depart_'): def noop(*args, **kwargs): pass return noop raise AttributeError(name) def visit_table(self, node): if self.level > 0: raise SkipChildren self.level += 1 def depart_table(self, node): self.width = sum(self.widths) + (len(self.widths) + 1) self.height = sum(self.heights) + (len(self.heights) + 1) self.level -= 1 def visit_tgroup(self, node): self.cols = node.attributes['cols'] def visit_colspec(self, node): self.widths.append(node.attributes['colwidth']) def visit_row(self, node): self.rows += 1 self.heights.append(1) self.col = 0 def visit_entry(self, node): cols = node.attributes.get('morecols', 0) + 1 rows = node.attributes.get('morerows', 0) + 1 width = sum(self.widths[self.col:self.col + cols]) + (cols - 1) c = CellDimCalculator(self.document, cols, rows, width) node.walkabout(c) # Correct invalid column sizing for simple rst tables if c.width > width and cols == 1: self.widths[self.col] = c.width self.heights[-1] = max(self.heights[-1], c.height) self.col += 1 raise nodes.SkipChildren class TableDrawer(nodes.NodeVisitor): def __init__(self, props, document, **options): nodes.NodeVisitor.__init__(self, document) self.props = props self.level = 0 self.lines = [''] self.line = 0 self.cursor = 0 self.col = 0 self.row = 0 self.nb_rows = 0 self.options = options def unicode_intersection(char, next): switch = { ('─', '│'): '┬', ('┐', '│'): '┐', ('┘', '│'): '┤', ('┘', '─'): '┴', ('┴', '│'): '┼', ('│', '─'): '├', ('┤', '─'): '┼', (' ', '─'): '┘', ('└', '─'): '└', ('═', '│'): '╤', ('╕', '│'): '╕', ('╛', '│'): '╡', ('╛', '═'): '╧', ('╧', '│'): '╪', ('│', '═'): '╞', ('╡', '═'): '╪', (' ', '═'): '╛', ('╘', '═'): '╘', } return switch[(u(char), u(next))] if options.get('unicode', False): self.char_single_rule = '─' self.char_double_rule = '═' self.char_vertical_rule = '│' self.get_intersection = unicode_intersection self.top_left = '┌' self.top_right = '┐' self.bottom_left = '╘' else: self.char_single_rule = '-' self.char_double_rule = '=' self.char_vertical_rule = '|' self.get_intersection = lambda *args: '+' self.top_left = self.bottom_left = self.top_right = '+' def __getattr__(self, name): if name.startswith('visit_') or name.startswith('depart_'): def noop(*args, **kwargs): pass return noop if name == 'curline': return self.lines[self.line] raise AttributeError(name) def _draw_rule(self): self.lines[self.line] += self.top_left + self.char_single_rule * (self.props.width - 2) + self.top_right self.lines.extend([self.char_vertical_rule + ' ' * (self.props.width - 1)] * (self.props.height - 2)) self.lines.extend([self.bottom_left + ' ' * (self.props.width - 1)]) self.line += 1 self.cursor = 0 def visit_table(self, node): if self.level > 0: raise SkipChildren self.level += 1 self._draw_rule() def depart_table(self, node): self.level -= 1 def visit_row(self, node): self.col = 0 self.cursor = 0 def depart_row(self, node): self.line += self.props.heights[self.row] + 1 self.row += 1 self.local_row += 1 def visit_thead(self, node): self.nb_rows = len(node.children) self.local_row = 0 visit_tbody = visit_thead def visit_entry(self, node): cols = node.attributes.get('morecols', 0) + 1 rows = node.attributes.get('morerows', 0) + 1 width = sum(self.props.widths[self.col:self.col + cols]) + (cols - 1) height = sum(self.props.heights[self.row:self.row + rows]) + (rows - 1) rule = self.char_double_rule if self.local_row + rows - 1 == self.nb_rows - 1 else self.char_single_rule sep = self.char_vertical_rule # Draw the horizontal rule line = self.lines[self.line + height] int1 = self.get_intersection(line[self.cursor], rule) int2 = self.get_intersection(line[self.cursor + width + 1], rule) line = line[:self.cursor] + int1 + (width * rule) + int2 + line[self.cursor + width + 2:] self.lines[self.line + height] = line # Draw the vertical rule for i in range(height): line = self.lines[self.line + i] line = line[:self.cursor + width + 1] + sep + line[self.cursor + width + 2:] self.lines[self.line + i] = line line = self.lines[self.line - 1] int3 = self.get_intersection(line[self.cursor + width + 1], sep) line = line[:self.cursor + width + 1] + int3 + line[self.cursor + width + 2:] self.lines[self.line - 1] = line self.col += cols self.cursor += width + 1 # Do not recurse raise nodes.SkipChildren class TableWriter(nodes.NodeVisitor): def __init__(self, props, document, **options): nodes.NodeVisitor.__init__(self, document) self.props = props self.level = 0 self.line = 0 self.cursor = 0 self.col = 0 self.row = 0 self.nb_rows = 0 self.options = options def __getattr__(self, name): if name.startswith('visit_') or name.startswith('depart_'): def noop(*args, **kwargs): pass return noop raise AttributeError(name) def visit_table(self, node): drawer = TableDrawer(self.props, self.document, **self.options) node.walkabout(drawer) self.lines = drawer.lines def visit_row(self, node): self.col = 0 self.cursor = 0 def depart_row(self, node): self.line += self.props.heights[self.row] + 1 self.row += 1 self.local_row += 1 def visit_thead(self, node): self.nb_rows = len(node.children) self.local_row = 0 visit_tbody = visit_thead def visit_entry(self, node): cols = node.attributes.get('morecols', 0) + 1 rows = node.attributes.get('morerows', 0) + 1 width = sum(self.props.widths[self.col:self.col + cols]) + (cols - 1) height = sum(self.props.heights[self.row:self.row + rows]) + (rows - 1) from .ansi import ANSITranslator if node.children: v = ANSITranslator(self.document, termsize=(width - 2, height), **self.options) node.children[0].walkabout(v) v.strip_empty_lines() i = 1 for l in v.lines: for sl in l.split('\n'): line = self.lines[self.line + i] line = line[:self.cursor + 2] + sl + line[self.cursor + 2 + len(sl):] self.lines[self.line + i] = line i += 1 self.col += cols self.cursor += width + 1 # Do not recurse raise nodes.SkipChildren python-rst2ansi-0.1.5/rst2ansi/unicode.py000066400000000000000000000035621272110200000203350ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import unicode_literals import sys def num_to_superscript(n): sups = { '0': '\u2070', '1': '\xb9', '2': '\xb2', '3': '\xb3', '4': '\u2074', '5': '\u2075', '6': '\u2076', '7': '\u2077', '8': '\u2078', '9': '\u2079' } return ''.join(sups.get(c, c) for c in str(n)) def ref_to_unicode(n): return '⁽' + num_to_superscript(n) + '⁾' def u(s): # Useful for very coarse version differentiation. PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 if PY3: return s else: # Workaround for standalone backslash try: ret_s = unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") except TypeError: ret_s = s.replace(r'\\', r'\\\\') return ret_s python-rst2ansi-0.1.5/rst2ansi/visitor.py000066400000000000000000000034411272110200000204020ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from docutils import core, frontend, nodes, utils, writers, languages, io from docutils.utils.error_reporting import SafeString from docutils.transforms import writer_aux from docutils.parsers.rst import roles from .ansi import ANSITranslator class Writer(writers.Writer): def __init__(self, **options): writers.Writer.__init__(self) self.translator_class = ANSITranslator self.options = options def translate(self): visitor = self.translator_class(self.document, **self.options) self.document.walkabout(visitor) self.output = visitor.output def get_transforms(self): return writers.Writer.get_transforms(self) + [writer_aux.Admonitions] python-rst2ansi-0.1.5/rst2ansi/wrap.py000066400000000000000000000036571272110200000176650ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ The MIT License (MIT) Copyright © 2015-2016 Franklin "Snaipe" Mathieu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import re _ANSI_CODE = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]') def word_size(word): return len(_ANSI_CODE.sub('', word)) def wrap(text, width=80, subsequent_indent=''): words = text.split() line_size = 0 lines = [[]] for w in words: size = word_size(w) + 1 if size == 0: continue if line_size + size - 1 > width and line_size > width / 2: line_size = len(subsequent_indent) lines.append([]) while line_size + size - 1 > width: stripped = width - line_size - 1 lines[-1].append(w[:stripped] + '-') line_size = len(subsequent_indent) lines.append([]) w = w[stripped:] size -= stripped if size == 0: continue lines[-1].append(w) line_size += size return [subsequent_indent + ' '.join(words) for words in lines] python-rst2ansi-0.1.5/setup.cfg000066400000000000000000000000371272110200000164030ustar00rootroot00000000000000[bdist_wheel] python-tag = py3 python-rst2ansi-0.1.5/setup.py000066400000000000000000000024121272110200000162730ustar00rootroot00000000000000#!/usr/bin/env python import os import sys try: from setuptools import setup except ImportError: from distutils.core import setup def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name="rst2ansi", version="0.1.5", author="Snaipe", author_email="franklinmathieu@gmail.com", description="A rst converter to ansi-decorated console output", long_description=read('README.rst'), license="MIT", keywords="rst restructuredtext ansi console code converter", url="https://github.com/Snaipe/python-rst-to-ansi", packages=['rst2ansi'], requires=['docutils'], scripts=['bin/rst2ansi'], data_files=[], classifiers=[ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Markup", "Topic :: Utilities", ], ) python-rst2ansi-0.1.5/test/000077500000000000000000000000001272110200000155415ustar00rootroot00000000000000python-rst2ansi-0.1.5/test/empty.t000066400000000000000000000000751272110200000170660ustar00rootroot00000000000000Test the rendering of an empty file: $ rst2ansi /dev/null python-rst2ansi-0.1.5/test/lists.t000066400000000000000000000071201272110200000170640ustar00rootroot00000000000000Docutils bullet list: $ echo " > Docutils Bullet List > > - This is item 1 > - This is item 2 > > - Bullets are '-', '*' or '+'. > Continuing text must be aligned > after the bullet and whitespace. > > Note that a blank line is required > before the first item and after the > last, but is optional between items. > " > paragraph.rst $ rst2ansi paragraph.rst Docutils Bullet List \u2022 This is item 1 \u2022 This is item 2 \u2022 Bullets are '-', '*' or '+'. Continuing text must be aligned after the bullet and whitespace. Note that a blank line is required before the first item and after the last, but is optional between items. Docutils enumerated lists: $ echo " > Docutils Enumerated List > > 3. This is the first item > 4. This is the second item > 5. Enumerators are arabic numbers, > single letters, or roman numerals > 6. List items should be sequentially > numbered, but need not start at 1 > (although not all formatters will > honour the first index). > #. This item is auto-enumerated > " > paragraph.rst $ rst2ansi paragraph.rst Docutils Enumerated List 3. This is the first item 4. This is the second item 5. Enumerators are arabic numbers, single letters, or roman numerals 6. List items should be sequentially numbered, but need not start at 1 (although not all formatters will honour the first index). 7. This item is auto-enumerated Test bullet list: $ echo " > Simple bullet list > > * list 1 > * list 2 with multiple > lines > * list 3 > " > paragraph.rst $ rst2ansi paragraph.rst Simple bullet list \u2022 list 1 \u2022 list 2 with multiple lines \u2022 list 3 Test definition list: $ echo " > Definition list > > Dinner > An evening meal. > > Lunch > A meal > typically > taken > mid day > > Breakfast > Morning meal that 'breaks' the overnight 'fast'. > " > paragraph.rst $ rst2ansi paragraph.rst Definition list Dinner An evening meal. Lunch A meal typically taken mid day Breakfast Morning meal that 'breaks' the overnight 'fast'. Option list: $ echo " > Option List > > -a command-line option 'a' > -b file options can have arguments > and long descriptions > --long options can be long also > --input file long options can also have > arguments > TODO: This should work with --input=file also > /V DOS/VMS-style options too > --text This is a long text that should span the line so that I can > see if there is the correct word wrap. If there > isn't it could be problem, but maybe not. > " > paragraph.rst $ rst2ansi paragraph.rst Option List -a command-line option 'a' -b file options can have arguments and long descriptions --long options can be long also --input file long options can also have arguments TODO: This should work with --input=file also /V DOS/VMS-style options too --text This is a long text that should span the line so that I can see if there is the correct word wrap. If there isn't it could be problem, but maybe not. Check Sub List: $ echo " > #. numbered > #. list > > #. and a > #. sublist > > #. end > > * unordered > * list > " > paragraph.rst $ rst2ansi paragraph.rst 1. numbered 2. list 1. and a 2. sublist 3. end \u2022 unordered \u2022 list python-rst2ansi-0.1.5/test/paragraph.t000066400000000000000000000052421272110200000176760ustar00rootroot00000000000000Test simple paragraph: $ echo "Lorem ipsum dolor sit amet" > paragraph.rst $ rst2ansi paragraph.rst Lorem ipsum dolor sit amet Test multi-line paragraph: $ echo "Lorem ipsum dolor sit amet, > consectetur adipiscing elit." > paragraph.rst $ rst2ansi paragraph.rst Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test multiple paragraphs: $ echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit. > > Donec a diam lectus." > paragraph.rst $ rst2ansi paragraph.rst Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Test paragraph wrapping: $ echo " > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam > lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra > nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam > eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, > ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula > ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing > elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, > adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. > Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl > imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio > eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum > sociis natoque penatibus et magnis dis parturient montes, nascetur > ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem > facilisis semper ac in est. > " | tr -d '\n' > long_paragraph.rst $ rst2ansi long_paragraph.rst Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est. python-rst2ansi-0.1.5/test/styles.t000066400000000000000000000044211272110200000172520ustar00rootroot00000000000000Test foreground colors: $ echo ':ansi-fg-black:`black`' > styles.rst $ echo ':ansi-fg-red:`red`' >> styles.rst $ echo ':ansi-fg-green:`green`' >> styles.rst $ echo ':ansi-fg-yellow:`yellow`' >> styles.rst $ echo ':ansi-fg-blue:`blue`' >> styles.rst $ echo ':ansi-fg-magenta:`magenta`' >> styles.rst $ echo ':ansi-fg-cyan:`cyan`' >> styles.rst $ echo ':ansi-fg-white:`white`' >> styles.rst $ rst2ansi styles.rst \x1b[30mblack\x1b[0m \x1b[31mred\x1b[0m \x1b[32mgreen\x1b[0m \x1b[33myellow\x1b[0m \x1b[34mblue\x1b[0m \x1b[35mmagenta\x1b[0m \x1b[36mcyan\x1b[0m \x1b[37mwhite\x1b[0m (esc) Test background colors: $ echo ':ansi-bg-black:`black`' > styles.rst $ echo ':ansi-bg-red:`red`' >> styles.rst $ echo ':ansi-bg-green:`green`' >> styles.rst $ echo ':ansi-bg-yellow:`yellow`' >> styles.rst $ echo ':ansi-bg-blue:`blue`' >> styles.rst $ echo ':ansi-bg-magenta:`magenta`' >> styles.rst $ echo ':ansi-bg-cyan:`cyan`' >> styles.rst $ echo ':ansi-bg-white:`white`' >> styles.rst $ rst2ansi styles.rst \x1b[40mblack\x1b[0m \x1b[41mred\x1b[0m \x1b[42mgreen\x1b[0m \x1b[43myellow\x1b[0m \x1b[44mblue\x1b[0m \x1b[45mmagenta\x1b[0m \x1b[46mcyan\x1b[0m \x1b[47mwhite\x1b[0m (esc) Test styles: $ echo ':ansi-bold:`bold`' > styles.rst $ echo ':ansi-dim:`dim`' >> styles.rst $ echo ':ansi-italic:`italic`' >> styles.rst $ echo ':ansi-underline:`underline`' >> styles.rst $ echo ':ansi-blink:`blink`' >> styles.rst $ echo ':ansi-blink-fast:`blink-fast`' >> styles.rst $ echo ':ansi-inverse:`inverse`' >> styles.rst $ echo ':ansi-conceal:`conceal`' >> styles.rst $ echo ':ansi-strikethrough:`strikethrough`' >> styles.rst $ rst2ansi styles.rst \x1b[1mbold\x1b[0m \x1b[2mdim\x1b[0m \x1b[3mitalic\x1b[0m \x1b[4munderline\x1b[0m \x1b[5mblink\x1b[0m \x1b[6mblink-fast\x1b[0m \x1b[7minverse\x1b[0m \x1b[8mconceal\x1b[0m \x1b[9mstrikethrough\x1b[0m (esc) Test standard reStructuredText text decorations: $ echo '*emphasis*' > styles.rst $ echo '**strong emphasis**' >> styles.rst $ rst2ansi styles.rst \x1b[3memphasis\x1b[0m \x1b[1mstrong emphasis\x1b[0m (esc) Test role coalescing: $ echo ' > .. role:: blue-and-bold > :class: ansi-bold ansi-fg-blue > > :blue-and-bold:`test` > ' > styles.rst $ rst2ansi styles.rst \x1b[1;34mtest\x1b[0m (esc)