Skip to content

Commit

Permalink
Sphinx docs (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr authored Sep 27, 2021
1 parent d5d9555 commit 3984825
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Convert text with ANSI color codes to HTML or to LaTeX.

Inspired by and developed off of the work of `pixelbeat`_ and `blackjack`_.

`Read the docs <https://ansi2html.readthedocs.io/>`_ for more informations.

Build Status
------------

Expand Down
6 changes: 6 additions & 0 deletions ansi2html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class Ansi2HTMLConverter:
"""Convert Ansi color codes to CSS+HTML
Example:
>>> conv = Ansi2HTMLConverter()
>>> ansi = " ".join(sys.stdin.readlines())
>>> html = conv.convert(ansi)
Expand Down Expand Up @@ -544,6 +545,11 @@ def attrs(self):
return self._attrs

def convert(self, ansi, full=True, ensure_trailing_newline=False):
r"""
:param ansi: ANSI sequence to convert.
:param full: Whether to include the full HTML document or only the body.
:param ensure_trailing_newline: Ensures that ``\n`` character is present at the end of the output.
"""
attrs = self.prepare(ansi, ensure_trailing_newline=ensure_trailing_newline)
if not full:
return attrs["body"]
Expand Down
21 changes: 21 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?= -aE
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
rm -rf "$(BUILDDIR)"
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
8 changes: 8 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
API Reference
=============


.. autoclass:: ansi2html.Ansi2HTMLConverter
:members:
:undoc-members:
:inherited-members:
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changelog
=========

.. include:: ../../changelog.rst
35 changes: 35 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from setuptools_scm import get_version

# -- Project information -----------------------------------------------------

project = "ansi2html"
copyright = "2021, Ralph Bean, Robin Schneider and various contributors"
author = "Ralph Bean, Robin Schneider and various contributors"

# The full version, including alpha/beta/rc tags
release = get_version(root="../..", relative_to=__file__)

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx_rtd_theme"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
17 changes: 17 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

.. include:: ../../README.rst

.. toctree::
:maxdepth: 1
:caption: Contents:

self
api
changelog


Indices and tables
==================

* :ref:`genindex`
* :ref:`search`
13 changes: 13 additions & 0 deletions readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

sphinx:
fail_on_warning: false

python:
version: 3.8
system_packages: false
install:
- method: pip
path: .
extra_requirements:
- docs
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ console_scripts =
[options.packages.find]
where = .

[options.extras_require]
docs =
Sphinx
setuptools_scm
sphinx_rtd_theme

[flake8]
format = pylint
# E203: https://github.com/python/black/issues/315
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ commands =
whitelist_externals =
rm
sh

[testenv:docs]
description = Generate Sphinx docs under build/docs
extras = docs
commands =
sphinx-build -aE -b html {toxinidir}/docs/source {toxinidir}/build/docs

0 comments on commit 3984825

Please sign in to comment.