summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/Makefile20
-rw-r--r--doc/conf.py63
-rw-r--r--doc/document.rst5
-rw-r--r--doc/formats.rst5
-rw-r--r--doc/index.rst84
-rw-r--r--doc/make.bat35
-rw-r--r--doc/templates.rst5
7 files changed, 217 insertions, 0 deletions
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..d4bb2cb
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS ?=
+SPHINXBUILD ?= sphinx-build
+SOURCEDIR = .
+BUILDDIR = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/doc/conf.py b/doc/conf.py
new file mode 100644
index 0000000..327cc49
--- /dev/null
+++ b/doc/conf.py
@@ -0,0 +1,63 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'Wikimini'
+copyright = '2021, Daniel Schadt'
+author = 'Daniel Schadt'
+
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ "sphinx.ext.autodoc",
+ "sphinx.ext.napoleon",
+ "sphinx_autodoc_typehints",
+ "sphinx.ext.intersphinx",
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# -- Intersphinx mappings ----------------------------------------------------
+intersphinx_mapping = {
+ 'mwparserfromhell': ('https://mwparserfromhell.readthedocs.io/en/latest/',
+ None),
+ 'stdlib': ('https://docs.python.org/3', None),
+}
diff --git a/doc/document.rst b/doc/document.rst
new file mode 100644
index 0000000..9acbb93
--- /dev/null
+++ b/doc/document.rst
@@ -0,0 +1,5 @@
+The Document representation
+===========================
+
+.. automodule:: wikimini.document
+ :members:
diff --git a/doc/formats.rst b/doc/formats.rst
new file mode 100644
index 0000000..ddf01be
--- /dev/null
+++ b/doc/formats.rst
@@ -0,0 +1,5 @@
+Output Formats
+==============
+
+.. automodule:: wikimini.formats
+ :members:
diff --git a/doc/index.rst b/doc/index.rst
new file mode 100644
index 0000000..9eaecfc
--- /dev/null
+++ b/doc/index.rst
@@ -0,0 +1,84 @@
+.. Wikimini documentation master file, created by
+ sphinx-quickstart on Tue Aug 17 00:07:39 2021.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+Welcome to Wikimini's documentation!
+====================================
+
+.. toctree::
+ :maxdepth: 2
+ :caption: Contents:
+
+ document
+ templates
+ formats
+
+Wikimini is a library that takes Wikimedia Markup and renders it into a text
+format, such as `Gemtext
+<https://gemini.circumlunar.space/docs/gemtext.gmi>`__::
+
+ from wikimini import Wikimini
+ from wikimini.formats.gemtext import Gemtext
+ import sys
+
+ # The English Wikipedia is the default source.
+ wiki = Wikimini()
+ _, markup = wiki.retrieve("Coffee")
+ document = wiki.convert_to_document(markup)
+ Gemtext(sys.stdout).render(document)
+
+The reason why Wikimini is "better" than simply stripping all markup (such as
+:meth:`mwparserfromhell.wikicode.Wikicode.strip_code` does) is that you can
+keep a lot more information: Some interesting bits are implemented as templates
+in Wikipedia (markup like ``{{lang|ar|قَهْوَة}}``), and leaving them out either
+means missing out on the provided information, or having nonsensical
+punctuation in your output.
+
+The Wikimini pipeline is made to work in three steps:
+
+#. We start with the parsed :class:`~mwparserfromhell.wikicode.Wikicode`, which
+ is a parsed representation of Wikipedia's markup language
+#. Then convert the :class:`~mwparserfromhell.wikicode.Wikicode` to our
+ internal representation, the :class:`~wikimini.document.Document`. This step
+ already executes the templates and provides a stripped-down markup that only
+ keeps the essential meta information (like heading).
+#. Lastly, we convert our :class:`~wikimini.document.Document` to our desired
+ format with the help of a :class:`~wikimini.formats.Format`.
+
+Extensibility
+-------------
+
+Wikimini is extensible in multiple ways:
+
+The easiest extension is to make Wikimini work for different Mediawiki
+instances. This can be done by passing the correct API URL to the constructor
+of :class:`~wikimini.Wikimini`.
+
+You can also extend Wikimini by teaching it about more templates, for that, see
+:doc:`templates`.
+
+Additionally, you can implement other output formats, see :doc:`formats` for
+that.
+
+Reference
+---------
+
+Most of the interaction with Wikimini is done through the
+:class:`wikimini.Wikimini` object:
+
+.. autoclass:: wikimini.Wikimini
+ :members:
+
+Additionally, the module defines some constants:
+
+.. autodata:: wikimini.API_URL
+
+.. autodata:: wikimini.TABLE_FORMAT
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/doc/make.bat b/doc/make.bat
new file mode 100644
index 0000000..2119f51
--- /dev/null
+++ b/doc/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=_build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/doc/templates.rst b/doc/templates.rst
new file mode 100644
index 0000000..b0b36fb
--- /dev/null
+++ b/doc/templates.rst
@@ -0,0 +1,5 @@
+Templates
+=========
+
+.. automodule:: wikimini.templates
+ :members: