ProjectWeb/Html5Prettifier.py

branch
eric7
changeset 50
19050d56699d
parent 49
1910859bbacf
child 52
815847f3d404
equal deleted inserted replaced
49:1910859bbacf 50:19050d56699d
7 Module implementing a class to prettify HTML code. 7 Module implementing a class to prettify HTML code.
8 """ 8 """
9 9
10 import re 10 import re
11 11
12 from bs4 import BeautifulSoup
12 from PyQt6.QtCore import QObject 13 from PyQt6.QtCore import QObject
13 14
14 from eric7 import Preferences 15 from eric7 import Preferences
15 16
16 17
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()

eric ide

mercurial