Copyright notices, and save before trying to use a graphical debugger.
This commit is contained in:
parent
3906c0ff3c
commit
c837bcf69b
3
GUIDE.md
3
GUIDE.md
|
@ -1,7 +1,4 @@
|
|||
# User's guide to the textout BBcode
|
||||
<TODO: insert a piece of history about how BBcode has been invented and how
|
||||
it has been adopted and implemented in Planète Casio to this day>
|
||||
|
||||
The BBcode markup language mainly uses tags, which the starting mark looks
|
||||
like `[xxx]` and the ending mark looks like `[/xxx]`. You can add an attribute
|
||||
to the starting mark to modify the tag's behaviour.
|
||||
|
|
10
README.md
10
README.md
|
@ -1,4 +1,14 @@
|
|||
# Planète Casio's textout() BBcode markup language translator
|
||||
**If you are accessing this repository from <https://git.planet-casio.com/>,**
|
||||
**keep in mind that it is only a mirror and that the real repository**
|
||||
**is located at <https://forge.touhey.fr/pc/textout.git> 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
|
||||
|
||||
<TODO: insert a piece of history about how BBcode has been invented and how
|
||||
it has been adopted and implemented in Planète Casio to this day>
|
||||
|
||||
On [Planète Casio][pc], 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()`.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" textout to HTML converter for the command line. """
|
||||
|
||||
import sys, argparse
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" textout to lightscript converter for the command line. """
|
||||
|
||||
import sys, argparse
|
||||
|
|
4
setup.py
4
setup.py
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the fingerd Python 3.x module, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Setup script for the textoutpc Python package and script. """
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Unit tests for the `textoutpc` Python module. """
|
||||
|
||||
# This file is only there to indicate that the folder is a module.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Unit tests for the Python version of textout.
|
||||
Uses the builtin `unittest` module.
|
||||
"""
|
||||
|
@ -33,6 +37,7 @@ __test_cases = {
|
|||
'[u][b]a[/]mdr': '<p><u><b>a</b>mdr</u></p>',
|
||||
|
||||
# Blocks, alignment.
|
||||
'[left]': '',
|
||||
'[left]lol[/]hi': '<p class="align-left">lol</p><p>hi</p>',
|
||||
'a[justify]b': '<p>a</p><p class="align-justify">b</p>',
|
||||
'a[i][justify]b': '<p>a</p><p class="align-justify"><i>b</i></p>',
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Unit tests for the Python version of textout, lightscript-related funcs.
|
||||
Uses the builtin `unittest` module.
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Functions for the user.
|
||||
Really simplifies the thing.
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" HTML/CSS-like color parsing, mainly for the `[color]` tag.
|
||||
Defines the `get_color()` function which returns an rgba value.
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Named colors definitions. Color names are case-insensitive.
|
||||
Taken from: https://www.w3schools.com/cssref/css_colors.asp """
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" HTML/CSS like color parsing, mainly for the `[color]` tag.
|
||||
Defines the `get_color()` function which returns an rgba value.
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Conversions between color systems. """
|
||||
|
||||
from colorsys import hls_to_rgb
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
""" Final functions the user will be able to use.
|
||||
Defined in another file so that the user can't access the internals
|
||||
easily (as it is highly unrecommended).
|
||||
"""
|
||||
|
||||
import io as _io
|
||||
from .translate import Translator as _Translator
|
||||
|
||||
__all__ = ["tohtml", "tolightscript"]
|
||||
|
||||
def tohtml(message, **tweaks):
|
||||
""" Converts textout BBcode to HTML.
|
||||
Receives a string, returns a string. """
|
||||
|
||||
return _Translator(_io.StringIO(message), _io.StringIO(), 'html', tweaks) \
|
||||
.process().getvalue()
|
||||
|
||||
def tolightscript(message, **tweaks):
|
||||
""" Converts textout BBcode to Lightscript.
|
||||
Receives a string, returns a string. """
|
||||
|
||||
return "" # TODO: real thing one day
|
||||
|
||||
return _Translator(_io.StringIO(message), _io.StringIO(), 'lightscript', \
|
||||
tweaks).process().getvalue()
|
||||
|
||||
# End of file.
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Smiley conversion.
|
||||
Just convert them™.
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Layer on top of the character stream.
|
||||
|
||||
See the `TextoutStream` class description for more information.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Tag helpers for the translate utilities.
|
||||
As we ought to be able to make separate tag modules, this module
|
||||
does not hardcode the imports and makes it possible to import any
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Base class for textout tags. For your class to be used as a textout tag,
|
||||
you have to make it inherit one of these (usually `TextoutBlockTag`
|
||||
or `TextoutInlineTag`). """
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
|
||||
|
@ -13,6 +17,7 @@ class TextoutAlignTag(TextoutBlockTag):
|
|||
"""
|
||||
|
||||
aliases = ('[align]', '[center]', '[left]', '[right]', '[justify]')
|
||||
notempty = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
align = None
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from urllib.parse import urlparse
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
import re as _re
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from html import escape as _htmlescape
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from html import escape as _htmlescape
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
import string as _string
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from html import escape as _htmlescape
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from html import escape as _htmlescape
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
from ...color import get_color
|
||||
|
@ -72,7 +76,7 @@ class TextoutTextTag(TextoutInlineTag):
|
|||
self._color = get_color(value)
|
||||
elif name == "font":
|
||||
assert value in _fonts
|
||||
self._font = value
|
||||
self._font = _fonts[value]
|
||||
elif name in ('size', 'big', 'small'):
|
||||
if name != 'size':
|
||||
value = name
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
|
||||
from ..base import *
|
||||
import re as _re
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Built-in tags for the `textoutpc` module.
|
||||
Some of these tags will probably have to move to a separate module
|
||||
Planète Casio-specific, but still, here we are.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Main translation function.
|
||||
See the `Translator` class documentation for more information.
|
||||
"""
|
||||
|
@ -66,14 +70,9 @@ class _TagData:
|
|||
else False
|
||||
self.started = False
|
||||
|
||||
# `tag` is the actual tag object returned by `get_tag()`.
|
||||
# XXX: because the tag is going to be called with different contents,
|
||||
# we might as well do deepcopies from a `self.base` each time we
|
||||
# want to start a new instance. But while this is not worked on,
|
||||
# `self.tag` will be enough.
|
||||
# `base` is the actual tag object returned by `get_tag()`.
|
||||
|
||||
self.base = tag
|
||||
self.tag = _deepcopy(tag)
|
||||
|
||||
# Flags and properties calculated from the tag's attributes, using the
|
||||
# rules given in `TAGS.md`.
|
||||
|
@ -106,6 +105,20 @@ class _TagData:
|
|||
|
||||
self.last = "" if hasattr(tag, 'preprocess') else False
|
||||
|
||||
# Reset the tag.
|
||||
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
""" Reset the tag, generally because it has been closed. """
|
||||
|
||||
self.tag = _deepcopy(self.base)
|
||||
self.started = False
|
||||
if isinstance(self.last, bool):
|
||||
self.last = False
|
||||
else:
|
||||
self.last = ""
|
||||
|
||||
def __repr__(self):
|
||||
return '<TagData>'
|
||||
|
||||
|
@ -432,10 +445,12 @@ class Translator:
|
|||
self.put_code(tag.content())
|
||||
elif hasattr(tag, 'default'):
|
||||
# Tag defines a default content if there might be none,
|
||||
# without text preprocessing.
|
||||
# without text preprocessing. If there is no content, print it.
|
||||
# Notice that the default content method can also raise
|
||||
# an exception if the tag in its current configuration should
|
||||
# not have an empty content.
|
||||
|
||||
has_content = dat.last
|
||||
if not has_content:
|
||||
if not dat.last:
|
||||
try:
|
||||
self.put_text(tag.default())
|
||||
except:
|
||||
|
@ -491,7 +506,6 @@ class Translator:
|
|||
# started for methods as `put_code()` that call this method
|
||||
# back not to re-put anything.
|
||||
|
||||
dat.started = True
|
||||
if dat.type == dat.BLOCK:
|
||||
blocks.insert(0, dat)
|
||||
else:
|
||||
|
@ -531,9 +545,9 @@ class Translator:
|
|||
# Then put the tag in the appropriate queue.
|
||||
|
||||
if dat.type == dat.BLOCK:
|
||||
blocks.insert(0, dat)
|
||||
blocks.append(dat)
|
||||
else:
|
||||
inlines.insert(0, dat)
|
||||
inlines.append(dat)
|
||||
|
||||
# Then we want to end the tags, and reset them in case we're going
|
||||
# to use them.
|
||||
|
@ -545,9 +559,7 @@ class Translator:
|
|||
if hasattr(tag, 'end'):
|
||||
self.put_code(tag.end())
|
||||
|
||||
dat.tag = _deepcopy(dat.base)
|
||||
dat.started = False
|
||||
dat.last = False
|
||||
dat.reset()
|
||||
|
||||
# Restore the queue.
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#******************************************************************************
|
||||
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
# This file is part of the textoutpc project, which is MIT-licensed.
|
||||
#******************************************************************************
|
||||
""" Autolinking (URL extraction from raw text) in HTML. """
|
||||
|
||||
import regex as _re
|
||||
|
|
Loading…
Reference in New Issue