Code Monkey home page Code Monkey logo

rinohtype's Introduction

rinohtype

PyPI

Python version

Discussions

Gitter chat

Tests

Test coverage

rinohtype is a batch-mode document processor. It renders structured documents to PDF based on a document template and a style sheet. An important design goal of rinohtype is make document layout and style customization user-friendly. Have a look at the showcase to get an idea of the level of customization that is possible. See the documentation to learn how to customize the style of your document.

Call for Contributions

Since rinohtype is a fairly sizable project and currently being maintained by a single person, your contribution can make a big difference. Specifically, the following things can help move rinohtype forward:

  • development of professional-looking stylesheets and document templates
  • volunteering to be a maintainer: fix issues that pop up when new versions of dependencies are released (Python, Sphinx, ...), or handling platform-specific regressions (development is mainly on macOS).
  • help with maintaining and improving the documentation
  • development of new features, e.g. widow/orphan handling, Knuth-Plass line breaking, mathematics typesetting, performance improvements, ...
  • companies might be interested in funding the development of particular features

So if you are interested in helping with any of these items, please don't hesitate to get in touch via Discussions, Gitter or [email protected]!

Features

rinohtype is still in beta, so you might run into some issues when using it. I'd highly appreciate it if you could create a ticket for any bugs you may encounter. That said, rinohtype is already quite capable. For example, it should be able to replace Sphinx's LaTeX builder in most cases. Here is an overview of the main features:

  • a powerful page layout system supporting columns, running headers/footers, floatable elements and footnotes
  • support for figures and (large) tables, optionally rendered sideways
  • automatic generation of table of contents and index
  • automatic numbering and cross-referencing of section headings, figures and tables
  • configure one of the included document templates or create your own
  • an intuitive style sheet system inspired by CSS allowing changing almost every aspect of how document elements are rendered
  • modular design allowing for multiple frontends (such as reStructuredText, Markdown, DocBook, ...)
  • handles OpenType, TrueType and Type1 fonts with support for advanced typographic features such as kerning, ligatures, small capitals and old style figures
  • built-in support for the 1000+ libre licensed fonts on Google Fonts
  • embeds PDF, PNG and JPEG images, preserving transparency and color profiles
  • easy to install and deploy; pure-Python with few dependencies
  • built on Unicode; ready for non-latin languages

rinohtype's primary input format is reStructuredText. The rinoh command line tool renders reStructuredText documents and the included Sphinx builder makes it possible to output large documents with your own style applied. Have a look at the rinohtype manual for an example of the output.

There is also a commercial DITA frontend, but it's development is currently on hold. Please contact me if you are interested in testing it.

Requirements

rinohtype supports all stable Python 3 versions that have not reached end-of-life status. For parsing reStructuredText and CommonMark documents, rinohtype depends on docutils and myst-parser respectively. pip takes care of installing these requirements when you install rinohtype.

Syntax highlighting of code blocks is enabled if Pygments is installed, which will be installed automatically with Sphinx. If you want to include images other than PDF, PNG or JPEG, you also need to install Pillow.

Getting Started

Installation is trivial:

pip install rinohtype

If you want to have access to bug fixes and features that are not available in a release, you can install the current development version:

pip install https://github.com/brechtm/rinohtype/archive/refs/heads/master.zip

reStructuredText Renderer

The easiest way to get started with rinohtype is to render a reStructuredText document (such as CHANGES.rst from this repository) using the rinoh command line tool:

rinoh CHANGES.rst

When rinoh finishes, you will find CHANGES.pdf alongside the input file.

By default rinoh renders the input document using the article template. Run rinoh --help to see how you can tell rinoh which document template and style sheet to use.

Sphinx Builder

rinohtype can be used as a drop-in replacement for the LaTeX builder (the latex_documents configuration variable has to be set). Simply select the rinoh builder when building the Sphinx project:

sphinx-build -b rinoh . _build/rinoh

Contributing

See CONTRIBUTING.rst and DEVELOPING.rst

License

All of rinohtype's source code is licensed under the Affero GPL 3.0, unless indicated otherwise in the source file (such as hyphenator.py and purepng.py).

The Affero GPL requires for software that builds on rinohtype to also be released as open source under this license. For building closed-source applications, you can obtain a commercial license. The author of rinohtype is also available for consultancy projects involving rinohtype.

