Added link_target option support.
This commit is contained in:
parent
d0f9f0ae83
commit
61c50224ec
|
@ -38,7 +38,9 @@ The following tweaks are read by the translator and built-in tags:
|
|||
(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.
|
||||
e.g. 5 means ``h5`` for ``h5`` for titles and ``h6`` for subtitles.
|
||||
- ``link_target`` (HTML): either ``self`` (default, load in the same
|
||||
frame as it was clicked) or ``blank`` (load in an other window).
|
||||
|
||||
An example call would be:
|
||||
|
||||
|
|
|
@ -52,7 +52,12 @@ class LinkTag(_InlineTag):
|
|||
self._validate()
|
||||
|
||||
def begin_html(self):
|
||||
return '<a href="{}">'.format(_htmlescape(self._url))
|
||||
target = self.tweak("link_target", "").casefold()
|
||||
tattrs = ''
|
||||
if target == 'blank':
|
||||
tattrs = ' target="_blank" rel="noopener"'
|
||||
|
||||
return '<a href="{}"{}>'.format(_htmlescape(self._url), tattrs)
|
||||
|
||||
def end_html(self):
|
||||
return '</a>'
|
||||
|
|
|
@ -21,8 +21,8 @@ class TitleTag(_BlockTag):
|
|||
raw = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
level = self.tweak("title_level", "1")
|
||||
if level[0] == "h":
|
||||
level = self.tweak("title_level", "1").casefold()
|
||||
if isinstance(level, str) and level[0] == "h":
|
||||
level = level[1:]
|
||||
level = int(level)
|
||||
assert 1 <= level <= 5
|
||||
|
|
Loading…
Reference in New Issue