@@ -35,7 +35,8 @@ class Tag(Node):
def __init__(self, tag, contents=None, attrs=None, wiki_markup=None,
def __init__(self, tag, contents=None, attrs=None, wiki_markup=None,
self_closing=False, invalid=False, implicit=False, padding="",
self_closing=False, invalid=False, implicit=False, padding="",
closing_tag=None, closing_wiki_markup=None):
closing_tag=None, wiki_style_separator=None,
closing_wiki_markup=None):
super(Tag, self).__init__()
super(Tag, self).__init__()
self._tag = tag
self._tag = tag
if contents is None and not self_closing:
if contents is None and not self_closing:
@@ -44,12 +45,6 @@ class Tag(Node):
self._contents = contents
self._contents = contents
self._attrs = attrs if attrs else []
self._attrs = attrs if attrs else []
self._wiki_markup = wiki_markup
self._wiki_markup = wiki_markup
if closing_wiki_markup:
self._closing_wiki_markup = closing_wiki_markup
elif wiki_markup and not self_closing:
self._closing_wiki_markup = wiki_markup
else:
self._closing_wiki_markup = None
self._self_closing = self_closing
self._self_closing = self_closing
self._invalid = invalid
self._invalid = invalid
self._implicit = implicit
self._implicit = implicit
@@ -58,16 +53,28 @@ class Tag(Node):
self._closing_tag = closing_tag
self._closing_tag = closing_tag
else:
else:
self._closing_tag = tag
self._closing_tag = tag
self._wiki_style_separator = wiki_style_separator
if closing_wiki_markup is not None:
self._closing_wiki_markup = closing_wiki_markup
elif wiki_markup and not self_closing:
self._closing_wiki_markup = wiki_markup
else:
self._closing_wiki_markup = None
def __unicode__(self):
def __unicode__(self):
if self.wiki_markup:
if self.wiki_markup:
attrs = "".join([str(attr) for attr in self.attributes]) if self.attributes else ""
close = self.closing_wiki_markup if self.closing_wiki_markup else ""
padding = self.padding if self.padding else ""
if self.attributes:
attrs = "".join([str(attr) for attr in self.attributes])
else:
attrs = ""
padding = self.padding or ""
separator = self.wiki_style_separator or ""
close = self.closing_wiki_markup or ""
if self.self_closing:
if self.self_closing:
return self.wiki_markup + attrs + padding + close
return self.wiki_markup + attrs + padding + separator
else:
else:
return self.wiki_markup + attrs + padding + str(self.contents) + close
return self.wiki_markup + attrs + padding + separator + \
str(self.contents) + close
result = ("</" if self.invalid else "<") + str(self.tag)
result = ("</" if self.invalid else "<") + str(self.tag)
if self.attributes:
if self.attributes:
@@ -144,20 +151,6 @@ class Tag(Node):
return self._wiki_markup
return self._wiki_markup
@property
@property
def closing_wiki_markup(self):
"""The wikified version of the closing tag to show instead of HTML.
If set to a value, this will be displayed instead of the close tag
brackets. If tag is :attr:`self_closing` is ``True`` and this is not
``None``, then it becomes the self-closing end tag. If
:attr:`wiki_markup` is set and this has not been set, this is set to the
value of :attr:`wiki_markup`. If this has been set and
:attr:`wiki_markup` is set to a ``False`` value, this is set to
``None``.
"""
return self._closing_wiki_markup
@property
def self_closing(self):
def self_closing(self):
"""Whether the tag is self-closing with no content (like ``<br/>``)."""
"""Whether the tag is self-closing with no content (like ``<br/>``)."""
return self._self_closing
return self._self_closing
@@ -197,6 +190,27 @@ class Tag(Node):
"""
"""
return self._closing_tag
return self._closing_tag
@property
def wiki_style_separator(self):
"""The separator between the padding and content in a wiki markup tag.
Essentially the wiki equivalent of the TagCloseOpen.
"""
return self._wiki_style_separator
@property
def closing_wiki_markup(self):
"""The wikified version of the closing tag to show instead of HTML.
If set to a value, this will be displayed instead of the close tag
brackets. If tag is :attr:`self_closing` is ``True`` then this is not
displayed. If :attr:`wiki_markup` is set and this has not been set, this
is set to the value of :attr:`wiki_markup`. If this has been set and
:attr:`wiki_markup` is set to a ``False`` value, this is set to
``None``.
"""
return self._closing_wiki_markup
@tag.setter
@tag.setter
def tag(self, value):
def tag(self, value):
self._tag = self._closing_tag = parse_anything(value)
self._tag = self._closing_tag = parse_anything(value)
@@ -211,10 +225,6 @@ class Tag(Node):
if not value or not self.closing_wiki_markup:
if not value or not self.closing_wiki_markup:
self.closing_wiki_markup = str(value) if value else None
self.closing_wiki_markup = str(value) if value else None
@closing_wiki_markup.setter
def closing_wiki_markup(self, value):
self._closing_wiki_markup = str(value) if value else None
@self_closing.setter
@self_closing.setter
def self_closing(self, value):
def self_closing(self, value):
self._self_closing = bool(value)
self._self_closing = bool(value)
@@ -241,6 +251,14 @@ class Tag(Node):
def closing_tag(self, value):
def closing_tag(self, value):
self._closing_tag = parse_anything(value)
self._closing_tag = parse_anything(value)
@wiki_style_separator.setter
def wiki_style_separator(self, value):
self._wiki_style_separator = str(value) if value else None
@closing_wiki_markup.setter
def closing_wiki_markup(self, value):
self._closing_wiki_markup = str(value) if value else None
def has(self, name):
def has(self, name):
"""Return whether any attribute in the tag has the given *name*.
"""Return whether any attribute in the tag has the given *name*.