2018-01-26 11:01:41 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-02-19 19:50:26 +01:00
|
|
|
#******************************************************************************
|
|
|
|
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
|
|
# This file is part of the textoutpc project, which is MIT-licensed.
|
|
|
|
#******************************************************************************
|
2018-01-26 11:01:41 +01:00
|
|
|
|
2018-07-28 19:49:29 +02:00
|
|
|
from .. import BlockTag as _BlockTag
|
2018-01-26 11:01:41 +01:00
|
|
|
|
2018-07-28 19:49:29 +02:00
|
|
|
__all__ = ["AlignTag"]
|
2018-01-26 11:01:41 +01:00
|
|
|
|
2018-08-25 17:38:24 +02:00
|
|
|
|
2018-07-28 19:49:29 +02:00
|
|
|
class AlignTag(_BlockTag):
|
2018-01-26 15:52:59 +01:00
|
|
|
""" Main tag for aligning paragraphs.
|
2018-01-26 11:01:41 +01:00
|
|
|
Example uses:
|
2018-08-25 17:38:24 +02:00
|
|
|
|
2018-01-26 11:01:41 +01: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
|
2018-02-19 19:50:26 +01:00
|
|
|
notempty = True
|
2018-01-26 11:01:41 +01:00
|
|
|
|
|
|
|
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]]
|
2018-01-26 11:01:41 +01:00
|
|
|
|
|
|
|
self._align = align
|
|
|
|
|
|
|
|
def begin_html(self):
|
2018-07-29 19:51:42 +02:00
|
|
|
if not self._align:
|
|
|
|
return ''
|
|
|
|
|
2018-01-26 11:01:41 +01:00
|
|
|
cl = []
|
|
|
|
if self._align:
|
|
|
|
cl.append('align-' + self._align)
|
|
|
|
|
2018-04-15 01:26:30 +02:00
|
|
|
return '<div{}>'.format(' class="' + ' '.join(cl) + '"' if cl else '')
|
2018-01-26 11:01:41 +01:00
|
|
|
|
|
|
|
def end_html(self):
|
2018-07-29 19:51:42 +02:00
|
|
|
if not self._align:
|
|
|
|
return ''
|
2018-04-15 01:26:30 +02:00
|
|
|
return '</div>'
|
2018-01-26 11:01:41 +01:00
|
|
|
|
|
|
|
# End of file.
|