rinohtype's People

Contributors

alexfargus avatar brechtm avatar dependabot[bot] avatar fizzadar avatar foster999 avatar frol avatar jaraco avatar jemrobinson avatar jwhitham avatar marian-vignau avatar mforbes avatar mjamro avatar msuszko avatar normanlorrain avatar pabloalexis611 avatar rappdw avatar seizmo avatar tavaresfilipe avatar th0mr avatar timgates42 avatar timm638 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rinohtype's Issues

Optimize rendering performance

Many features have been added since the rendering loop was last profiled and optimized. See where in the code most time is spent and optimize these parts.

HTML5 tags

Rinohtype is a wonderful document generator, but I am wondering that whether you can use HTML5 tags and a CSS-like styling system for input, such as <table> instead of <tabular>. It may help publishing your document to both the web and the print.

ClassNotFound exception in Literal_Block.lexer_getter()

Rendering the Lizmap documentation:

  ...
  File "/Users/brechtm/Documents/Code/rinohtype/src/rinoh/highlight.py", line 54, in highlight_block
    lexer = get_lexer(text, language)
  File "/Users/brechtm/Documents/Code/rinohtype/src/rinoh/frontend/sphinx/nodes.py", line 122, in lexer_getter
    lexer = get_lexer_by_name(language)
  File "/Users/brechtm/.pyenv/versions/rinoh-py35/lib/python3.5/site-packages/pygments/lexers/__init__.py", line 93, in get_lexer_by_name
    raise ClassNotFound('no lexer for alias %r found' % _alias)
pygments.util.ClassNotFound: no lexer for alias 'none' found

Internally represent style log as a tree

This more easily allows for a better representation of the log:

  • plain text log: using ASCII/Unicode lines to visualize the document tree structure
  • HTML log: allow dynamically collapsing/expanding nodes (and hide all inline elements for example)

Complete support for code highlighting

Syntax highlighting of code blocks in Sphinx projects does not yet support:

  • background color (and border) for inline text
  • highlighting of lines
  • displaying line numbers

Installation broken

While reviewing your proposal for EuroPython 2014 I came the following installation problem:

Suxmac-2:rinohtype ajung$ bin/python setup.py install
Attempting to get version number from git...
fatal: No names found, cannot describe anything.
Assume we are running from a source distribution.
Traceback (most recent call last):
File "setup.py", line 37, in
with open(VERSION_FILE) as version_file:
IOError: [Errno 2] No such file or directory: 'rinoh/version.py'

I don't think that it is of advantage writing a proposal for a module that can not be installed properly.

Turn templates into resources

Just like style sheets and typefaces, templates could be uniquely identified by name and automatically installed from PyPI.

Not sure how to handle TemplateConfiguration. Should this also be a Resource?

Long strings in a code block disappear

Example: in the "HTTP Verbs" section of the requests documentation.

Code block::

    >>> import requests
    >>> r = requests.get('https://api.github.com/repos/kennethreitz/requests/git/commits/a050faf084662f3a352dd1a941f2c7c9f886d4ad')

RecursionError: maximum recursion depth exceeded while calling a Python object

demo.txt:

