Commit 259ba226 authored by Tobias ferrari's avatar Tobias ferrari

Added checkboxes to rst2html.

At the moment no difference between checked and unchecked boxes
parent 5d4cc233
......@@ -3,7 +3,8 @@ from .embedded_image_directive import EmbeddedImage, EmbeddedFigure
from .jupyter_outbox_directive import JupyterOutbox
from .tikz_directive import Tikz, TikzFigure
from .output_mode import get_output_mode, set_output_mode
from .rst_checkboxes_directive import RSTCheckBox
__all__ = ("CodeBlock", "EmbeddedImage", "EmbeddedFigure", "JupyterOutbox", "Tikz", "TikzFigure", "get_output_mode",
"set_output_mode")
"set_output_mode", "RSTCheckBox")
from docutils import nodes
from docutils.parsers.rst import Directive
class RSTCheckBox(Directive):
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
has_content = True
def run(self):
content = u"\n".join(self.content)
lines = content.split("\n")
html = "<ul>"
for line in lines:
if "- [ ]" in line:
html += "<li>" + line[6:] + "</li>"
elif "- [x]" in line:
html += "<li>" + line[6:] + "</li>"
html += "</ul>"
return [nodes.raw("", html, format="html")]
......@@ -19,7 +19,7 @@ except:
from docutils.core import publish_cmdline, default_description
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.body import ParsedLiteral
from ..directives import EmbeddedImage, EmbeddedFigure, Tikz, TikzFigure, set_output_mode
from ..directives import EmbeddedImage, EmbeddedFigure, Tikz, TikzFigure, set_output_mode, RSTCheckBox
description = "Generates (X)HTML documents from standalone reStructuredText " "sources. " + default_description
......@@ -32,6 +32,7 @@ def main():
directives.register_directive("jupyter-outbox", ParsedLiteral)
directives.register_directive("tikz", Tikz)
directives.register_directive("tikz-figure", TikzFigure)
directives.register_directive("checkboxes", RSTCheckBox);
publish_cmdline(writer_name="html", description=description)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment