2
0
Fork 0

Fixed private tag properties.

This commit is contained in:
Thomas Touhey 2018-01-22 20:49:30 +01:00
parent df0bc1affa
commit fd909e3b9c
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
7 changed files with 60 additions and 54 deletions

View File

@ -66,7 +66,7 @@ __test_cases = {
'onclick="toggleSpoiler(this.parentNode, ' "'open'" ');">Hello' \
'</div><div class="title off" ' \
'onclick="toggleSpoiler(this.parentNode, ' "'close'" ');">world' \
'&gt; :D</div><div class="off">' \
'&gt; <img src="/images/smileys/grin.gif"></div><div class="off">' \
'Close this, quick!</div></div>',
# Videos.

View File

@ -29,9 +29,9 @@ class TextoutRotTag(TextoutRawInlineTag):
upr1 = upr0[rot:] + upr0[:rot]
lwr0 = _string.ascii_lowercase
lwr1 = lwr0[rot:] + lwr0[:rot]
self.trans = str.maketrans(upr0 + lwr0, upr1 + lwr1)
self._trans = str.maketrans(upr0 + lwr0, upr1 + lwr1)
def preprocess(self, content):
return str.translate(content, self.trans)
return str.translate(content, self._trans)
# End of file.

View File

@ -21,11 +21,11 @@ class TextoutSizeTag(TextoutInlineTag):
value = name
if not value in ('small', 'big'):
raise Exception
self.sz = value
self._sz = value
def begin_html(self):
return '<span style="font-size: {};">' \
.format({'big': '15px', 'small': '9px'}[self.sz])
.format({'big': '15px', 'small': '9px'}[self._sz])
def end_html(self):
return '</span>'

View File

@ -1,12 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .__base__ import *
from html import escape as _htmlescape
from .__base__ import *
from ..smileys import htmlsmileys as _htmlsmileys
__all__ = ["TextoutSpoilerTag"]
class TextoutSpoilerTag(TextoutBlockTag):
class TextoutSpoilerTag(TextoutParagraphTag):
""" Hide content at first glance, force people to click to read content.
These elements can contain 'secret' elements such as solutions, source
code, or various other things.
@ -20,24 +21,24 @@ class TextoutSpoilerTag(TextoutBlockTag):
aliases = ('[spoiler]',)
def prepare(self, name, value):
self.closed = "Cliquez pour découvrir"
self.open = "Cliquez pour recouvrir"
self._closed = "Cliquez pour découvrir"
self._open = "Cliquez pour recouvrir"
if value:
titles = value.split('|')
if titles[0]:
self.closed = titles[0]
self._closed = titles[0]
if len(titles) >= 2 and titles[1]:
self.open = titles[1]
self._open = titles[1]
def begin_text(self):
return self.closed + "\n"
return self._closed + "\n"
def preprocess_text(self, content):
self.content = content
self._content = content
def content_text(self):
return "| " + "\n| ".join(self.content.split('\n'))
return "| " + "\n| ".join(self._content.split('\n'))
def begin_html(self):
return '<div class="spoiler">' \
@ -45,8 +46,8 @@ class TextoutSpoilerTag(TextoutBlockTag):
'\'open\');">{}</div>' \
'<div class="title off" onclick="toggleSpoiler(this.parentNode, ' \
'\'close\');">{}</div>' \
'<div class="off">'.format(_htmlescape(self.closed),
_htmlescape(self.open))
'<div class="off">'.format(_htmlsmileys(_htmlescape(self._closed)),
_htmlsmileys(_htmlescape(self._open)))
def end_html(self):
return '</div></div>'

View File

@ -48,59 +48,61 @@ class TextoutTextTag(TextoutInlineTag):
'[grey]', '[brown]')
def prepare(self, name, value):
self.bold = False
self.italic = False
self.underline = False
self.strike = False
self.font = None
self.color = None
self._bold = False
self._italic = False
self._underline = False
self._strike = False
self._font = None
self._color = None
name = name[1:-1]
if name == "b":
self.bold = True
self._bold = True
elif name == "i":
self.italic = True
self._italic = True
elif name == "u":
self.underline = True
self._underline = True
elif name in ("s", "strike"):
self.strike = True
self._strike = True
elif name == "color":
self.color = get_color(value)
self._color = get_color(value)
elif name == "font":
assert value in _fonts
self.font = value
self._font = value
elif name in _fonts:
self.font = value
self._font = value
else:
self.color = get_color(name)
self._color = get_color(name)
def begin_html(self):
props = []
if self.font:
props.append('font-family: ' + self.font)
if self.color:
if self.color[3] < 1.0:
col = 'rgba({}, {}, {}, {})'.format(*self.color)
else:
col = '#%02X%02X%02X' \
% (self.color[0], self.color[1], self.color[2])
props.append('color: ' + col)
self.has_props = bool(props)
if self._font:
props.append('font-family: ' + self._font)
if self._color:
# always append the #rgb color: it will be read by older
# browsers if the `rgba()` function isn't supported.
props.append('color: #%02X%02X%02X' % self._color[0:3])
if self._color[3] < 1.0:
props.append('color: rgba({}, {}, {}, {})' \
.format(*self._color))
self._has_props = bool(props)
props = '<span style="{}">'.format('; '.join(props)) if props else ''
return '' \
+ ('', '<b>')[self.bold] \
+ ('', '<i>')[self.italic] \
+ ('', '<u>')[self.underline] \
+ ('', '<strike>')[self.strike] \
+ ('', '<b>')[self._bold] \
+ ('', '<i>')[self._italic] \
+ ('', '<u>')[self._underline] \
+ ('', '<strike>')[self._strike] \
+ props
def end_html(self):
return '' \
+ ('', '</span>')[self.has_props] \
+ ('', '</strike>')[self.strike] \
+ ('', '</u>')[self.underline] \
+ ('', '</i>')[self.italic] \
+ ('', '</b>')[self.bold]
+ ('', '</span>')[self._has_props] \
+ ('', '</strike>')[self._strike] \
+ ('', '</u>')[self._underline] \
+ ('', '</i>')[self._italic] \
+ ('', '</b>')[self._bold]
# End of file.

View File

@ -16,15 +16,15 @@ class TextoutTitleTag(TextoutRawBlockTag):
aliases = ('[title]', '[subtitle]')
def prepare(self, name, value):
self.level = name[1:-1]
self._level = name[1:-1]
def begin_text(self):
return ('## ', '# ')[self.level == "title"]
return ('## ', '# ')[self._level == "title"]
def begin_html(self):
return ('<h5>', '<h4>')[self.level == "title"]
return ('<h5>', '<h4>')[self._level == "title"]
def end_html(self):
return ('</h5>', '</h4>')[self.level == "title"]
return ('</h5>', '</h4>')[self._level == "title"]
# End of file.

View File

@ -68,7 +68,10 @@ _colors = {
'tan': '#D2B48C', 'teal': '#008080', 'thistle': '#D8BFD8',
'tomato': '#FF6347', 'turquoise': '#40E0D0', 'violet': '#EE82EE',
'wheat': '#F5DEB3', 'white': '#FFFFFF', 'whitesmoke': '#F5F5F5',
'yellow': '#FFFF00', 'yellowgreen': '#9ACD32'
'yellow': '#FFFF00', 'yellowgreen': '#9ACD32',
# Planète Casio special colors.
'transparent': 'rgba(0, 0, 0, 0)',
}
_cr = _re.compile('^\s*('