aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Touhey <thomas@touhey.fr>2019-07-30 13:35:49 +0200
committerThomas Touhey <thomas@touhey.fr>2019-07-30 13:35:49 +0200
commit61c50224ec89c582d3c5b40fc4fbd177a179c6d1 (patch)
tree9e69bced4239e0921eaf65da949a060ac68ab4fe
parentd0f9f0ae834c75101e1b64224d9852b5751175fe (diff)
Added link_target option support.HEADmaster
-rw-r--r--docs/usage.rst4
-rwxr-xr-xtextoutpc/builtin/_Link.py7
-rwxr-xr-xtextoutpc/builtin/_Title.py4
3 files changed, 11 insertions, 4 deletions
diff --git a/docs/usage.rst b/docs/usage.rst
index 1e23cba..6411351 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -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:
diff --git a/textoutpc/builtin/_Link.py b/textoutpc/builtin/_Link.py
index efe4a5a..b4b7ed9 100755
--- a/textoutpc/builtin/_Link.py
+++ b/textoutpc/builtin/_Link.py
@@ -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>'
diff --git a/textoutpc/builtin/_Title.py b/textoutpc/builtin/_Title.py
index 05d12ff..0f744e9 100755
--- a/textoutpc/builtin/_Title.py
+++ b/textoutpc/builtin/_Title.py
@@ -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