Package: rst2html5
rst2html5generates (X)HTML5 documents from standalone reStructuredText sources.
It is a complete rewrite of the docutils’rst2htmland uses new HTML5 constructs such as<section>and<aside>.Installation$pipinstallrst2html5Usage$rst2html5[options]SOURCE[DEST]Options:--no-indentDon’t indent output--stylesheet=<URL or path>Specify a stylesheet URL to be included.
(This option can be used multiple times)--stylesheet-inline=<path>Specify a stylesheet file whose contents will be
included into the output HTML file. (This option can
be used multiple times)--script=<URL or path>Specify a script URL to be included.
(This option can be used multiple times)--script-defer=<URL or path>Specify a script URL with a defer attribute
to be included in the output HTML file.
(This option can be used multiple times)--script-async=<URL or path>Specify a script URL with a async attribute
to be included in the output HTML file.
(This option can be used multiple times)--html-tag-attr=<attribute>Specify a html tag attribute.
(This option can be used multiple times)--template=<filename or text>Specify a filename or text to be used as the HTML5
output template. The template must have the {head} and
{body} placeholders. The “<html{html_attr}>”
placeholder is recommended.--define=<identifier>Define a case insensitive identifier to be used with
ifdef and ifndef directives. There is no value
associated with an identifier. (This option can be
used multiple times)IfDESTis not provided, the output is send tostdout.ExampleConsider a file calledexample.rstthat contains:Title=====Some text and a target to`Title 2`_.**strong emphasis**:*item 1*item 2Title 2=======..parsed-literal::Inline markup is supported, e.g.*emphasis*,**strong**,``literal
    text``,_`hyperlink targets`, and `references<http://www.python.org/>`_The command to produce anexample.htmloutput file is:$ rst2html5 example.rst example.htmlThe HTML5 produced is clean and tidy:<!DOCTYPE html><html><head><metacharset="utf-8"/></head><body><sectionid="title"><h1>Title</h1><p>Some text and a target to<ahref="#title-2">Title 2</a>.<strong>strong emphasis</strong>:</p><ul><li>item 1</li><li>item 2</li></ul></section><sectionid="title-2"><h1>Title 2</h1><pre>Inline markup is supported, e.g.<em>emphasis</em>,<strong>strong</strong>,<code>literal
text</code>,<aid="hyperlink-targets">hyperlink targets</a>, and<ahref="http://www.python.org/">references</a></pre></section></body></html>Stylesheets and ScriptsNo stylesheets or scripts are spread over the HTML5 by default.
However stylesheets and javascripts URLs or paths can be included throughstylesheetandscriptoptions:$ rst2html5 example.rst \--stylesheethttps://example.com/css/default.css\--stylesheet-inlinecss/simple.css \--scripthttps://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js--script-deferjs/test1.js--script-asyncjs/test2.js<!DOCTYPE html><html><head><metacharset="utf-8"/><linkrel="stylesheet"href="https://example.com/css/default.css"/><style>h1{font-size:20em}img.icon{width:48px;height:48px;}h2{color:red}</style><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><scriptsrc="js/test1.js"defer="defer"></script><scriptsrc="js/test2.js"async="async"></script></head>...HTML tag attributes can be included throughhtml-tag-attroption:$ rst2html5--html-tag-attr'lang="pt-BR"' example.rst<!DOCTYPE html><htmllang="pt-BR">...TemplatesCustom HTML5 template via the--templateoption. Example:$ template='<!DOCTYPE html>
<html{html_attr}>
<head>{head}    <!-- custom links and scripts -->
    <link href="css/default.css" rel="stylesheet" />
    <link href="css/pygments.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>{body}</body>
</html>'

$ echo 'one line' > example.rst

