-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelements.py
More file actions
37 lines (30 loc) · 1.38 KB
/
elements.py
File metadata and controls
37 lines (30 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
__author__ = 'kremerdesign'
class Element(object):
def __init__(self, id, type, parent='0', text="", element_class="", style=""):
self.id = id
self.type = type
self.parent = parent
self.text = text
self.element_class = element_class
self.style = style
if self.parent == "":
self.parent = 0
def render_open(self):
return '<{} class="{}" id="{}" style="{}">'.format(self.type, self.element_class, "{}-{}".format(self.type, self.id), self.style)
def render_content(self):
if "[http://" in self.text:
match = re.search(r'(.+) (\w+)\[(http:\/\/.+)\](.+)', self.text)
# m = re.search(r'(.+) (\w+)\[(http:\/\/.+)\](.+)', self.text)
return "{} <a href='{}'>{}</a>{}".format(str(match.group(1)), str(match.group(3)), str(match.group(2)), str(match.group(4)))
else:
return self.text
def render_close(self):
return "</{}>\n".format(self.type, self.id)
#
# class Link(Element):
# def __init__(self, id, type, weblink, parent="", text="", element_class="", style=""):
# super(Link, self).__init__(id, type, parent, text, element_class, style)
# self.weblink = weblink
#
# def render_link(self):
# return '<{} href="{}" class="{}" id="{}" style="{}">'.format(self.type, self.weblink, self.element_class, self.id, self.style)