6 """ |
6 """ |
7 Module implementing functions to prepare an HTML documentation view. |
7 Module implementing functions to prepare an HTML documentation view. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication |
|
13 |
|
14 import Utilities |
|
15 |
11 |
16 |
12 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
17 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
13 """ |
18 """ |
14 Public function to prepare the HTML document. |
19 Public function to prepare the HTML document. |
15 |
20 |
67 name = documentationInfo["name"] |
72 name = documentationInfo["name"] |
68 if name: |
73 if name: |
69 title = titleTemplate.replace("@NAME@", name) |
74 title = titleTemplate.replace("@NAME@", name) |
70 if documentationInfo["argspec"] or documentationInfo["note"]: |
75 if documentationInfo["argspec"] or documentationInfo["note"]: |
71 if documentationInfo["argspec"]: |
76 if documentationInfo["argspec"]: |
|
77 argspec = Utilities.html_encode(documentationInfo["argspec"]) |
|
78 for char in ['=', ',', '(', ')', '*', '**']: |
|
79 argspec = argspec.replace( |
|
80 char, |
|
81 '<span class="argspec-highlight">{0}</span>'.format( |
|
82 char)) |
72 argspec = argspecTemplate\ |
83 argspec = argspecTemplate\ |
73 .replace("@NAME@", name)\ |
84 .replace("@NAME@", name)\ |
74 .replace("@ARGSPEC@", documentationInfo["argspec"]) |
85 .replace("@ARGSPEC@", argspec) |
75 else: |
86 else: |
76 argspec = "" |
87 argspec = "" |
77 if documentationInfo["note"]: |
88 if documentationInfo["note"]: |
78 note = noteTemplate.replace("@NOTE@", |
89 note = noteTemplate.replace("@NOTE@", |
79 documentationInfo["note"]) |
90 documentationInfo["note"]) |
96 .replace("\r\n", "<br/>")\ |
107 .replace("\r\n", "<br/>")\ |
97 .replace("\n", "<br/>")\ |
108 .replace("\n", "<br/>")\ |
98 .replace("\r", "<br/>") |
109 .replace("\r", "<br/>") |
99 docstring = docstringTemplate.replace("@DOCSTRING@", docstring) |
110 docstring = docstringTemplate.replace("@DOCSTRING@", docstring) |
100 else: |
111 else: |
101 docstring = "" |
112 docstring = \ |
|
113 """<div class="hr"></div><div id="doc-warning">{0}</div>"""\ |
|
114 .format(QCoreApplication.translate( |
|
115 "CodeDocumentationViewer", |
|
116 "No further documentation available")) |
102 |
117 |
103 return mainTemplate\ |
118 return mainTemplate\ |
104 .replace("@HEADER@", header)\ |
119 .replace("@HEADER@", header)\ |
105 .replace("@DOCSTRING@", docstring) |
120 .replace("@DOCSTRING@", docstring) |
106 |
121 |
107 def prepareDocumentationViewerHtmlWarningDocument(text): |
122 |
|
123 def prepareDocumentationViewerHtmlDocWarningDocument(text): |
108 """ |
124 """ |
109 Public function to prepare a HTML warning document. |
125 Public function to prepare a HTML warning document. |
110 |
126 |
111 @param text warning text to be shown |
127 @param text warning text to be shown |
112 @type str |
128 @type str |
126 </body> |
142 </body> |
127 </html> |
143 </html> |
128 """ |
144 """ |
129 |
145 |
130 return mainTemplate.replace("@TEXT@", text) |
146 return mainTemplate.replace("@TEXT@", text) |
|
147 |
|
148 |
|
149 def prepareDocumentationViewerHtmlWarningDocument(text): |
|
150 """ |
|
151 Public function to prepare a HTML warning document. |
|
152 |
|
153 @param text warning text to be shown |
|
154 @type str |
|
155 @return prepared HTML document |
|
156 @rtype str |
|
157 """ |
|
158 mainTemplate = """ |
|
159 <!DOCTYPE html> |
|
160 <html> |
|
161 <head> |
|
162 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
163 <link rel="stylesheet" href="qrc:documentViewerStyle.css" |
|
164 type="text/css" /> |
|
165 </head> |
|
166 <body> |
|
167 <div id="warning">@TEXT@</div> |
|
168 </body> |
|
169 </html> |
|
170 """ |
|
171 |
|
172 return mainTemplate.replace("@TEXT@", text) |