$ rst2html5--template "$template"example.rst<!DOCTYPE html><html><head><metacharset="utf-8"/><!-- custom links and scripts --><linkhref="css/default.css"rel="stylesheet"/><linkhref="css/pygments.css"rel="stylesheet"/><scriptsrc="http://code.jquery.com/jquery-latest.min.js"></script></head><body><p>one line</p></body></html>New Directivesdefine,undef,ifdefandifndefrst2html5provides some new directives:define,undef,ifdefandifndef,
similar to those used in C++.
They allow to conditionally include (or not) some rst snippets:..ifdef::xthis line will be included if 'x' was previously definedIn case of you check two or more identifiers,
there must be an operator ([and | or]) defined:..ifdef::x y z:operator:orThis line will be included only if 'x', 'y' or 'z' is defined.stylesheetandscriptFrom rst2html5 1.9, you can include stylesheets and scripts via directives inside a reStructuredText text:Just an ordinary paragraph...stylesheet::css/default.css..stylesheet::https://pronus.io/css/standard.css..script::http://code.jquery.com/jquery-latest.min.js..script::slide.js:defer:..script::test/animations.js:async:Another paragraph<!DOCTYPE html><html><head><metacharset="utf-8"/><linkhref="css/default.css"rel="stylesheet"/><linkhref="https://pronus.io/css/standard.css"rel="stylesheet"/><scriptsrc="http://code.jquery.com/jquery-latest.min.js"></script><scriptsrc="slide.js"defer="defer"></script><scriptsrc="test/animations.js"async="async"></script></head><body><p>Just an ordinary paragraph.</p><p>Another paragraph</p></body></html>templateThere also is atemplatedirective. The usage is:..template::filenameor..template::template content here.New Roles:abbr:FromMDN Web Docs:The HTML Abbreviation element (<abbr>) represents an abbreviation or acronym;
the optional title attribute can provide an expansion or description for the abbreviation.
If present, title must contain this full description and nothing else.To create an abbreviation inrst2html5use the:abbr:role:*:abbr:`SPA (Single-Page Application)`*:abbr:`ASGI (Asynchronous Server Gateway Interface)`is a spiritual successor to:abbr:`WSGI`*:abbr:`WSGI (Web Server Gateway Interface)`Resulting in:<ul><li><abbrtitle="Single-Page Application">SPA</abbr></li><li><abbrtitle="Asynchronous Server Gateway Interface">ASGI</abbr>is a spiritual successor to<abbr>WSGI</abbr></li><li><abbrtitle="Web Server Gateway Interface">WSGI</abbr></li></ul>Note that if the abbreviation follows the patternABBR (Description for the abbreviation),
the description is extracted and becomes thetitle.How To Use rst2html5 ProgrammaticallyYou should userst2html5.HTML5Writerwith one of thepublish_*` methods available in ``docutils.core.
In the case that the input and output will be in memory,publish_partsis the best fit:fromdocutils.coreimportpublish_partsfromrst2html5importHTML5Writertext=r'''The area of a circle is :math:`A_\text{c}= (\pi/4) d^2`.

.. math::

    \frac{ \sum_{t=0}^{N}f(t,k) }{N}'''override={'html_tag_attr':['lang="pt-BR"'],'stylesheet':['https://example.com/css/default.css'],'script':[('https://blog.pronus.xyz/test.js','async')],}html=publish_parts(writer=HTML5Writer(),source=text,settings_overrides=override)['whole']print(html)Resulting in:<!DOCTYPE html><htmllang="pt-BR"><head><metacharset="utf-8"/><linkrel="stylesheet"href="https://example.com/css/default.css"/><scriptsrc="https://blog.pronus.xyz/test.js"async="async"></script><scriptsrc="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></head><body><p>The area of a circle is<spanclass="math">\(A_\text{c} = (\pi/4) d^2\)</span>.</p><divclass="math">\(\frac{ \sum_{t=0}^{N}f(t,k) }{N}\)</div></body></html>Attention!Version 2.0 renames the modulerst2html5_back torst2html5since the conflict with docutils installation is solved.
Importingrst2html5_.HTML5Writerstill works though.
See the section “Workaround to Conflicts with Docutils”
ondocs/design_notes.rstfor more information.See also:The Docutils PublisherLinksDocumentationProject page at Heptapod