.. [#label] Footnotes may be numbered, either manually (as in [1]_) or
   automatically using a "#"-prefixed label.  This footnote has a
   label so it can be referred to from multiple places, both as a
   footnote reference ([#label]_) and as a hyperlink reference
   (label_).
$ rinoh demo.txt
qq.txt:1: (ERROR/3) Unknown target name: "1".
RinohType 0.1.3-154-g264f (Feb 28 2016, 09:57:09)  Copyright (c) Brecht Machiels
This program comes with ABSOLUTELY NO WARRANTY. Its use is subject
to the terms of the GNU Affero General Public License version 3.
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
Traceback (most recent call last):
  File "env3/bin/rinoh", line 5, in <module>
    main()
  File "env3/lib/python3.5/site-packages/rinoh/tool.py", line 44, in main
    document.render(input_root)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 360, in render
    section_num_pages = self.render_pages(_sections)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 386, in render_pages
    section_page_count = section.render(sum(section_page_counts))
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 235, in render
    part_page_count = part.render(doc_page_count + section_page_count)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 171, in render
    chains_requiring_new_page = set(chain for chain in page.render())
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 171, in <genexpr>
    chains_requiring_new_page = set(chain for chain in page.render())
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 117, in render
    for chain in super().render(rerender=index > 0):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 178, in render
    for chain in child.render(rerender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 178, in render
    for chain in child.render(rerender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 278, in render
    last_descender=last_descender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 557, in render
    self._state.flowable_state)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 125, in flow
    state=state, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 348, in render
    render_content(maybe_container, last_descender)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 334, in render_content
    descender, state=state)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 125, in flow
    state=state, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 244, in render
    state=state.first_flowable_state, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 125, in flow
    state=state, **kwargs)
  ...
  File "env3/lib/python3.5/site-packages/rinoh/paragraph.py", line 260, in render
    line_width = float(container.width)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 129, in __float__
    return float(self.minuend) - float(self.subtrahend)
  File "env3/lib/python3.5/site-packages/rinoh/dimension.py", line 109, in __float__
    return float(self._value)
RecursionError: maximum recursion depth exceeded while calling a Python object

Avoid a second rendering pass if it is not needed

If the document contains no page references, a second rendering pass is not required. We can still save the .rtc though.

If a table of contents or index is present, there will always be page references though.

Undeclared purepng > 0.1 dependency

setup.py should declare the dependency on purepng, in install_requires. Note that currently this dependency is on an unreleased version of purepng.

Running rinoh in a fresh virtualenv. :

(env) alex@martha:~/src/rinohtype$ pip install -e .
...
Successfully installed RinohType
Cleaning up...
(env) alex@martha:~/src/rinohtype$ rinoh
Traceback (most recent call last):
  File "/home/alex/src/rinohtype/env/bin/rinoh", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/alex/src/rinohtype/bin/rinoh", line 4, in <module>
    from rinoh.tool import main
  File "/home/alex/src/rinohtype/rinoh/__init__.py", line 37, in <module>
    module = import_module('.' + name, __name__)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/alex/src/rinohtype/rinoh/document.py", line 31, in <module>
    from .backend import pdf
  File "/home/alex/src/rinohtype/rinoh/backend/pdf/__init__.py", line 19, in <module>
    from .png import PNGReader
  File "/home/alex/src/rinohtype/rinoh/backend/pdf/png.py", line 11, in <module>
    import png as purepng
ImportError: No module named 'png'

Install the latest released version of purepng (0.1.0), running rinoh raises an AttributeError:

(env) alex@martha:~/src/rinohtype$ pip install purepng
Downloading/unpacking purepng
  Downloading purepng-0.1.0.zip (284kB): 284kB downloaded
...
Successfully installed purepng
Cleaning up...
(env) alex@martha:~/src/rinohtype$ rinoh
Traceback (most recent call last):
  File "/home/alex/src/rinohtype/env/bin/rinoh", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/alex/src/rinohtype/bin/rinoh", line 4, in <module>
    from rinoh.tool import main
  File "/home/alex/src/rinohtype/rinoh/__init__.py", line 37, in <module>
    module = import_module('.' + name, __name__)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/alex/src/rinohtype/rinoh/document.py", line 31, in <module>
    from .backend import pdf
  File "/home/alex/src/rinohtype/rinoh/backend/pdf/__init__.py", line 19, in <module>
    from .png import PNGReader
  File "/home/alex/src/rinohtype/rinoh/backend/pdf/png.py", line 166, in <module>
    RENDERING_INTENT = {purepng.ABSOLUTE_COLORIMETRIC: ABSOLUTE_COLORIMETRIC,
AttributeError: 'module' object has no attribute 'ABSOLUTE_COLORIMETRIC'

Install an unreleased build of purepng, straight from github. rinoh runs

(env) alex@martha:~/src/rinohtype$ pip uninstall purepng
Uninstalling purepng:
...
  Successfully uninstalled purepng
(env) alex@martha:~/src/rinohtype$ pip install https://github.com/Scondo/purepng/archive/58f553e62a4b608df04b19d2ff83f12607b49f63.zip
Downloading/unpacking https://github.com/Scondo/purepng/archive/58f553e62a4b608df04b19d2ff83f12607b49f63.zip
  Downloading 58f553e62a4b608df04b19d2ff83f12607b49f63.zip (unknown size): 267kB downloaded
  Running setup.py (path:/tmp/pip-tdvayijc-build/setup.py) egg_info for package from https://github.com/Scondo/purepng/archive/58f553e62a4b608df04b19d2ff83f12607b49f63.zip

    warning: no directories found matching 'html'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.DS_Store' found anywhere in distribution
Installing collected packages: purepng
  Running setup.py install for purepng

    warning: no directories found matching 'html'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.DS_Store' found anywhere in distribution
Successfully installed purepng
Cleaning up...
(env) alex@martha:~/src/rinohtype$ rinoh
usage: rinoh [-h] [--paper [PAPER]] [input]

Render a reStructuredText document to PDF.

positional arguments:
  input            the reStructuredText document to render

optional arguments:
  -h, --help       show this help message and exit
  --paper [PAPER]  the paper size to render to (default: A4)
(env) alex@martha:~/src/rinohtype$ 

Add option to keep minimally x number of lines together

Add a ParagraphStyle attribute split_minimum_lines to configure how paragraphs are split across pages. For example, if split_minimum_lines is set to 3, a paragraph will start on the next page if less than 2 lines fit on the current page.

Travis CI: install poppler-utils 0.41.0

The poppler-utils version (0.18.4) provided by Ubuntu 12.04 cannot properly render PDFs generated by rinohtype (see #2). Poppler 0.41.0 can be built on Ubuntu, so we could use that one:

apt-get install libopenjpeg
wget https://poppler.freedesktop.org/poppler-0.41.0.tar.xz
tar xf poppler-0.41.0.tar.xz
cd poppler-0.41.0
./configure --prefix=/usr
make
make install

We should package this in a .deb so it can be easily installed before running the tests on Travis.

Non-latin characters produce "?" output instead of a proper character

demo.txt

Non-latin characters
====================

Ф - Cyrillyc

검 - Korean

ت - Arabic
$ rinoh  demo.rst
RinohType 0.1.3-154-g264f (Feb 28 2016, 09:57:09)  Copyright (c) Brecht Machiels
This program comes with ABSOLUTELY NO WARRANTY. Its use is subject
to the terms of the GNU Affero General Public License version 3.
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
TeXGyrePagella-Regular does not contain glyph for unicode index 0x0424 (Ф)
TeXGyrePagella-Regular does not contain glyph for unicode index 0xac80 (검)
TeXGyrePagella-Regular does not contain glyph for unicode index 0x062a (ت)
TeXGyreHeros-Bold does not contain glyph for unicode index 0x0009 (     )
Writing output: demo.pdf

PDF contains:

? - Cyrillyc
? - Korean
? - Arabic

UnboundLocalError: local variable 'width' referenced before assignment

demo.txt:

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
$ rinoh demo.txt
RinohType 0.1.3-154-g264f (Feb 28 2016, 09:57:09)  Copyright (c) Brecht Machiels
This program comes with ABSOLUTELY NO WARRANTY. Its use is subject
to the terms of the GNU Affero General Public License version 3.
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
No style 'table of contents title' found in stylesheet
No style 'table head cell right border' found in stylesheet
No style 'table cell right border' found in stylesheet
No style 'table head cell right border' found in stylesheet
No style 'table cell right border' found in stylesheet
No style 'table head left border' found in stylesheet
No style 'table left border' found in stylesheet
No style 'table head cell left border' found in stylesheet
No style 'table cell left border' found in stylesheet
No style 'table head left border' found in stylesheet
No style 'table left border' found in stylesheet
No style 'table head cell left border' found in stylesheet
No style 'table cell left border' found in stylesheet
Traceback (most recent call last):
  File "env3/lib/python3.5/site-packages/rinoh/util.py", line 101, in function_wrapper
    return cache[args_kwargs]
KeyError: ('vertical_align', <rinohlib.templates.article.Article object at 0x7f0cad6bc4e0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "env3/lib/python3.5/site-packages/rinoh/util.py", line 101, in function_wrapper
    return cache[args_kwargs]
KeyError: (<rinohlib.templates.article.Article object at 0x7f0cad6bc4e0>,)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 412, in flow
    state)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 125, in flow
    state=state, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/table.py", line 101, in render
    if render_rows(self.head) != len(self.head):
  File "env3/lib/python3.5/site-packages/rinoh/table.py", line 95, in render_rows
    rendered_rows)
  File "env3/lib/python3.5/site-packages/rinoh/table.py", line 242, in _place_rows_and_render_borders
    document)
  File "env3/lib/python3.5/site-packages/rinoh/util.py", line 103, in function_wrapper
    cache_value = function(obj, *args, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/style.py", line 338, in get_style
    return self.get_style_recursive(attribute, flowable_target)
  File "env3/lib/python3.5/site-packages/rinoh/style.py", line 358, in get_style_recursive
    style = self._style(flowable_target)
  File "env3/lib/python3.5/site-packages/rinoh/util.py", line 103, in function_wrapper
    cache_value = function(obj, *args, **kwargs)
  File "env3/lib/python3.5/site-packages/rinoh/style.py", line 374, in _style
    return container.document.stylesheet.find_style(self, container)
AttributeError: 'Article' object has no attribute 'document'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "env3/bin/rinoh", line 5, in <module>
    main()
  File "env3/lib/python3.5/site-packages/rinoh/tool.py", line 44, in main
    document.render(input_root)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 360, in render
    section_num_pages = self.render_pages(_sections)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 386, in render_pages
    section_page_count = section.render(sum(section_page_counts))
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 235, in render
    part_page_count = part.render(doc_page_count + section_page_count)
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 171, in render
    chains_requiring_new_page = set(chain for chain in page.render())
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 171, in <genexpr>
    chains_requiring_new_page = set(chain for chain in page.render())
  File "env3/lib/python3.5/site-packages/rinoh/document.py", line 117, in render
    for chain in super().render(rerender=index > 0):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 178, in render
    for chain in child.render(rerender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 178, in render
    for chain in child.render(rerender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 278, in render
    last_descender=last_descender):
  File "env3/lib/python3.5/site-packages/rinoh/layout.py", line 557, in render
    self._state.flowable_state)
  File "env3/lib/python3.5/site-packages/rinoh/flowable.py", line 417, in flow
    self._align(align_container, width)
UnboundLocalError: local variable 'width' referenced before assignment

A document without a table of contents or without a chapter crashes to build

The minimal working document is:

.. contents:: Table of Contents

Structural Elements
===================

If I remove any line from here I will get the following traceback:

Traceback (most recent call last):
  File "/tmp/env/bin/rinoh", line 5, in <module>
    main()
  File "/tmp/env/lib/python3.5/site-packages/rinoh/tool.py", line 43, in main
    document.render(input_base)
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 313, in render
    section_num_pages = self.render_pages()
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 333, in render_pages
    section_page_count = section.render(sum(section_page_counts))
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 206, in render
    part_page_count = part.render(doc_page_count + section_page_count)
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 152, in render
    chains_requiring_new_page = set(chain for chain in page.render())
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 152, in <genexpr>
    chains_requiring_new_page = set(chain for chain in page.render())
  File "/tmp/env/lib/python3.5/site-packages/rinoh/document.py", line 109, in render
    for chain in super().render(rerender=index > 0):
  File "/tmp/env/lib/python3.5/site-packages/rinoh/layout.py", line 221, in render
    for chain in child.render(rerender):
  File "/tmp/env/lib/python3.5/site-packages/rinoh/layout.py", line 225, in render
    height, last_descender = flowable.flow(self, last_descender)
  File "/tmp/env/lib/python3.5/site-packages/rinoh/flowable.py", line 123, in flow
    state=state, **kwargs)
  File "/tmp/env/lib/python3.5/site-packages/rinoh/paragraph.py", line 293, in render
    word = state.next_word()
  File "/tmp/env/lib/python3.5/site-packages/rinoh/paragraph.py", line 238, in next_word
    word = next(self._words)
  File "/tmp/env/lib/python3.5/site-packages/rinoh/paragraph.py", line 200, in spans_to_words
    for chars in span.split(container):
  File "/tmp/env/lib/python3.5/site-packages/rinoh/reference.py", line 241, in split
    if section else None) or ''
  File "/tmp/env/lib/python3.5/site-packages/rinoh/reference.py", line 42, in get_id
    return self.id or document.ids_by_element[self]
AttributeError: 'TableOfContentsSection' object has no attribute 'ids_by_element'

Discover fonts installed on the system

Scan the OS-specific font paths for fonts and make them available for use in rinohtype. This might require caching as each font needs to be parsed to find out its name.

Extend the rinoh command line tool's options

Allow for:

  • selecting a style sheet (by name or by path)
  • choosing a document template
  • setting template options
  • automatic detection of the input format (each frontend should provide a function to test a file)
  • ...

Python 3.5 is not supported

When I run RinohType on Python 3.5 (I haven't tried 3.4 or earlier versions), I get the traceback:

  File "/tmp/env/lib/python3.5/site-packages/rinoh/backend/pdf/cos.py", line 75, in <module>
    class Null(Object, NoneType):
TypeError: type 'NoneType' is not an acceptable base type

Add support for Markdown files to rinoh

rinoh should be able to render CommonMark files besides reStructuredText files.

  • autodetection based on file extension
  • each frontend should provide a list of extensions to help with this
  • option to manually specify the input file format

We could even detect the input file format by simply parsing the input by each parser and see if it errors...

Support hyperlinked images

reStructuredText allows for images to link to a target:

.. image:: images/biohazard.png
   :target: http://www.python.org

Rinohtype does not yet create the hyperlink in the PDF.

Handle images more like the LaTeX Sphinx builder?

Some of the images in the Lizmap documentation are displayed much larger than in the LaTeX-generated PDF.

Notes:

  • this is perhaps only the case for images that do not have a DPI set
  • LaTeX's \includegraphics or Sphinx's \sphinxincludegraphics may always scale down the image if it doesn't fit the available width
  • setting an .. image:'s :scale: 80% seems to scale the image to 80% of the text width (not 80% of the image's original size)

While it is convenient to have the images fit the available width if they are too wide, it is probably not a good idea to scale relative to the text width. If supported by Sphinx/docutils, the user should set :width: 80%.

Investigate whether memory usage can be reduced

Rendering the Sphinx documentation takes about 2GB of memory.

Top 10 lines
#1: pdf/__init__.py:143: 400.0 MiB
    parent_canvas.write(self.getvalue())
#2: rinoh/util.py:115: 189.0 MiB
    cache[args_kwargs] = cache_value
#3: rinoh/dimension.py:156: 88.0 MiB
    self.addends = list(addends)
#4: rinoh/layout.py:218: 58.6 MiB
    self._self_cursor = Dimension(0)  # initialized at container's top edge
#5: pdf/__init__.py:136: 58.2 MiB
    self.fonts = {}
#6: rinoh/style.py:290: 54.2 MiB
    if not hasattr(styled, attr) or getattr(styled, attr) != value:
#7: rinoh/style.py:317: 48.1 MiB
    return type(self)(*(child_selector for selector in self.selectors
#8: pdf/__init__.py:137: 47.5 MiB
    self.images = {}
#9: packaging/version.py:353: 41.2 MiB
    reversed(release),
#10: pdf/__init__.py:344: 35.9 MiB
    self.annotation = annotation
11976 other: 819.5 MiB
Total allocated size: 1840.2 MiB

See:

Allow generating a INI style sheet

The generated style sheet should list all styles defined in the matcher and show all the style's attributes along with their default values, but commented out. This provides a good starting point for writing a style sheet from scratch.

Similarly, it would be useful to do the same starting from an existing stylesheet, adding undefined styles and the (commented out) values for unset style attributes.

AttributeError: No such document option: page_size

rinohtype raised an AttributeError when I did rinoh demo.txt.
demo.txt comes from tutorial texts.

Traceback (most recent call last):
  File "/Users/taku/dev/src/github.com/brechtm/rinohtype/venv/bin/rinoh", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/Users/taku/dev/src/github.com/brechtm/rinohtype/bin/rinoh", line 5, in <module>
    main()
  File "/Users/taku/dev/src/github.com/brechtm/rinohtype/rinoh/tool.py", line 89, in main
    options = ArticleOptions(page_size=page_size)
  File "/Users/taku/dev/src/github.com/brechtm/rinohtype/rinoh/template.py", line 248, in __init__
    raise AttributeError('No such document option: {}'.format(name))
AttributeError: No such document option: page_size

Run tests on AppVeyor

The appveyor branch already includes a basic configuration. What needs to be done:

  • diffpdf.shneeds to be converted to a Python script to allow running on Windows (and this would make it easier to maintain)
  • ImageMagick's convert and Poppler's pdftoppm and pdfinfo need to be installed
  • have each build matrix entry build only the relevant Tox environment

The AppVeyor web hook needs to be enabled in GitHub's Settings > Webhooks & services.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.