• Home
  • API Documentation
  • wte.text_formatter.docutils_ext

wte.text_formatter.docutils_ext¶

This module contains docutils extensions (roles and directives) that provide the additional formatting support required by the compile_rst() function.

class wte.text_formatter.docutils_ext.HtmlElementBlock(rawsource, *children, *, html_element=None, html_attributes=None, **kwargs)[source]¶

The HtmlElementBlock is a docutils node for generating arbitrary HTML elements.

The HTML element to generate can be configured by setting html_element on the node. HTML attributes can be configured by setting the html_attributes property on the node, which must be set to a dict.

class wte.text_formatter.docutils_ext.Pygments(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

The Pygments reStructuredText directive

This fragment is a Docutils 0.5 directive that renders source code (to HTML only, currently) via Pygments.

To use it, adjust the options below and copy the code into a module that you import on initialization. The code then automatically registers a sourcecode directive that you can use instead of normal code blocks like this:

.. sourcecode:: python

    My code goes here.

If you want to have different code styles, e.g. one with line numbers and one without, add formatters with their names in the VARIANTS dict below. You can invoke them instead of the DEFAULT one by using a directive option:

.. sourcecode:: python
    :linenos:

    My code goes here.

Look at the directive documentation to get all the gory details.

Copyright:Copyright 2006-2014 by the Pygments team, see AUTHORS.
License:BSD, see LICENSE for details.
class wte.text_formatter.docutils_ext.Quiz(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

The Quiz is a directive to generate the outer wrapper for an in-part quiz. It takes a single required parameter that is the identifier for the quiz in the current Part. An optional title parameter is the title of the quiz to show to the user. The actual questions need to be provided via QuizAnswer:

.. quiz: quiz_identifier
   :title: This is a Quiz!

   .. quiz-question: question1
      :question: Is this right?

      [x] Answer 1
      Answer 2
      Answer 3
class wte.text_formatter.docutils_ext.QuizQuestion(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

The QuizQuestion generates a single question output. It takes a single required parameter that is the identifier for the question. An optional question parameter can be used to give the question’s title. An optional type parameter can be used to specify whether single (“single-choice”) or multiple choices (“multi-choice”) are available:

.. quiz-question:: question_id
   :question: Is this right?
   :type: single-choice

   [x]Answer 1
   [x]Answer 2
   Answer 3

Each line of content represents one answer. The correct answers must be pre-fixed with “[x]”.

class wte.text_formatter.docutils_ext.ShowHideBlock(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

The docutils_ext generates a block with arbitrary content that the user can show and hide. Two optional parameters are available. initial can either be set to “hidden” or “visible” (the default) to set the initial visiblity of the block. title can be used to add a title to the block.

class wte.text_formatter.docutils_ext.YouTube(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶

The YouTube directive enables support for embeddeding YouTube videos in ReST. It takes a single parameter that is the YouTube URL to embed:

.. youtube:: https://URL/TO/VIDEO

The URL must either be the share or embed URLs.

wte.text_formatter.docutils_ext.asset_ref_role(name, rawtext, text, lineno, inliner, options={}, content=[])[source]¶

The asset_ref_role() function provides a docutils role that handles linking in Asset into the text. If the Asset is an image, then the image is loaded inline, otherwise a download link for all other types of Asset is created.

wte.text_formatter.docutils_ext.crossref_role(name, rawtext, text, lineno, inliner, options={}, content=[])[source]¶

The crossref_role() function implements an additional docutils role that handles cross-references between Parts.

Usage in ReST is :crossref:`part_id` or :crossref:`link text <part_id>`.

wte.text_formatter.docutils_ext.depart_htmlelementblock(self, node)[source]¶

Visitor exit for the HtmlElementBlock.

wte.text_formatter.docutils_ext.flag_bool_option(value)[source]¶

Options conversion function for ReST Directive that returns True if the value is set and has any value except “false”.

wte.text_formatter.docutils_ext.init(settings)[source]¶

Initialise and load the docutils extensions.

wte.text_formatter.docutils_ext.inline_css_role(name, rawtext, text, lineno, inliner, options={}, content=[])[source]¶

The inline_css_role() function provides a docutils role that allows for the specification of arbitrary CSS that is then assigned to a <span> element.

wte.text_formatter.docutils_ext.inline_pygments_role(name, rawtext, text, lineno, inliner, options={}, content=[])[source]¶

The inline_pygments_role() function provides a docutils role that handles inline code highlighting using Pygments. The name of the language to use for highlighting is taken from the name of the role (which must be formatted code-language_name).

wte.text_formatter.docutils_ext.visit_htmlelementblock(self, node)[source]¶

Visitor for the HtmlElementBlock to generate the actual HTML output.

  • wte.text_formatter
  • wte.util – Utility functions