diff --git a/README.rst b/README.rst index 4ad812f..6b2dd31 100644 --- a/README.rst +++ b/README.rst @@ -1,82 +1,15 @@ Planète Casio's textout() BBcode markup language translator =========================================================== +For more information, read the documentation accessible on +`the official website`_. + .. warning:: If you are accessing this repository from _, keep in mind that it is only a mirror and that the real repository is located at _ for now. -BBcode has been invented in the 90s/2000s for bulletin board systems. -It has been implemented in `Planète Casio`_ during its first years (although -some research has to be made on how that choice was done…). - -On `Planète Casio`_, which is coded in PHP at the time I'm writing this, -we have our own custom version of BBcode, which we pass through an internal -utility named ``textout()``. - -I, Thomas “Cakeisalie5” Touhey, rewrote it recently, and it works pretty well -while being secure, but as the next version of `Planète Casio`_ (the ”v5”) -will be written from scratch, I figured out I could rewrite the ``textout()`` -utility in Python, and improve the language parsing to be more practical and -add features that are in the original BBcode markup language. - -As this is a rewrite, the vulnerabilities and bug will not be common to this -project and the online version of the transcoder. - ------ -Usage ------ - -To use this module, simply use the ``to()`` functions once imported: - -.. code-block:: python - - #!/usr/bin/env python3 - import textoutpc - - text = "Hello, [i]beautiful [b]world[/i]!" - print(textoutpc.tohtml(text)) - print("---") - print(textoutpc.tolightscript(text)) - -The supported output types are: - -- ``html``: `HTML`_ compatible output, requiring some additional style and - script; -- ``lightscript``: `Lightscript`_ Markdown-like language. See - `the Lightscript topic on Planète Casio `_ for - more information. - ------- -Tweaks ------- - -The ``tohtml()`` and ``tolightscript()`` can take additional keywords that -tags can read so that they can adapt their behaviour. The name of the tweaks -are case-insensitive and non-alphanumeric characters are ignored: for example, -``label_prefix``, ``LABELPREFIX`` and ``__LaBeL___PRE_FIX__`` are all -equivalent. - -The following tweaks are read by the translator and built-in tags: - -- ``label_prefix`` (HTML): prefix to be used by the ``[label]`` and - ``[target]`` tags, e.g. ``msg45529-``. Defaults to `""` for PCv42 - compatibility; -- ``obsolete_tags`` (HTML): use obsolete HTML tags for old browsers - (e.g. lynx) compatibility, e.g. ````, ````, ``
``, and - others. Defaults to ``True``. - -An example call would be: - -.. code-block:: python - - #!/usr/bin/env python3 - import textoutpc - - print(textoutpc.tohtml("Hello, [i]beautiful[/i]!", obsolete__TAGS=False)) - ------------------- What is left to do ------------------ @@ -94,8 +27,6 @@ What is left to do - Implement the ``inline`` tweak in order not to read blocks in the translator. - Look for security flaws (we really don't want stored XSS flaws!). +- Manage keywords with tags such as ``[tag key=value other="something else"]``. -.. _Planète Casio: https://www.planet-casio.com/Fr/ -.. _HTML: https://www.w3.org/html/ -.. _Lightscript: https://git.planet-casio.com/lephe/lightscript -.. _Lightscript topic: https://planet-casio.com/Fr/forums/lecture_sujet.php?id=15022 +.. _the official website:: https://textout.touhey.fr/docs/ diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..f459b9e --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = textoutpc +SOURCEDIR = source +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) \ No newline at end of file diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000..b7d7b4f --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build +set SPHINXPROJ=textoutpc + +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% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 0000000..290f6a9 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,159 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- 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 = 'textoutpc' +copyright = '2018, Thomas Touhey' +author = 'Thomas Touhey' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# 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.viewcode', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# 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 = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + + +# -- 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' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# 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'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'textoutpcdoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'textoutpc.tex', 'textoutpc Documentation', + 'Thomas Touhey', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'textoutpc', 'textoutpc Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'textoutpc', 'textoutpc Documentation', + author, 'textoutpc', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Extension configuration ------------------------------------------------- \ No newline at end of file diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..0c48c57 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,29 @@ +textoutpc, a BBcode markup language translator for Planète Casio +================================================================ + +BBcode has been invented in the 90s/2000s for bulletin board systems. +It has been implemented in `Planète Casio`_ during its first years (although +some research has to be made on how that choice was done…). + +On `Planète Casio`_, which is coded in PHP at the time I'm writing this, +we have our own custom version of BBcode, which we pass through an internal +utility named ``textout()``. + +I, Thomas “Cakeisalie5” Touhey, rewrote it recently, and it works pretty well +while being secure, but as the next version of `Planète Casio`_ (the ”v5”) +will be written from scratch, I figured out I could rewrite the ``textout()`` +utility in Python, and improve the language parsing to be more practical and +add features that are in the original BBcode markup language. + +As this is a rewrite, the vulnerabilities and bug will not be common to this +project and the online version of the transcoder. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + language + usage + tags + +.. _Planète Casio: https://www.planet-casio.com/Fr/ diff --git a/GUIDE.rst b/doc/source/language.rst similarity index 98% rename from GUIDE.rst rename to doc/source/language.rst index e46040b..6df0554 100644 --- a/GUIDE.rst +++ b/doc/source/language.rst @@ -1,4 +1,4 @@ -User's guide to the textout BBcode +The textout BBcode markup language ================================== The BBcode markup language mainly uses tags, which the starting mark looks @@ -109,6 +109,7 @@ Here are some examples: .. code:: [blue]I'm blue![/] + [color=#ff69b4]That color is called “Cuisse de Nymphe émue”![/] [color=rgb(255, 255,255,0.4)]I'm black![/] [color=hsl(0,100%, 0.5)]I'm red![/] diff --git a/TAGS.rst b/doc/source/tags.rst similarity index 97% rename from TAGS.rst rename to doc/source/tags.rst index 84c2e3c..dd13970 100644 --- a/TAGS.rst +++ b/doc/source/tags.rst @@ -1,5 +1,5 @@ -Adding a tag in the Python port of Planète Casio's textout -========================================================== +Defining tags for textoutpc +=========================== A tag is a class defined in the ``textoutpc.Tags`` submodule and referenced in the `_tags` array in ``textoutpc.Tags.__init__``. It usually takes a name diff --git a/doc/source/usage.rst b/doc/source/usage.rst new file mode 100644 index 0000000..957e94c --- /dev/null +++ b/doc/source/usage.rst @@ -0,0 +1,50 @@ +Using textoutpc +=============== + +To use this module, simply use the ``to()`` functions once imported: + +.. code-block:: python + + #!/usr/bin/env python3 + import textoutpc + + text = "Hello, [i]beautiful [b]world[/i]!" + print(textoutpc.tohtml(text)) + print("---") + print(textoutpc.tolightscript(text)) + +The supported output types are: + +- ``html``: `HTML`_ compatible output, requiring some additional style and + script; +- ``lightscript``: `Lightscript`_ Markdown-like language. See + `the Lightscript topic on Planète Casio `_ for + more information. + +The ``tohtml()`` and ``tolightscript()`` can take additional keywords that +tags can read so that they can adapt their behaviour. The name of the tweaks +are case-insensitive and non-alphanumeric characters are ignored: for example, +``label_prefix``, ``LABELPREFIX`` and ``__LaBeL___PRE_FIX__`` are all +equivalent. + +The following tweaks are read by the translator and built-in tags: + +- ``label_prefix`` (HTML): prefix to be used by the ``[label]`` and + ``[target]`` tags, e.g. ``msg45529-``. Defaults to `""` for PCv42 + compatibility; +- ``obsolete_tags`` (HTML): use obsolete HTML tags for old browsers + (e.g. lynx) compatibility, e.g. ````, ````, ``
``, and + others. Defaults to ``True``. + +An example call would be: + +.. code-block:: python + + #!/usr/bin/env python3 + import textoutpc + + print(textoutpc.tohtml("Hello, [i]beautiful[/i]!", obsolete__TAGS=False)) + +.. _HTML: https://www.w3.org/html/ +.. _Lightscript: https://git.planet-casio.com/lephe/lightscript +.. _Lightscript topic: https://planet-casio.com/Fr/forums/lecture_sujet.php?id=15022 diff --git a/textoutpc/builtin_tags/Rot.py b/textoutpc/builtin_tags/Rot.py index 7c2090b..ed9ff31 100755 --- a/textoutpc/builtin_tags/Rot.py +++ b/textoutpc/builtin_tags/Rot.py @@ -15,7 +15,7 @@ class TextoutRotTag(_TextoutInlineTag): Example uses: [rot=13]obawbhe[/rot] - [rot13]obawbhe[/rot13] + [rot13]Obawbhe[/rot13] """ aliases = ('[rot]', '[rot13]')