2
0
Fork 0

Added link_target option support.

This commit is contained in:
Thomas Touhey 2019-07-30 13:35:49 +02:00
parent d0f9f0ae83
commit 61c50224ec
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
3 changed files with 11 additions and 4 deletions

View File

@ -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:

View File

@ -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>'

View File

@ -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