From bae09cabba18d064c57beb41503d52a771735baf Mon Sep 17 00:00:00 2001 From: gryf Date: Tue, 5 Jul 2022 21:47:19 +0200 Subject: [PATCH] Added simple executable for rendering rst files. --- Dockerfile | 4 ++++ README.rst | 42 ++++++++++++++++++++++++++++++++++++++++++ rst2htmlbody.py | 25 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Dockerfile create mode 100644 README.rst create mode 100755 rst2htmlbody.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..291d6e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM gitea/gitea:latest +COPY ./rst2htmlbody.py /bin/rst2htmlbody +RUN apk --no-cache add py3-docutils && \ + chmod 755 /bin/rst2htmlbody diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..17dcc7f --- /dev/null +++ b/README.rst @@ -0,0 +1,42 @@ +Restructured text renderer for Gitea +==================================== + +This is simple custom rst2html5 renderer for `Gitea`_. + +Installation +------------ + +Before starting deployment of Gitea using docker or docker-compose, you'll +need to create an altered image which would contain `docutils`_ python package. +There is a simple Dockerfile attached, which can be adjusted to your needs +(i.e. it might be needed to pin to stable version of gitea), than let's assume, +that we tag the image with ``:rst``: + +.. code:: shell + + $ docker build -t gitea:rst -f Dockerfile . + +Procedure of running dockerized deployment is `same as documented`_. + +Now, as you have it up and running, there is still a need for altering +configuration. Stop the container, and alter file +``path-to/gitea/conf/app.ini``, and add external renderer section: + +.. code:: ini + + [markup.restructuredtext] + ENABLED = true + FILE_EXTENSIONS = .rst + RENDER_COMMAND = "rst2htmlbody" + IS_INPUT_FILE = false + + +And that's it! + +Unfortunately, you'll need to repeat those steps every time you'd like to +update gitea. + + +.. _docutils: https://docutils.sourceforge.io +.. _gitea: https://gitea.io +.. _same as documented: https://docs.gitea.io/en-us/install-with-docker/ diff --git a/rst2htmlbody.py b/rst2htmlbody.py new file mode 100755 index 0000000..426fa41 --- /dev/null +++ b/rst2htmlbody.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import sys + +from docutils import core +from docutils.writers import html5_polyglot + + +def main(): + if not sys.stdin.isatty(): + text = sys.stdin.readlines() + else: + if len(sys.argv) != 2: + print("There is no piped reSt source nor provided file, abort.") + sys.exit(4) + with open(sys.argv[1]) as fobj: + text = fobj.read() + + parts = core.publish_parts(writer=html5_polyglot.Writer(), + source=''.join(text)) + + print(parts.get('body', '')) + + +if __name__ == '__main__': + main()