38 Public method to prettify the HTML code. |
39 Public method to prettify the HTML code. |
39 |
40 |
40 @return prettified HTML code |
41 @return prettified HTML code |
41 @rtype str |
42 @rtype str |
42 """ |
43 """ |
43 from bs4 import BeautifulSoup |
|
44 |
|
45 soup = BeautifulSoup(self.__html, "html.parser") |
44 soup = BeautifulSoup(self.__html, "html.parser") |
46 prettyHtml = soup.prettify(formatter=self.tagPrettify) |
45 prettyHtml = soup.prettify(formatter=self.tagPrettify) |
47 # prettify comments |
46 # prettify comments |
48 prettyHtml = re.sub( |
47 prettyHtml = re.sub( |
49 "<!--(.*?)-->", self.commentPrettify, prettyHtml, flags=re.DOTALL |
48 "<!--(.*?)-->", self.commentPrettify, prettyHtml, flags=re.DOTALL |
78 @param matchobj reference to the match object |
77 @param matchobj reference to the match object |
79 @type re.MatchObject |
78 @type re.MatchObject |
80 @return prettified comment |
79 @return prettified comment |
81 @rtype str |
80 @rtype str |
82 """ |
81 """ |
83 if re.search("\n", matchobj.group()): |
82 if re.search(r"\n", matchobj.group()): |
84 return self.tagPrettify(matchobj.group()) |
83 return self.tagPrettify(matchobj.group()) |
85 else: |
84 else: |
86 return matchobj.group() |
85 return matchobj.group() |