diff --git a/docs/tags.rst b/docs/tags.rst
index dd13970..ea3775b 100644
--- a/docs/tags.rst
+++ b/docs/tags.rst
@@ -28,6 +28,7 @@ There are a few public members you can define as a tag:
level, and adds a paragraph tag implicitely.
- ``inlined``: if is a block, transforms automatically the surrounding block
into a superblock while it's there.
+- ``procvalue`` : process the value as normal text before passing it.
So for example, if I want to make the inline tag ``[hello]`` as an example,
with the alternate name ``[hai]``, I'd start off by writing:
diff --git a/textoutpc/__init__.py b/textoutpc/__init__.py
index 4af39c2..cf5dbe5 100755
--- a/textoutpc/__init__.py
+++ b/textoutpc/__init__.py
@@ -7,27 +7,38 @@
Really simplifies the thing.
"""
-import io as _io
-from .translate import Translator as _Translator
+from io import StringIO as _StringIO
-__all__ = ["version", "tohtml", "tolightscript"]
+from ._options import TextoutOptions as Options, \
+ TextoutBlockTag as BlockTag, TextoutInlineTag as InlineTag, \
+ TextoutParagraphTag as ParagraphTag, TextoutSmiley as Smiley
+from ._translate import Translator as _Translator
+
+__all__ = ["version", "tohtml", "tolightscript",
+ "Options", "BlockTag", "ParagraphTag", "InlineTag", "Smiley"]
version = "0.1.1"
-def tohtml(message, **tweaks):
+# ---
+# Public functions.
+# ---
+
+_default_options = Options()
+
+def tohtml(message, options = _default_options, **tweaks):
""" Converts textout BBcode to HTML.
Receives a string, returns a string. """
- return _Translator(_io.StringIO(message), _io.StringIO(), 'html', \
- tweaks).process().getvalue()
+ return _Translator(_StringIO(message), _StringIO(), 'html', \
+ tweaks, options).process().getvalue()
-def tolightscript(message, **tweaks):
+def tolightscript(message, options = _default_options, **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()
+ return _Translator(_StringIO(message), _StringIO(), 'lightscript', \
+ tweaks, options).process().getvalue()
# End of file.
diff --git a/textoutpc/_html.py b/textoutpc/_html.py
new file mode 100644
index 0000000..0472e18
--- /dev/null
+++ b/textoutpc/_html.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
+# This file is part of the textoutpc project, which is MIT-licensed.
+#******************************************************************************
+""" Utilities for HTML conversions. """
+
+import regex as _re
+from html import escape
+
+__all__ = ["escape", "urls", "SmileyConvertor"]
+
+# ---
+# Smileys.
+# ---
+
+class SmileyConvertor:
+ """ Smileys convertor. """
+
+ def __init__(self, smileys = {}):
+ self._html = {escape(a): b.url \
+ for a, b in smileys.items() if b.url != None}
+ self._re = _re.compile('(^|\\s)(' + '|'.join(map(_re.escape,
+ self._html.keys())) + ')(\\s|$)')
+
+ def convert(self, text):
+ def sub_html(m):
+ return m.group(1) + '' + m.group(3)
+
+ # FIXME: this is to avoid the ":):)" case, but there probably
+ # is a cleaner way to fix this…
+
+ text = self._re.sub(sub_html, text)
+ text = self._re.sub(sub_html, text)
+ return text
+
+# ---
+# URLs.
+# ---
+
+_urlreg = _re.compile("""\
+ (?P^|\s|[[:punct:]])
+ (?P(https?|ftp):
+ (?P[^\[\]\(\)\s]* (\[(?&ucore)\]?)* (\((?&ucore)\)?)*)*
+ )
+""", _re.VERBOSE | _re.M)
+
+def urls(text):
+ """ Convert URLs. """
+
+ def _sub_html(m):
+ sp = m.group('sp')
+ url = m.group('url')
+ aft = ''
+
+ # Hack for the last comma.
+ if url[-1] == ',':
+ url, aft = url[:-1], ','
+
+ text = '{}{}{}' \
+ .format(sp, url, url, aft)
+ return text
+
+ return _urlreg.sub(_sub_html, text)
+
+# End of file.
diff --git a/textoutpc/tags.py b/textoutpc/_options.py
similarity index 66%
rename from textoutpc/tags.py
rename to textoutpc/_options.py
index aa37edb..d8ab1ce 100644
--- a/textoutpc/tags.py
+++ b/textoutpc/_options.py
@@ -3,7 +3,8 @@
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-""" Base classes to use with tags in textoutpc, with a manager class.
+""" Base classes to use with options (tags, smileys) in textoutpc, with a
+ manager class.
For your tag to be used as a textoutpc tag, you have to make it
inherit one of the `TextoutBlockTag` or `TextoutInlineTag` classes.
@@ -17,8 +18,11 @@ from inspect import ismodule as _ismod, isclass as _isclass, \
currentframe as _currentframe, getouterframes as _getouterframes
from importlib import import_module as _importmod
-__all__ = ["TextoutTags", "TextoutTag", "TextoutBlockTag", "TextoutInlineTag",
- "TextoutParagraphTag"]
+from ._html import SmileyConvertor as _htmlsm
+
+__all__ = ["TextoutOptions",
+ "TextoutTag", "TextoutBlockTag", "TextoutInlineTag", "TextoutParagraphTag",
+ "TextoutSmiley"]
def _getargscount(func):
try:
@@ -27,10 +31,12 @@ def _getargscount(func):
return len(_getargspec(func).args)
# ---
-# Main base tag class.
-# For more about defining a tag, see `/TAGS.md`.
+# Tags.
# ---
+# Main base tag class.
+# For more about defining a tag, see `doc/tags.md`.
+
class TextoutTag:
""" The textout tag base class.
Is initialized with these values:
@@ -82,6 +88,7 @@ class TextoutTag:
prep(*args)
# Prepare the preprocessing elements.
+
if hasattr(self, 'preprocess'):
if hasattr(self, 'preprocess_' + ot):
self.__preprocess0 = self.preprocess
@@ -98,6 +105,11 @@ class TextoutTag:
if hasattr(self, 'default_' + ot):
self.default = getattr(self, 'default_' + ot)
+ def __repr__(self):
+ return f"{self.__class__.__name__}(name = {repr(self.__name)}, " \
+ f"value = {repr(self.__value)}, " \
+ f"ot = {repr(self.__output_type)})"
+
def __preprocess_double(self, content):
""" Preprocess using the two methods. """
@@ -141,18 +153,14 @@ class TextoutTag:
except KeyError:
return default
-# ---
# Role-specific base tag classes.
-# ---
class TextoutBlockTag(TextoutTag):
pass
class TextoutInlineTag(TextoutTag):
pass
-# ---
# Default tag: paragraph.
-# ---
class TextoutParagraphTag(TextoutBlockTag):
""" Main tag for basic paragraphs. """
@@ -166,22 +174,51 @@ class TextoutParagraphTag(TextoutBlockTag):
return '
'
# ---
-# Tag extractor.
+# Smileys.
# ---
-class TextoutTags:
- """ Tag manager.
+class TextoutSmiley:
+ """ Base class for smileys. """
+
+ aliases = ()
+ url = None
+
+ def __repr__(self):
+ return f"{self.__class__.__name__}(aliases = {repr(self.aliases)}, " \
+ f"url = {repr(self.url)})"
+
+# ---
+# Options extractor and manager.
+# ---
+
+_builtin_module = None
+def _get_builtin_module():
+ """ Get the `.builtin` module. """
+
+ global _builtin_module
+
+ if _builtin_module == None:
+ _builtin_module = _importmod('..builtin', __name__)
+ return _builtin_module
+
+class TextoutOptions:
+ """ Options manager.
Object responsible for getting the tags. """
- def __init__(self, *modules):
+ def __init__(self, *modules, default = True):
self._aliases = {}
- for mod in modules:
- self.import_tags(mod)
+ self._s_aliases = {}
- def __extract_tags(self, module):
- """ Extract tags from a module. """
+ if default:
+ self.import_options(_get_builtin_module())
+ for mod in modules:
+ self.import_options(mod)
+
+ def __extract_from(self, module):
+ """ Extract options from a module. """
tags = []
+ smileys = []
# Obtain the list of properties from the module.
@@ -196,32 +233,61 @@ class TextoutTags:
for submodule in (obj for name, obj in ((nm, getattr(module, nm)) \
for nm in ds) if (name == '__init__' or name[0] != '_') \
and _ismod(obj)):
- obtained = self.__extract_tags(submodule)
- tags += [tag for tag in obtained \
+ ob_tags, ob_smileys = self.__extract_tags(submodule)
+ tags += [tag for tag in ob_tags \
if not any(tag is x for x in tags)]
+ smileys += [sm for sm in ob_smileys \
+ if not any(sm is x for x in smileys)]
del obtained
# Extract the tags from the current module.
- for tag in (obj for name, obj in ((nm, getattr(module, nm)) \
- for nm in ds) if name[0] != '_' and _isclass(obj) \
- and issubclass(obj, TextoutTag)):
- tags.append(tag)
+ for obj in (obj for name, obj in ((nm, getattr(module, nm)) \
+ for nm in ds) if name[0] != '_'):
+ if _isclass(obj) and issubclass(obj, TextoutTag):
+ tags += [tag for tag in (obj,) \
+ if not any(tag is x for x in tags)]
+ if _isclass(obj) and issubclass(obj, TextoutSmiley):
+ smileys += [sm for sm in (obj,) \
+ if not any(sm is x for x in smileys)]
- return tags
+ return tags, smileys
- def import_tags(self, module):
- """ Import tags from a dedicated module. """
+ def import_options(self, module):
+ """ Import tags and smileys from a dedicated module. """
- if not _ismod(module):
+ if isinstance(module, str):
+ module = str(module)
module = _importmod(module,
_getouterframes(_currentframe(), 1)[0].name)
- for tag in self.__extract_tags(module):
+ if not _ismod(module):
+ raise ValueError(f"expected a module, got: {repr(module)}")
+
+ tags, smileys = self.__extract_from(module)
+ for tag in tags:
for alias in tag.aliases:
self._aliases[alias] = tag
+ for sm in smileys:
+ for alias in sm.aliases:
+ self._s_aliases[alias] = sm
+ self._htmlsm = None
- def get_tag(self, name, value, output_type = 'html', tweaks = {}):
- """ Initialize a tag. """
+ def get_smileys(self):
+ """ Get the smileys dictionary. """
+
+ return self._s_aliases.copy()
+
+ def htmlsmileys(self, text):
+ """ Get the smileys convertor for HTML. """
+
+ if not self._htmlsm:
+ self._htmlsm = _htmlsm(self._s_aliases)
+ return self._htmlsm.convert(text)
+
+ def get_tag(self, name):
+ """ Get the tag class corresponding to a name. """
+
+ return self._aliases[name]
try:
als = self._aliases[name]
diff --git a/textoutpc/stream.py b/textoutpc/_stream.py
similarity index 100%
rename from textoutpc/stream.py
rename to textoutpc/_stream.py
diff --git a/textoutpc/translate.py b/textoutpc/_translate.py
similarity index 96%
rename from textoutpc/translate.py
rename to textoutpc/_translate.py
index d877f38..73b5d93 100755
--- a/textoutpc/translate.py
+++ b/textoutpc/_translate.py
@@ -9,21 +9,14 @@
import string as _string
from copy import deepcopy as _deepcopy
-from html import escape as _htmlescape
-from importlib import import_module as _importmod
-from .tags import TextoutBlockTag as _TextoutBlockTag, \
- TextoutParagraphTag as _TextoutParagraphTag, TextoutTags as _Tags
-from .stream import TextoutStream as _TextoutStream
-from .smileys import htmlsmileys as _htmlsmileys
-from .urls import htmlurls as _htmlurls
+from ._options import TextoutBlockTag as _TextoutBlockTag, \
+ TextoutParagraphTag as _TextoutParagraphTag, TextoutOptions as _Options
+from ._stream import TextoutStream as _TextoutStream
+from ._html import escape as _htmlescape, urls as _htmlurls
__all__ = ["Translator"]
-# Builtin tags.
-
-_builtin_tags = _Tags(_importmod('..builtin_tags', __name__))
-
# ---
# Tweaks interface.
# ---
@@ -143,8 +136,7 @@ class Translator:
You can even chain calls as the `process()` method returns
the output stream object. """
- def __init__(self, inp, outp, output_type = 'html', \
- tweaks = {}, tags = _builtin_tags):
+ def __init__(self, inp, outp, output_type, tweaks, options):
""" Initializer. """
if not output_type in ('html', 'lightscript'):
@@ -152,7 +144,7 @@ class Translator:
self.output_type = output_type
self.tweaks = _TweaksDictionary(tweaks)
- self.tags = tags
+ self.options = options
self.inp = inp
self.outp = outp
@@ -203,7 +195,8 @@ class Translator:
# because it's nicer!
if not self.raw_mode and self.output_type == 'html':
- text = _htmlsmileys(_htmlurls(text))
+ text = _htmlurls(text)
+ text = self.options.htmlsmileys(text)
return text
@@ -712,9 +705,19 @@ class Translator:
# Get the initialized tag with the name and value.
# If the tag is unknown, output the full thing and just go on.
- tag = self.tags.get_tag(tagdata.name, tagdata.value,
- self.output_type, self.tweaks)
- if not tag:
+ try:
+ tag = self.options.get_tag(tagdata.name)
+ except:
+ self.put_text(tagdata.full)
+ continue
+
+ value = tagdata.value
+ if value != None and hasattr(tag, 'procvalue') and tag.procvalue:
+ value = self.process_text(value)
+
+ try:
+ tag = tag(tagdata.name, value, self.output_type, self.tweaks)
+ except:
self.put_text(tagdata.full)
continue
diff --git a/textoutpc/builtin_tags/Align.py b/textoutpc/builtin/_Align.py
similarity index 95%
rename from textoutpc/builtin_tags/Align.py
rename to textoutpc/builtin/_Align.py
index 8bcf526..521ee85 100755
--- a/textoutpc/builtin_tags/Align.py
+++ b/textoutpc/builtin/_Align.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutAlignTag"]
diff --git a/textoutpc/builtin_tags/Code.py b/textoutpc/builtin/_Code.py
similarity index 94%
rename from textoutpc/builtin_tags/Code.py
rename to textoutpc/builtin/_Code.py
index 760020d..c9ddfb7 100755
--- a/textoutpc/builtin_tags/Code.py
+++ b/textoutpc/builtin/_Code.py
@@ -4,8 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag, \
- TextoutInlineTag as _TextoutInlineTag
+from .. import BlockTag as _TextoutBlockTag, InlineTag as _TextoutInlineTag
__all__ = ["TextoutCodeTag", "TextoutInlineCodeTag", "TextoutNoEvalTag"]
diff --git a/textoutpc/builtin_tags/Image.py b/textoutpc/builtin/_Image.py
similarity index 98%
rename from textoutpc/builtin_tags/Image.py
rename to textoutpc/builtin/_Image.py
index b24ee1e..ae21891 100755
--- a/textoutpc/builtin_tags/Image.py
+++ b/textoutpc/builtin/_Image.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
+from .. import BlockTag as _TextoutBlockTag
from html import escape as _htmlescape
__all__ = ["TextoutImageTag", "TextoutAdminImageTag"]
diff --git a/textoutpc/builtin_tags/Label.py b/textoutpc/builtin/_Label.py
similarity index 96%
rename from textoutpc/builtin_tags/Label.py
rename to textoutpc/builtin/_Label.py
index 8845488..956f8ed 100755
--- a/textoutpc/builtin_tags/Label.py
+++ b/textoutpc/builtin/_Label.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutInlineTag as _TextoutInlineTag
+from .. import InlineTag as _TextoutInlineTag
import re as _re
__all__ = ["TextoutLabelTag", "TextoutTargetTag"]
diff --git a/textoutpc/builtin_tags/Link.py b/textoutpc/builtin/_Link.py
similarity index 97%
rename from textoutpc/builtin_tags/Link.py
rename to textoutpc/builtin/_Link.py
index f0cfdc9..7d8778e 100755
--- a/textoutpc/builtin_tags/Link.py
+++ b/textoutpc/builtin/_Link.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutInlineTag as _TextoutInlineTag
+from .. import InlineTag as _TextoutInlineTag
from html import escape as _htmlescape
__all__ = ["TextoutLinkTag", "TextoutProfileTag"]
diff --git a/textoutpc/builtin_tags/Progress.py b/textoutpc/builtin/_Progress.py
similarity index 95%
rename from textoutpc/builtin_tags/Progress.py
rename to textoutpc/builtin/_Progress.py
index f99d96a..75f5f9a 100755
--- a/textoutpc/builtin_tags/Progress.py
+++ b/textoutpc/builtin/_Progress.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutProgressTag"]
diff --git a/textoutpc/builtin_tags/Quote.py b/textoutpc/builtin/_Quote.py
similarity index 82%
rename from textoutpc/builtin_tags/Quote.py
rename to textoutpc/builtin/_Quote.py
index 2a7666b..3f6e716 100755
--- a/textoutpc/builtin_tags/Quote.py
+++ b/textoutpc/builtin/_Quote.py
@@ -4,9 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
-from html import escape as _htmlescape
-from ..smileys import htmlsmileys as _htmlsmileys
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutQuoteTag"]
@@ -24,6 +22,7 @@ class TextoutQuoteTag(_TextoutBlockTag):
aliases = ('[quote]',)
superblock = True
notempty = True
+ procvalue = True
def prepare(self, name, value):
self._value = value
@@ -31,8 +30,7 @@ class TextoutQuoteTag(_TextoutBlockTag):
def begin_html(self):
f = ''
if self._value:
- f += '
{} a écrit :
' \
- .format(_htmlsmileys(_htmlescape(self._value)))
+ f += '
{} a écrit :
'.format(self._value)
return f
def end_html(self):
diff --git a/textoutpc/builtin_tags/Rot.py b/textoutpc/builtin/_Rot.py
similarity index 94%
rename from textoutpc/builtin_tags/Rot.py
rename to textoutpc/builtin/_Rot.py
index ed9ff31..284bfc5 100755
--- a/textoutpc/builtin_tags/Rot.py
+++ b/textoutpc/builtin/_Rot.py
@@ -4,8 +4,8 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutInlineTag as _TextoutInlineTag
import string as _string
+from .. import InlineTag as _TextoutInlineTag
__all__ = ["TextoutRotTag"]
diff --git a/textoutpc/builtin_tags/Show.py b/textoutpc/builtin/_Show.py
similarity index 93%
rename from textoutpc/builtin_tags/Show.py
rename to textoutpc/builtin/_Show.py
index 66df4e8..f9ede78 100755
--- a/textoutpc/builtin_tags/Show.py
+++ b/textoutpc/builtin/_Show.py
@@ -4,8 +4,8 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
from html import escape as _htmlescape
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutShowTag"]
diff --git a/textoutpc/builtin/_Smileys.py b/textoutpc/builtin/_Smileys.py
new file mode 100644
index 0000000..0f10c8d
--- /dev/null
+++ b/textoutpc/builtin/_Smileys.py
@@ -0,0 +1,141 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
+# This file is part of the textoutpc project, which is MIT-licensed.
+#******************************************************************************
+
+from .. import Smiley as _TextoutSmiley
+
+__all__ = ["TwistedSmiley", "EvilSmiley", "SmileSmiley", "WinkSmiley",
+ "SadSmiley", "GrinSmiley", "HeheSmiley", "CoolSmiley", "Cool2Smiley",
+ "MadSmiley", "EekSmiley", "MrGreenSmiley", "ShockedSmiley",
+ "ConfusedSmiley", "EyebrowsSmiley", "CrySmiley", "LolSmiley",
+ "SorrySmiley", "RollEyesSmiley", "WazaSmiley", "HereSmiley",
+ "BowSmiley", "GoodSmiley", "LoveSmiley", "OuchSmiley", "FacepalmSmiley",
+ "InsultsSmiley", "WhatSmiley", "ExclSmiley"]
+
+_prefix = '/images/smileys/'
+
+class TwistedSmiley(_TextoutSmiley):
+ aliases = ('>:)',)
+ url = _prefix + 'twisted.gif'
+
+class EvilSmiley(_TextoutSmiley):
+ aliases = ('>:(', ':grr:')
+ url = _prefix + 'evil.gif'
+
+class SmileSmiley(_TextoutSmiley):
+ aliases = (':)',)
+ url = _prefix + 'smile.gif'
+
+class WinkSmiley(_TextoutSmiley):
+ aliases = (';)',)
+ url = _prefix + 'wink.gif'
+
+class SadSmiley(_TextoutSmiley):
+ aliases = (':(',)
+ url = _prefix + 'sad.gif'
+
+class GrinSmiley(_TextoutSmiley):
+ aliases = (':D', ':grin:')
+ url = _prefix + 'grin.gif'
+
+class HeheSmiley(_TextoutSmiley):
+ aliases = (':p',)
+ url = _prefix + 'hehe.gif'
+
+class CoolSmiley(_TextoutSmiley):
+ aliases = (':cool:',)
+ url = _prefix + 'cool.gif'
+
+class Cool2Smiley(_TextoutSmiley):
+ aliases = ('8-)',)
+ url = _prefix + 'cool2.gif'
+
+class MadSmiley(_TextoutSmiley):
+ aliases = (':@',)
+ url = _prefix + 'mad.gif'
+
+class EekSmiley(_TextoutSmiley):
+ aliases = ('0_0',)
+ url = _prefix + 'eek.gif'
+
+class MrGreenSmiley(_TextoutSmiley):
+ aliases = (':E', ':mrgreen:')
+ url = _prefix + 'mrgreen.gif'
+
+class ShockedSmiley(_TextoutSmiley):
+ aliases = (':O',)
+ url = _prefix + 'shocked.gif'
+
+class ConfusedSmiley(_TextoutSmiley):
+ aliases = (':s', ':oops:')
+ url = _prefix + 'confused2.gif'
+
+class EyebrowsSmiley(_TextoutSmiley):
+ aliases = ('^^',)
+ url = _prefix + 'eyebrows.gif'
+
+class CrySmiley(_TextoutSmiley):
+ aliases = (":'(", ":cry:")
+ url = _prefix + 'cry.gif'
+
+# FIXME
+#class WhistleSmiley(_TextoutSmiley):
+# aliases = (":-°", ':whistle:')
+# url = _prefix + 'whistle.gif'
+# height = '15px'
+
+class LolSmiley(_TextoutSmiley):
+ aliases = (":lol:",)
+ url = _prefix + 'lol.gif'
+
+class SorrySmiley(_TextoutSmiley):
+ aliases = (":sry:",)
+ url = _prefix + 'redface.gif'
+
+class RollEyesSmiley(_TextoutSmiley):
+ aliases = (":mmm:",)
+ url = _prefix + 'rolleyes.gif'
+
+class WazaSmiley(_TextoutSmiley):
+ aliases = (":waza:",)
+ url = _prefix + 'waza.gif'
+
+class HereSmiley(_TextoutSmiley):
+ aliases = (":here:", ":arrow:")
+ url = _prefix + 'pointer.gif'
+
+class BowSmiley(_TextoutSmiley):
+ aliases = (":bow:",)
+ url = _prefix + 'bow.gif'
+
+class GoodSmiley(_TextoutSmiley):
+ aliases = (":good:",)
+ url = _prefix + 'welldone.gif'
+
+class LoveSmiley(_TextoutSmiley):
+ aliases = (":love:",)
+ url = _prefix + 'love.gif'
+
+class OuchSmiley(_TextoutSmiley):
+ aliases = (":aie:",)
+ url = _prefix + 'banghead2.gif'
+
+class FacepalmSmiley(_TextoutSmiley):
+ aliases = (":facepalm:",)
+ url = _prefix + 'facepalm.gif'
+
+class InsultsSmiley(_TextoutSmiley):
+ aliases = (":argh:",)
+ url = _prefix + 'insults.gif'
+
+class WhatSmiley(_TextoutSmiley):
+ aliases = (":?:",)
+ url = _prefix + 'what.gif'
+
+class ExclSmiley(_TextoutSmiley):
+ aliases = (":!:",)
+ url = _prefix + 'excl.gif'
+
+# End of file.
diff --git a/textoutpc/builtin_tags/Spoiler.py b/textoutpc/builtin/_Spoiler.py
similarity index 81%
rename from textoutpc/builtin_tags/Spoiler.py
rename to textoutpc/builtin/_Spoiler.py
index 597d9f6..f5e3db2 100755
--- a/textoutpc/builtin_tags/Spoiler.py
+++ b/textoutpc/builtin/_Spoiler.py
@@ -4,9 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
-from html import escape as _htmlescape
-from ..smileys import htmlsmileys as _htmlsmileys
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutSpoilerTag"]
@@ -24,6 +22,7 @@ class TextoutSpoilerTag(_TextoutBlockTag):
aliases = ('[spoiler]',)
superblock = True
notempty = True
+ procvalue = True
def prepare(self, name, value):
self._closed = "Cliquez pour découvrir"
@@ -33,8 +32,8 @@ class TextoutSpoilerTag(_TextoutBlockTag):
titles = value.split('|')
if titles[0]:
self._closed = titles[0]
- if len(titles) >= 2 and titles[1]:
- self._open = titles[1]
+ if len(titles) >= 2 and (len(titles) > 2 or titles[1]):
+ self._open = '|'.join(titles[1:])
def begin_html(self):
return '' \
@@ -42,8 +41,7 @@ class TextoutSpoilerTag(_TextoutBlockTag):
'\'open\');">
{}
' \
'' \
- ''.format(_htmlsmileys(_htmlescape(self._closed)),
- _htmlsmileys(_htmlescape(self._open)))
+ '
'.format(self._closed, self._open)
def end_html(self):
return '
'
diff --git a/textoutpc/builtin_tags/Text.py b/textoutpc/builtin/_Text.py
similarity index 97%
rename from textoutpc/builtin_tags/Text.py
rename to textoutpc/builtin/_Text.py
index 86de152..506ab1f 100755
--- a/textoutpc/builtin_tags/Text.py
+++ b/textoutpc/builtin/_Text.py
@@ -4,8 +4,8 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutInlineTag as _TextoutInlineTag
-from ..color import get_color
+from .. import InlineTag as _TextoutInlineTag
+from ..color import get_color as _get_color
__all__ = ["TextoutTextTag"]
@@ -96,7 +96,7 @@ class TextoutTextTag(_TextoutInlineTag):
self._strike = True
elif name == "color":
value, props = get_props(value)
- self._color = get_color(value)
+ self._color = _get_color(value)
elif name == "font":
value, props = get_props(value)
assert value in _fonts
@@ -117,7 +117,7 @@ class TextoutTextTag(_TextoutInlineTag):
elif name in _fonts:
self._font = name
else:
- self._color = get_color(name)
+ self._color = _get_color(name)
# Gestion des injections CSS.
diff --git a/textoutpc/builtin_tags/Title.py b/textoutpc/builtin/_Title.py
similarity index 94%
rename from textoutpc/builtin_tags/Title.py
rename to textoutpc/builtin/_Title.py
index 01b0e44..7f8bdeb 100755
--- a/textoutpc/builtin_tags/Title.py
+++ b/textoutpc/builtin/_Title.py
@@ -4,7 +4,7 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
+from .. import BlockTag as _TextoutBlockTag
__all__ = ["TextoutTitleTag"]
diff --git a/textoutpc/builtin_tags/Video.py b/textoutpc/builtin/_Video.py
similarity index 98%
rename from textoutpc/builtin_tags/Video.py
rename to textoutpc/builtin/_Video.py
index c23c047..4cf8052 100755
--- a/textoutpc/builtin_tags/Video.py
+++ b/textoutpc/builtin/_Video.py
@@ -4,11 +4,12 @@
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
-from ..tags import TextoutBlockTag as _TextoutBlockTag
import re as _re
import urllib.parse as _urlparse
from html import escape as _htmlescape
+from .. import BlockTag as _TextoutBlockTag
+
__all__ = ["TextoutVideoTag"]
_hexcode = _re.compile('[a-zA-Z0-9_]+')
diff --git a/textoutpc/builtin/__init__.py b/textoutpc/builtin/__init__.py
new file mode 100755
index 0000000..9feec19
--- /dev/null
+++ b/textoutpc/builtin/__init__.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
+# This file is part of the textoutpc project, which is MIT-licensed.
+#******************************************************************************
+""" Built-in tags and smileys for the `textoutpc` module.
+
+ Some of these options will probably have to move to a separate module
+ Planète Casio-specific, but still, here we are.
+"""
+
+# Tags.
+
+from ._Align import *
+from ._Code import *
+from ._Image import *
+from ._Label import *
+from ._Link import *
+from ._Progress import *
+from ._Quote import *
+from ._Rot import *
+from ._Show import *
+from ._Spoiler import *
+from ._Text import *
+from ._Title import *
+from ._Video import *
+
+# Smileys.
+
+from ._Smileys import *
+
+# End of file.
diff --git a/textoutpc/builtin_tags/__init__.py b/textoutpc/builtin_tags/__init__.py
deleted file mode 100755
index 4781fea..0000000
--- a/textoutpc/builtin_tags/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env python3
-#******************************************************************************
-# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
-# 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.
-"""
-
-_names = ["Align", "Code", "Image", "Label", "Link", "Progress",
- "Quote", "Rot", "Show", "Spoiler", "Text", "Title", "Video"]
-for name in _names:
- __import__(name, globals(), level=1)
-
-# End of file.
diff --git a/textoutpc/color/__init__.py b/textoutpc/color/__init__.py
index 09f2281..8046fed 100755
--- a/textoutpc/color/__init__.py
+++ b/textoutpc/color/__init__.py
@@ -10,8 +10,6 @@
the W3C standards, although it is inspired from it.
"""
-from .read import get_color
-
-__all__ = ["get_color"]
+from ._read import get_color
# End of file.
diff --git a/textoutpc/color/named.py b/textoutpc/color/_named.py
similarity index 100%
rename from textoutpc/color/named.py
rename to textoutpc/color/_named.py
diff --git a/textoutpc/color/read.py b/textoutpc/color/_read.py
similarity index 98%
rename from textoutpc/color/read.py
rename to textoutpc/color/_read.py
index 375ac30..79c88af 100755
--- a/textoutpc/color/read.py
+++ b/textoutpc/color/_read.py
@@ -10,8 +10,8 @@
import re as _re
import math as _math
-from .named import colors as _named_colors
-from .sys import hls_to_rgb as _hls_to_rgb, hwb_to_rgb as _hwb_to_rgb
+from ._named import colors as _named_colors
+from ._sys import hls_to_rgb as _hls_to_rgb, hwb_to_rgb as _hwb_to_rgb
__all__ = ["get_color"]
diff --git a/textoutpc/color/sys.py b/textoutpc/color/_sys.py
similarity index 100%
rename from textoutpc/color/sys.py
rename to textoutpc/color/_sys.py
diff --git a/textoutpc/smileys.py b/textoutpc/smileys.py
deleted file mode 100755
index 5d06e62..0000000
--- a/textoutpc/smileys.py
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/usr/bin/env python3
-#******************************************************************************
-# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
-# This file is part of the textoutpc project, which is MIT-licensed.
-#******************************************************************************
-""" Smiley conversion.
- Just convert them™.
-"""
-
-import regex as _re
-from html import escape as _htmlescape
-
-__all__ = ["htmlsmileys"]
-
-# ---
-# List of them.
-# ---
-
-_Smileys_prefix = "/images/smileys/"
-
-_Smileys = {
- '>:)': 'twisted.gif',
- '>:(': 'evil.gif',
- ':)': 'smile.gif',
- ';)': 'wink.gif',
- ':(': 'sad.gif',
- ':D': 'grin.gif',
- ':p': 'hehe.gif',
- '8-)': 'cool2.gif',
- ':@': 'mad.gif',
- '0_0': 'eek.gif',
- ':E': 'mrgreen.gif',
- ':O': 'shocked.gif',
- ':s': 'confused2.gif',
- '^^': 'eyebrows.gif',
- ":'(": 'cry.gif',
-# ':-°': ('whistle.gif', 'height: 15px;'),
-
- # Name-based smileys.
-
- ':lol:': 'lol.gif',
- ':oops:': 'confused2.gif',
- ':grr:': 'evil.gif',
- ':sry:': 'redface.gif',
- ':mmm:': 'rolleyes.gif',
- ':waza:': 'waza.gif',
-# ':whistle:': ('whistle.gif', 'height: 15px;'),
- ':here:': 'pointer.gif',
- ':bow:': 'bow.gif',
- ':cool:': 'cool.gif',
- ':good:': 'welldone.gif',
- ':love:': 'love.gif',
- ':aie:': 'banghead2.gif',
- ':cry:': 'cry.gif',
- ':facepalm:': 'facepalm.gif',
- ':argh:': 'insults.gif',
- ':?:': 'what.gif',
- ':!:': 'excl.gif',
- ':arrow:': 'here.gif',
- ':grin:': 'grin.gif',
-}
-_Smileys_html = {_htmlescape(a): _Smileys_prefix + b \
- for a, b in _Smileys.items()}
-
-def _Smiley_sub_html(m):
- return m.group(1) + '' + m.group(3)
-
-_Smiley_html_re = _re.compile('(^|\\s)(' + '|'.join(map(_re.escape,
- _Smileys_html.keys())) + ')(\\s|$)')
-
-# ---
-# Functions.
-# ---
-
-def htmlsmileys(text):
- """ HTML smileys """
-
- text = _Smiley_html_re.sub(_Smiley_sub_html, text)
- text = _Smiley_html_re.sub(_Smiley_sub_html, text)
- return text
-
-# End of file.
diff --git a/textoutpc/urls.py b/textoutpc/urls.py
deleted file mode 100755
index 7d35296..0000000
--- a/textoutpc/urls.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env python3
-#******************************************************************************
-# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey
-# This file is part of the textoutpc project, which is MIT-licensed.
-#******************************************************************************
-""" Autolinking (URL extraction from raw text) in HTML. """
-
-import regex as _re
-
-__all__ = ["htmlurls", "lightscripturls"]
-
-# ---
-# Autolinking regex.
-# ---
-
-def _sub_html(m):
- sp = m.group('sp')
- url = m.group('url')
- aft = ''
-
- # Hack for the last comma.
- if url[-1] == ',':
- url, aft = url[:-1], ','
-
- text = '{}{}{}' \
- .format(sp, url, url, aft)
- return text
-
-def _sub_lightscript(m):
- sp = m.group('sp')
- url = m.group('url')
- aft = ''
-
- # Hack for the last comma.
- if url[-1] == ',':
- url, aft = url[:-1], ','
-
- url = url.replace('<', '%3C')
- url = url.replace('>', '%3E')
- text = '{}<{}>{}'.format(sp, url, aft)
- return text
-
-_reg = _re.compile("""\
- (?P^|\s|[[:punct:]])
- (?P(https?|ftp):
- (?P[^\[\]\(\)\s]* (\[(?&ucore)\]?)* (\((?&ucore)\)?)*)*
- )
-""", _re.VERBOSE | _re.M)
-
-# ---
-# Main functions.
-# ---
-
-def htmlurls(text):
- return _reg.sub(_sub_html, text)
-
-def lightscripturls(text):
- return _reg.sub(_sub_lightscript, text)
-
-# End of file.