2018-01-02 18:57:04 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import re as _re
|
2018-01-05 22:13:30 +01:00
|
|
|
from .__base__ import *
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
__all__ = ["TextoutLabelTag", "TextoutTargetTag"]
|
|
|
|
|
|
|
|
_v42compat = True
|
2018-01-16 13:34:11 +01:00
|
|
|
_labelexpr = _re.compile('^[a-z0-9-]{1,16}$', _re.I)
|
2018-01-02 18:57:04 +01:00
|
|
|
|
2018-01-05 03:31:33 +01:00
|
|
|
class TextoutLabelTag(TextoutInlineTag):
|
2018-01-02 18:57:04 +01:00
|
|
|
""" The label tag, defines an anchor at a point of the post.
|
|
|
|
Example uses:
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
[label=installation]Installation de tel logiciel... (no ending req.)
|
2018-01-02 18:57:04 +01:00
|
|
|
[label=compilation][/label] Compilation de tel logiciel...
|
|
|
|
"""
|
|
|
|
|
2018-01-05 22:13:30 +01:00
|
|
|
aliases = ('[label]',)
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
def prepare(self, name, value):
|
|
|
|
if not _labelexpr.match(value):
|
2018-01-02 18:57:04 +01:00
|
|
|
raise Exception
|
2018-01-16 13:34:11 +01:00
|
|
|
self.label = value
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
def begin_text(self):
|
2018-01-16 13:34:11 +01:00
|
|
|
return '[{}]: '.format(self.label)
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
def begin_html(self):
|
2018-01-16 13:34:11 +01:00
|
|
|
#name = 'label-{}'.format(self.value)
|
|
|
|
#if _v42compat:
|
|
|
|
# name += ' ' + self.value
|
|
|
|
name = self.label if _v42compat else 'label-{}'.format(self.label)
|
2018-01-02 18:57:04 +01:00
|
|
|
return '<a name="{}"></a>'.format(name)
|
|
|
|
|
2018-01-05 03:31:33 +01:00
|
|
|
class TextoutTargetTag(TextoutInlineTag):
|
2018-01-02 18:57:04 +01:00
|
|
|
""" The goto tag, links to an anchor defined in the post.
|
|
|
|
Example uses:
|
|
|
|
|
|
|
|
[target=installation]Check out the installation manual[/target]!
|
|
|
|
"""
|
|
|
|
|
2018-01-05 22:13:30 +01:00
|
|
|
aliases = ('[target]',)
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
def prepare(self, name, value):
|
|
|
|
if not _labelexpr.match(value):
|
2018-01-02 18:57:04 +01:00
|
|
|
raise Exception
|
2018-01-16 13:34:11 +01:00
|
|
|
self.label = value
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
def end_text(self):
|
2018-01-16 13:34:11 +01:00
|
|
|
return ' (voir "{}")'.format(self.label)
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
def begin_html(self):
|
2018-01-16 13:34:11 +01:00
|
|
|
#name = 'label-' + self.value
|
|
|
|
name = self.label if _v42compat else 'label-' + self.label
|
2018-01-02 18:57:04 +01:00
|
|
|
return '<a href="#{}">'.format(name)
|
|
|
|
|
|
|
|
def end_html(self):
|
2018-01-05 22:13:30 +01:00
|
|
|
return '</a>'
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
# End of file.
|