ProjectWeb/Html5ToCss3Converter.py

branch
eric7
changeset 38
6a12561fc0b5
parent 35
a3f1dcf94fe4
child 40
a9b17341d181
equal deleted inserted replaced
37:01822a402c97 38:6a12561fc0b5
10 import os 10 import os
11 import datetime 11 import datetime
12 import getpass 12 import getpass
13 import random 13 import random
14 14
15 from PyQt5.QtCore import QObject 15 from PyQt6.QtCore import QObject
16 from PyQt5.QtWidgets import QDialog 16 from PyQt6.QtWidgets import QDialog
17 17
18 from .Html5ToCss3ConverterParameterDialog import ( 18 from .Html5ToCss3ConverterParameterDialog import (
19 Html5ToCss3ConverterParameterDialog 19 Html5ToCss3ConverterParameterDialog
20 ) 20 )
21 21
37 37
38 def __init__(self, html, parent=None): 38 def __init__(self, html, parent=None):
39 """ 39 """
40 Constructor 40 Constructor
41 41
42 @param html HTML text to be converted (string) 42 @param html HTML text to be converted
43 @param parent reference to the parent object (QObject) 43 @type str
44 @param parent reference to the parent object
45 @type QObject
44 """ 46 """
45 super().__init__(parent) 47 super().__init__(parent)
46 48
47 self.__html = html 49 self.__html = html
48 50
49 def getCss3(self): 51 def getCss3(self):
50 """ 52 """
51 Public method to get the converted CSS3 text. 53 Public method to get the converted CSS3 text.
52 54
53 @return CSS3 text (string) 55 @return CSS3 text
56 @rtype str
54 """ 57 """
55 dlg = Html5ToCss3ConverterParameterDialog() 58 dlg = Html5ToCss3ConverterParameterDialog()
56 if dlg.exec() == QDialog.Accepted: 59 if dlg.exec() == QDialog.DialogCode.Accepted:
57 indentation, placeholders = dlg.getData() 60 indentation, placeholders = dlg.getData()
58 61
59 self.__createSoup() 62 self.__createSoup()
60 63
61 alreadyDone = list(self.TagsToIgnore) 64 alreadyDone = list(self.TagsToIgnore)
142 145
143 def __getTags(self): 146 def __getTags(self):
144 """ 147 """
145 Private method to extract all tags of the HTML text. 148 Private method to extract all tags of the HTML text.
146 149
147 @return list of all tags (list of strings) 150 @return list of all tags
151 @rtype list of str
148 """ 152 """
149 tags = [t.name for t in self.__soup.find_all(True)] 153 tags = [t.name for t in self.__soup.find_all(True)]
150 return list(set(tags)) 154 return list(set(tags))
151 155
152 def __getClasses(self): 156 def __getClasses(self):
153 """ 157 """
154 Private method to extract all classes of the HTML text. 158 Private method to extract all classes of the HTML text.
155 159
156 @return list of tuples containing the tag name and its classes 160 @return list of tuples containing the tag name and its classes
157 as a blank separated string (list of tuples of two strings) 161 as a blank separated string
162 @rtype list of tuples of (str, str)
158 """ 163 """
159 classes = [(t.name, " ".join(t["class"])) for t in 164 classes = [(t.name, " ".join(t["class"])) for t in
160 self.__soup.find_all(True, {"class": True})] 165 self.__soup.find_all(True, {"class": True})]
161 return sorted(list(set(classes))) 166 return sorted(list(set(classes)))
162 167
163 def __getIds(self): 168 def __getIds(self):
164 """ 169 """
165 Private method to extract all IDs of the HTML text. 170 Private method to extract all IDs of the HTML text.
166 171
167 @return list of tuples containing the tag name and its ID 172 @return list of tuples containing the tag name and its ID
168 (list of tuples of two strings) 173 @rtype list of tuples of (str, str)
169 """ 174 """
170 ids = [(t.name, t["id"]) for t in 175 ids = [(t.name, t["id"]) for t in
171 self.__soup.find_all(True, {"id": True})] 176 self.__soup.find_all(True, {"id": True})]
172 return sorted(list(set(ids))) 177 return sorted(list(set(ids)))

eric ide

mercurial