Tue, 25 May 2021 20:12:47 +0200
Ported the plug-in to PyQt6 for eric7.
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
34
a6d8718f37b5
Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
32
diff
changeset
|
3 | # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the HTML5 to CSS3 converter. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | import os |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | import datetime |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | import getpass |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | import random |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
15 | from PyQt6.QtCore import QObject |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
16 | from PyQt6.QtWidgets import QDialog |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | |
30
38092622e612
Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
18 | from .Html5ToCss3ConverterParameterDialog import ( |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | Html5ToCss3ConverterParameterDialog |
30
38092622e612
Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
20 | ) |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | class Html5ToCss3Converter(QObject): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Class implementing the HTML5 to CSS3 converter. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | CssTemplate7 = "{0}{1}{2}{3}{4}{5}{6}" |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | CssTemplate8 = "{0}{1}{2}{3}{4}{5}{6}{7}" |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Placeholders = ('margin:0', 'padding:0', 'border:0', 'font-size:100%', |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | 'font:inherit', 'vertical-align:baseline', 'line-height:1', |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | 'outline:0', 'font-weight:inherit', 'font-style:inherit', |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | 'font-family:inherit', 'vertical-align:baseline') |
3
e478a359e1fb
Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1
diff
changeset
|
33 | TagsToIgnore = ('head', 'meta', 'noscript', 'script', 'style', 'link', |
e478a359e1fb
Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1
diff
changeset
|
34 | 'no-js', 'title', 'object', 'col', 'colgroup', 'option', |
e478a359e1fb
Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1
diff
changeset
|
35 | 'param', 'audio', 'basefont', 'isindex', 'svg', 'area', |
e478a359e1fb
Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1
diff
changeset
|
36 | 'embed', 'br') |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | def __init__(self, html, parent=None): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | Constructor |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
42 | @param html HTML text to be converted |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
43 | @type str |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
44 | @param parent reference to the parent object |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
45 | @type QObject |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | """ |
35
a3f1dcf94fe4
Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
34
diff
changeset
|
47 | super().__init__(parent) |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.__html = html |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | def getCss3(self): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | Public method to get the converted CSS3 text. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
55 | @return CSS3 text |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
56 | @rtype str |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | dlg = Html5ToCss3ConverterParameterDialog() |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
59 | if dlg.exec() == QDialog.DialogCode.Accepted: |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | indentation, placeholders = dlg.getData() |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | self.__createSoup() |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
3
e478a359e1fb
Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1
diff
changeset
|
64 | alreadyDone = list(self.TagsToIgnore) |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | css = '@charset "utf-8";{0}'.format(os.linesep) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | css += "/* {0} by {1}*/{2}".format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | datetime.datetime.now().isoformat().split(".")[0], |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | getpass.getuser(), |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | 2 * os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | # step 1: tags |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | for tag in self.__getTags(): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | if tag not in alreadyDone: |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | css += self.CssTemplate7.format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | tag, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | "{", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | os.linesep, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | indentation, |
30
38092622e612
Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
81 | random.choice(self.Placeholders) + os.linesep # secok |
6
a1600fa29542
A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
82 | if placeholders else os.linesep, |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | "}", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | alreadyDone.append(tag) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | css += "/*{0}*/{1}".format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | "-" * 75, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | # step 2: IDs |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | for id_ in self.__getIds(): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | if id_ not in alreadyDone: |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | css += "/* {0} */{1}".format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | "_".join(id_).lower(), |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | css += self.CssTemplate8.format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | "#", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | id_[1], |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | "{", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | os.linesep, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | indentation, |
30
38092622e612
Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
105 | random.choice(self.Placeholders) + os.linesep # secok |
6
a1600fa29542
A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
106 | if placeholders else os.linesep, |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | "}", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | alreadyDone.append(id_) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | css += "/*{0}*/{1}".format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | "-" * 75, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | # step 3: classes |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | for class_ in self.__getClasses(): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | if class_ not in alreadyDone: |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | css += "/* {0} */{1}".format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | "_".join(class_).lower(), |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | css += self.CssTemplate8.format( |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | ".", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | ", .".join(class_[1].split()), |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | "{", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | os.linesep, |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | indentation, |
30
38092622e612
Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
129 | random.choice(self.Placeholders) + os.linesep # secok |
6
a1600fa29542
A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
130 | if placeholders else os.linesep, |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | "}", |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | os.linesep |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | ) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | alreadyDone.append(class_) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | else: |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | css = "" |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | return css.strip() |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | def __createSoup(self): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | Private method to get a BeaitifulSoup object with our HTML text. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | from bs4 import BeautifulSoup |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | self.__soup = BeautifulSoup(BeautifulSoup(self.__html).prettify()) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | def __getTags(self): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | Private method to extract all tags of the HTML text. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
150 | @return list of all tags |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
151 | @rtype list of str |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | tags = [t.name for t in self.__soup.find_all(True)] |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | return list(set(tags)) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | def __getClasses(self): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | Private method to extract all classes of the HTML text. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | @return list of tuples containing the tag name and its classes |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
161 | as a blank separated string |
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
162 | @rtype list of tuples of (str, str) |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | classes = [(t.name, " ".join(t["class"])) for t in |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | self.__soup.find_all(True, {"class": True})] |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | return sorted(list(set(classes))) |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | def __getIds(self): |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | Private method to extract all IDs of the HTML text. |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | @return list of tuples containing the tag name and its ID |
38
6a12561fc0b5
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
173 | @rtype list of tuples of (str, str) |
1
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | """ |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | ids = [(t.name, t["id"]) for t in |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | self.__soup.find_all(True, {"id": True})] |
e3a92a671aa5
Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | return sorted(list(set(ids))) |