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

61 lines
1.5 KiB
Python
Raw Normal View History

2018-01-02 18:57:04 +01:00
#!/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.
#******************************************************************************
2018-01-02 18:57:04 +01:00
from .. import InlineTag as _InlineTag
2018-01-02 18:57:04 +01:00
import re as _re
__all__ = ["LabelTag", "TargetTag"]
2018-01-02 18:57:04 +01:00
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-08-25 17:38:24 +02:00
class LabelTag(_InlineTag):
2018-01-02 18:57:04 +01:00
""" The label tag, defines an anchor at a point of the post.
Example uses:
2018-08-25 17:38:24 +02:00
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...
"""
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
self._label = value
2018-01-02 18:57:04 +01:00
def begin_html(self):
#name = 'label-{}'.format(self._label)
2018-01-16 13:34:11 +01:00
#if _v42compat:
# name += ' ' + self._label
name = self.tweak("label_prefix", "") + self._label
2018-01-02 18:57:04 +01:00
return '<a name="{}"></a>'.format(name)
2018-08-25 17:38:24 +02:00
class TargetTag(_InlineTag):
2018-01-02 18:57:04 +01:00
""" The goto tag, links to an anchor defined in the post.
Example uses:
2018-08-25 17:38:24 +02:00
2018-01-02 18:57:04 +01:00
[target=installation]Check out the installation manual[/target]!
"""
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
self._label = value
2018-01-02 18:57:04 +01:00
def begin_html(self):
#name = 'label-' + self._label
name = self.tweak("label_prefix", "") + self._label
2018-01-02 18:57:04 +01:00
return '<a href="#{}">'.format(name)
def end_html(self):
return '</a>'
2018-01-02 18:57:04 +01:00
# End of file.