2
0
Fork 0
textout/textoutpc/builtin/_Align.py

58 lines
1.3 KiB
Python
Raw Normal View History

#!/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 .. import BlockTag as _BlockTag
__all__ = ["AlignTag"]
2018-08-25 17:38:24 +02:00
class AlignTag(_BlockTag):
2018-01-26 15:52:59 +01:00
""" Main tag for aligning paragraphs.
Example uses:
2018-08-25 17:38:24 +02:00
[align=center]This text is centered horizontally.[/align]
[justify]This text is justified.[/justify]
"""
2018-07-29 19:51:42 +02:00
aliases = ('[align]', '[center]', '[centre]', '[left]', '[right]',
'[justify]')
2018-06-21 00:43:03 +02:00
superblock = True
notempty = True
def prepare(self, name, value):
2018-07-29 19:51:42 +02:00
_align = {
'center': 'center',
'centre': 'center',
'left': 'left',
'right': 'right',
'justify': 'justify'}
if not name:
align = None
2018-08-25 17:38:24 +02:00
elif name == 'align' and value is not None:
2018-07-29 19:51:42 +02:00
align = _align[value]
else:
align = _align[name[1:-1]]
self._align = align
def begin_html(self):
2018-07-29 19:51:42 +02:00
if not self._align:
return ''
cl = []
if self._align:
cl.append('align-' + self._align)
return '<div{}>'.format(' class="' + ' '.join(cl) + '"' if cl else '')
def end_html(self):
2018-07-29 19:51:42 +02:00
if not self._align:
return ''
return '</div>'
# End of file.