Corrected a few things about the tags.
This commit is contained in:
parent
bb36d42a54
commit
5acbc428cd
|
@ -35,6 +35,8 @@ The following tweaks are read by the translator and built-in tags:
|
|||
- ``obsolete_tags`` (HTML): use obsolete HTML tags for old browsers
|
||||
(e.g. lynx) compatibility, e.g. ``<b>``, ``<i>``, ``<center>``, and
|
||||
others. Defaults to ``True``.
|
||||
- ``title_level`` (HTML): level at which to start for titles and subtitles,
|
||||
e.g. ``h5`` for ``h5`` for titles and ``h6`` for subtitles``.
|
||||
|
||||
An example call would be:
|
||||
|
||||
|
|
|
@ -52,16 +52,16 @@ __test_cases = {
|
|||
'<p><i>d</i>wouhou</p>',
|
||||
|
||||
# Show tag for super preprocessing blocks.
|
||||
'[show]lol': '<p><span style="font-family: monospace;">lol</span></p>',
|
||||
'[show]lol': '<p><span class="inline-code">lol</span></p>',
|
||||
'[quote][show][justify]hehe': \
|
||||
'<div class="citation"><p><span style="font-family: monospace;">' \
|
||||
'<div class="citation"><p><span class="inline-code">' \
|
||||
'<div class="align-justify">' \
|
||||
'<p>hehe</p></div>' \
|
||||
'</span></p></div>',
|
||||
|
||||
# Titles.
|
||||
'lolk[title]smth': '<p>lolk</p>' '<h4>smth</h4>',
|
||||
'[subtitle]<>': '<h5><></h5>',
|
||||
'lolk[title]smth': '<p>lolk</p>' '<h1 class="title">smth</h1>',
|
||||
'[subtitle]<>': '<h2 class="subtitle"><></h2>',
|
||||
|
||||
# Fonts.
|
||||
'[arial]test': '<p><span style="font-family: arial">test</span></p>',
|
||||
|
@ -128,11 +128,10 @@ __test_cases = {
|
|||
|
||||
# Code.
|
||||
'[code]': '',
|
||||
"`[code]`": '<p><span style="font-family: monospace;">[code]</span></p>',
|
||||
"`[code]`": '<p><span class="inline-code">[code]</span></p>',
|
||||
|
||||
'[inlinecode]': '',
|
||||
"[inlinecode]`[/inlinecode]": \
|
||||
'<p><span style="font-family: monospace;">`</span></p>',
|
||||
"[inlinecode]`[/inlinecode]": '<p><span class="inline-code">`</span></p>',
|
||||
|
||||
"[b]a[noeval]b[/b]c[/noeval]d": "<p><b>ab[/b]cd</b></p>",
|
||||
"a[noeval]b[noeval]c[/noeval]d[/noeval]e": "<p>ab[noeval]c[/noeval]de</p>",
|
||||
|
@ -143,6 +142,9 @@ __test_cases = {
|
|||
'[img]': '<p>[img]</p>',
|
||||
'[img]"incroyable<>"[/img]': \
|
||||
'<p>[img]"incroyable<>"[/img]</p>',
|
||||
'[img=right|float|12x345]https://example.org/image.png': \
|
||||
'<img src="https://example.org/image.png" class="img-float-right" ' \
|
||||
'style="width: 12px; height: 345px" />',
|
||||
|
||||
# Videos.
|
||||
'[video]"><script>alert(1)</script>[/video]': \
|
||||
|
@ -152,7 +154,7 @@ __test_cases = {
|
|||
'<p>[video]<script>alert(document.cookie)</script>' \
|
||||
'[/video]</p>',
|
||||
'[video]https://www.youtube.com/watch?v=6odDOOyUawY[/video]': \
|
||||
'<div class="video-wrapper video-medium"><iframe ' \
|
||||
'<div class="video-wrapper"><iframe ' \
|
||||
'src="https://www.youtube.com/embed/6odDOOyUawY" ' \
|
||||
'frameborder="0" allowfullscreen></iframe></div>',
|
||||
'[video]https://www.youtube.com/watch?v=<script>alert(1)</script>': \
|
||||
|
@ -160,6 +162,11 @@ __test_cases = {
|
|||
'</script>">' \
|
||||
'https://www.youtube.com/watch?v=<script>alert(1)' \
|
||||
'</script></a></p>',
|
||||
'[video=left|float|4:3]https://www.youtube.com/watch?v=XEjLoHdbVeE': \
|
||||
'<div class="video-wrapper img-float-left" ' \
|
||||
'style="padding-bottom: 0.75%"><iframe ' \
|
||||
'src="https://www.youtube.com/embed/XEjLoHdbVeE" frameborder="0" ' \
|
||||
'allowfullscreen></iframe></div>',
|
||||
|
||||
# Progress bars.
|
||||
'[progress=lol]mdr[/progress]': '<p>[progress=lol]mdr[/progress]</p>',
|
||||
|
|
|
@ -11,11 +11,13 @@ from io import StringIO as _StringIO
|
|||
|
||||
from ._options import TextoutOptions as Options, \
|
||||
TextoutBlockTag as BlockTag, TextoutInlineTag as InlineTag, \
|
||||
TextoutParagraphTag as ParagraphTag, TextoutSmiley as Smiley
|
||||
TextoutParagraphTag as ParagraphTag, TextoutListTag as _TextoutListTag, \
|
||||
TextoutListElementTag as _TextoutListElementTag, TextoutSmiley as Smiley
|
||||
from ._translate import Translator as _Translator
|
||||
|
||||
__all__ = ["version", "tohtml", "tolightscript",
|
||||
"Options", "BlockTag", "ParagraphTag", "InlineTag", "Smiley"]
|
||||
"Options", "BlockTag", "ParagraphTag", "InlineTag",
|
||||
"ListTag", "ListElementTag", "Smiley"]
|
||||
|
||||
version = "0.1.1"
|
||||
|
||||
|
|
|
@ -162,6 +162,11 @@ class TextoutBlockTag(TextoutTag):
|
|||
class TextoutInlineTag(TextoutTag):
|
||||
pass
|
||||
|
||||
class TextoutListTag(TextoutBlockTag):
|
||||
superblock = True
|
||||
class TextoutListElementTag(TextoutBlockTag):
|
||||
superblock = True
|
||||
|
||||
# Default tag: paragraph.
|
||||
|
||||
class TextoutParagraphTag(TextoutBlockTag):
|
||||
|
|
|
@ -11,26 +11,37 @@ __all__ = ["AlignTag"]
|
|||
class AlignTag(_BlockTag):
|
||||
""" Main tag for aligning paragraphs.
|
||||
Example uses:
|
||||
|
||||
|
||||
[align=center]This text is centered horizontally.[/align]
|
||||
[justify]This text is justified.[/justify]
|
||||
"""
|
||||
|
||||
aliases = ('[align]', '[center]', '[left]', '[right]', '[justify]')
|
||||
aliases = ('[align]', '[center]', '[centre]', '[left]', '[right]',
|
||||
'[justify]')
|
||||
superblock = True
|
||||
notempty = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
align = None
|
||||
if not name: pass
|
||||
_align = {
|
||||
'center': 'center',
|
||||
'centre': 'center',
|
||||
'left': 'left',
|
||||
'right': 'right',
|
||||
'justify': 'justify'}
|
||||
|
||||
if not name:
|
||||
align = None
|
||||
elif name == 'align' and value != None:
|
||||
align = value
|
||||
elif name[1:-1] in ('center', 'left', 'right', 'justify'):
|
||||
align = name[1:-1]
|
||||
align = _align[value]
|
||||
else:
|
||||
align = _align[name[1:-1]]
|
||||
|
||||
self._align = align
|
||||
|
||||
def begin_html(self):
|
||||
if not self._align:
|
||||
return ''
|
||||
|
||||
cl = []
|
||||
if self._align:
|
||||
cl.append('align-' + self._align)
|
||||
|
@ -38,6 +49,8 @@ class AlignTag(_BlockTag):
|
|||
return '<div{}>'.format(' class="' + ' '.join(cl) + '"' if cl else '')
|
||||
|
||||
def end_html(self):
|
||||
if not self._align:
|
||||
return ''
|
||||
return '</div>'
|
||||
|
||||
# End of file.
|
||||
|
|
|
@ -49,7 +49,7 @@ class InlineCodeTag(_InlineTag):
|
|||
raw = True
|
||||
|
||||
def begin_html(self):
|
||||
return '<span style="font-family: monospace;">'
|
||||
return '<span class="inline-code">'
|
||||
|
||||
def end_html(self):
|
||||
return '</span>'
|
||||
|
|
|
@ -24,10 +24,22 @@ class ImageTag(_BlockTag):
|
|||
raw = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
_align = {
|
||||
'center': ('center', False),
|
||||
'centre': ('center', False),
|
||||
'left': ('left', False),
|
||||
'right': ('right', False),
|
||||
'float': (None, True),
|
||||
'floating': (None, True),
|
||||
'float-left': ('left', True),
|
||||
'float-center': ('center', True),
|
||||
'float-centre': ('center', True),
|
||||
'float-right': ('right', True),
|
||||
}
|
||||
|
||||
self._width = None
|
||||
self._height = None
|
||||
self._align = None
|
||||
self._float = False
|
||||
|
||||
for arg in ("", value)[value != None].split('|'):
|
||||
if not arg:
|
||||
|
@ -41,13 +53,12 @@ class ImageTag(_BlockTag):
|
|||
except: pass
|
||||
try: self._height = int(dim[1])
|
||||
except: pass
|
||||
elif arg in ('center', 'left', 'right'):
|
||||
self._align = arg
|
||||
elif arg in ('float-left', 'float-right'):
|
||||
self._align = arg[6:]
|
||||
self._float = True
|
||||
elif arg in ('float', 'floating'):
|
||||
self._float = True
|
||||
elif arg in _align:
|
||||
al, fl = _align[arg]
|
||||
if al != None:
|
||||
self._align = al
|
||||
if fl:
|
||||
self._float = True
|
||||
|
||||
def preprocess(self, content):
|
||||
for prefix in ('http://', 'https://', 'ftp://', '/'):
|
||||
|
@ -70,12 +81,11 @@ class ImageTag(_BlockTag):
|
|||
elif self._width:
|
||||
style.append('height: auto')
|
||||
if self._float:
|
||||
cls.append('img-float')
|
||||
if self._align:
|
||||
cls.append('img-float-{}'.format(self._align or 'right'))
|
||||
elif self._align:
|
||||
cls.append('img-{}'.format(self._align))
|
||||
|
||||
return '<img src="{}"{}{} />'.format(\
|
||||
_htmlescape(self._url),
|
||||
return '<img src="{}"{}{} />'.format(_htmlescape(self._url),
|
||||
' class="{}"'.format(' '.join(cls)) if cls else '',
|
||||
' style="{}"'.format('; '.join(style)) if style else '')
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ _labelexpr = _re.compile('^[a-z0-9-]{1,16}$', _re.I)
|
|||
class LabelTag(_InlineTag):
|
||||
""" The label tag, defines an anchor at a point of the post.
|
||||
Example uses:
|
||||
|
||||
|
||||
[label=installation]Installation de tel logiciel... (no ending req.)
|
||||
[label=compilation][/label] Compilation de tel logiciel...
|
||||
"""
|
||||
|
|
|
@ -28,11 +28,8 @@ class ProgressTag(_BlockTag):
|
|||
|
||||
def end_html(self):
|
||||
return '' \
|
||||
'<div style="background-color: white; border: 1px solid black; ' \
|
||||
'width: 50%; margin-top: 2px; text-align: left;">' \
|
||||
'<div style="background-color: #FF3E28; color: black; ' \
|
||||
'font-weight: bold; max-width: 100%; width: {}%;' \
|
||||
'height: 18px;"> {}%' \
|
||||
'<div class="progress">' \
|
||||
'<div class="progress-inner" style="width: {}%;"> {}%' \
|
||||
'</div></div></div>'.format(self._val, self._val)
|
||||
|
||||
# End of file.
|
||||
|
|
|
@ -23,8 +23,11 @@ class RotTag(_InlineTag):
|
|||
|
||||
def prepare(self, name, value):
|
||||
if name == "[rot]":
|
||||
rot = int(value)
|
||||
assert 1 <= rot <= 25
|
||||
if not value:
|
||||
value = 13
|
||||
else:
|
||||
rot = int(value)
|
||||
assert 1 <= rot <= 25
|
||||
else:
|
||||
rot = int(name[4:-1])
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class ShowTag(_BlockTag):
|
|||
return _htmlescape(content)
|
||||
|
||||
def begin_html(self):
|
||||
return '<span style="font-family: monospace;">'
|
||||
return '<span class="inline-code">'
|
||||
|
||||
def end_html(self):
|
||||
return '</span>'
|
||||
|
|
|
@ -53,7 +53,7 @@ class TextTag(_InlineTag):
|
|||
"""
|
||||
|
||||
aliases = ('[b]', '[i]', '[u]', '[s]', '[strike]',
|
||||
'[monospace]', '[mono]', '[font]', '[color]',
|
||||
'[monospace]', '[mono]', '[font]', '[color]', '[c]',
|
||||
'[size]', '[big]', '[small]',
|
||||
'[arial]', '[comic]', '[tahoma]', '[courier]',
|
||||
'[haettenschweiler]', '[red]', '[green]', '[blue]',
|
||||
|
@ -68,6 +68,7 @@ class TextTag(_InlineTag):
|
|||
self._strike = False
|
||||
self._font = None
|
||||
self._color = None
|
||||
self._bgcolor = None
|
||||
self._size = None
|
||||
|
||||
# Récupérer la partie correspondant à l'injection CSS s'il y
|
||||
|
@ -94,9 +95,12 @@ class TextTag(_InlineTag):
|
|||
self._underline = True
|
||||
elif name in ("s", "strike", "striked"):
|
||||
self._strike = True
|
||||
elif name == "color":
|
||||
elif name in ("color", 'c'):
|
||||
value, props = get_props(value)
|
||||
self._color = _get_color(value)
|
||||
elif name == 'f':
|
||||
value, props = get_props(value)
|
||||
self._bgcolor = _get_color(value)
|
||||
elif name == "font":
|
||||
value, props = get_props(value)
|
||||
assert value in _fonts
|
||||
|
@ -185,6 +189,12 @@ class TextTag(_InlineTag):
|
|||
props.append('color: rgba({}, {}, {}, {})' \
|
||||
.format(*self._color))
|
||||
|
||||
if self._bgcolor and self._bgcolor[3] != 0.0:
|
||||
props.append('background-color: #%02X%02X%02X' % self._color[0:3])
|
||||
if self._bgcolor[3] < 1.0:
|
||||
props.append('background-color: rgba({}, {}, {}, {})' \
|
||||
.format(*self._bgcolor))
|
||||
|
||||
if self._size:
|
||||
props.append('font-size: {}em'.format(self._size))
|
||||
|
||||
|
|
|
@ -20,13 +20,26 @@ class TitleTag(_BlockTag):
|
|||
raw = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
level = self.tweak("title_level", "1")
|
||||
if level[0] == "h":
|
||||
level = level[1:]
|
||||
level = int(level)
|
||||
assert 1 <= level <= 5
|
||||
|
||||
# Name.
|
||||
|
||||
self._level = name[1:-1]
|
||||
|
||||
# HTML tag.
|
||||
|
||||
level += self._level == "subtitle"
|
||||
self._tag = f"h{level}"
|
||||
|
||||
def begin_html(self):
|
||||
return ('<h5>', '<h4>')[self._level == "title"]
|
||||
return f'<{self._tag} class="{self._level}">'
|
||||
|
||||
def end_html(self):
|
||||
return ('</h5>', '</h4>')[self._level == "title"]
|
||||
return f'</{self._tag}>'
|
||||
|
||||
def begin_lightscript(self):
|
||||
return '#' * ((self._level == "subtitle") + 1) + ' '
|
||||
|
|
|
@ -12,7 +12,7 @@ from .. import BlockTag as _BlockTag
|
|||
|
||||
__all__ = ["VideoTag"]
|
||||
|
||||
_hexcode = _re.compile('[a-zA-Z0-9_]+')
|
||||
_hexcode = _re.compile('[a-zA-Z0-9_-]+')
|
||||
_numcode = _re.compile('^/[0-9]+$')
|
||||
_dailypath = _re.compile('^/video/([a-z0-9]+)$')
|
||||
|
||||
|
@ -20,8 +20,9 @@ class VideoTag(_BlockTag):
|
|||
""" The video tag, puts a preview of the video whose URL is given.
|
||||
Only a few 'big' services are supported for now.
|
||||
Example uses:
|
||||
|
||||
|
||||
[video]video_url[/video]
|
||||
[video=4:3]video_url[/video]
|
||||
[video tiny]video_url[/video tiny]
|
||||
[video]https://www.youtube.com/watch?v=yhXpV8hRKxQ[/video]
|
||||
"""
|
||||
|
@ -32,9 +33,44 @@ class VideoTag(_BlockTag):
|
|||
def prepare(self, name, value):
|
||||
""" Prepare the video tag. """
|
||||
|
||||
_align = {
|
||||
'center': ('center', False),
|
||||
'centre': ('center', False),
|
||||
'left': ('left', False),
|
||||
'right': ('right', False),
|
||||
'float': (None, True),
|
||||
'floating': (None, True),
|
||||
'float-left': ('left', True),
|
||||
'float-center': ('center', True),
|
||||
'float-centre': ('center', True),
|
||||
'float-right': ('right', True),
|
||||
}
|
||||
|
||||
self._sizeclass = "video-tiny" if "tiny" in name \
|
||||
else "video-medium"
|
||||
self._center = False
|
||||
else None
|
||||
self._align = None
|
||||
self._float = False
|
||||
self._ratio = round(9 / 16, 4)
|
||||
|
||||
for arg in map(str.strip, (value or "").split('|')):
|
||||
if not arg:
|
||||
pass
|
||||
elif arg[0] in '0123456789:':
|
||||
rx, ry = 16, 9
|
||||
rat = arg.split(':')
|
||||
|
||||
try: rx = int(rat[0])
|
||||
except: pass
|
||||
try: ry = int(rat[1])
|
||||
except: pass
|
||||
|
||||
self._ratio = round(ry / rx, 4)
|
||||
elif arg in _align:
|
||||
al, fl = _align[arg]
|
||||
if al != None:
|
||||
self._align = al
|
||||
if fl:
|
||||
self._float = True
|
||||
|
||||
def _getvideo(self, url):
|
||||
""" Try to get the video type for preprocessing. """
|
||||
|
@ -84,8 +120,14 @@ class VideoTag(_BlockTag):
|
|||
url = _htmlescape(self._url)
|
||||
return '<p><a href="{}">{}</a></p>'.format(url, url)
|
||||
|
||||
code = '<div class="video-wrapper {}{}">'.format(self._sizeclass,
|
||||
" video-center" if self._center else "")
|
||||
align = "float-" + (self._align or "left") if self._align \
|
||||
else self._align
|
||||
|
||||
code = '<div class="video-wrapper{}{}"{}>' \
|
||||
.format(f" {self._sizeclass}" if self._sizeclass else "",
|
||||
f' img-{align}' if align else "",
|
||||
f' style="padding-bottom: {self._ratio}%"' \
|
||||
if self._ratio != round(9 / 16, 4) else "")
|
||||
|
||||
if self._type == "youtube":
|
||||
code += '<iframe ' \
|
||||
|
|
Loading…
Reference in New Issue