45 |
45 |
46 @keyparam tabSize size of tabs (integer) |
46 @keyparam tabSize size of tabs (integer) |
47 @keyparam useTabs flag indicating the use of tab characters (boolean) |
47 @keyparam useTabs flag indicating the use of tab characters (boolean) |
48 @keyparam wysiwyg flag indicating colorization (boolean) |
48 @keyparam wysiwyg flag indicating colorization (boolean) |
49 @keyparam folding flag indicating usage of fold markers |
49 @keyparam folding flag indicating usage of fold markers |
50 @keyparam onlyStylesUsed flag indicating to include only style definitions |
50 @keyparam onlyStylesUsed flag indicating to include only style |
51 for styles used in the source (boolean) |
51 definitions for styles used in the source (boolean) |
52 @keyparam titleFullPath flag indicating to include the full file path |
52 @keyparam titleFullPath flag indicating to include the full file path |
53 in the title tag (boolean) |
53 in the title tag (boolean) |
54 @return generated HTML text (string) |
54 @return generated HTML text (string) |
55 """ |
55 """ |
56 self.editor.recolor(0, -1) |
56 self.editor.recolor(0, -1) |
68 else: |
68 else: |
69 for index in range(QsciScintilla.STYLE_MAX + 1): |
69 for index in range(QsciScintilla.STYLE_MAX + 1): |
70 styleIsUsed[index] = True |
70 styleIsUsed[index] = True |
71 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True |
71 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True |
72 |
72 |
73 html = '''<!DOCTYPE html PUBLIC "-//W3C//DTD''' \ |
73 html = \ |
|
74 '''<!DOCTYPE html PUBLIC "-//W3C//DTD''' \ |
74 ''' XHTML 1.0 Transitional//EN"\n''' \ |
75 ''' XHTML 1.0 Transitional//EN"\n''' \ |
75 ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n''' \ |
76 ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">''' \ |
|
77 '''\n''' \ |
76 '''<html xmlns="http://www.w3.org/1999/xhtml">\n''' \ |
78 '''<html xmlns="http://www.w3.org/1999/xhtml">\n''' \ |
77 '''<head>\n''' |
79 '''<head>\n''' |
78 if titleFullPath: |
80 if titleFullPath: |
79 html += '''<title>{0}</title>\n'''.format(self.editor.getFileName()) |
81 html += '''<title>{0}</title>\n'''.format( |
|
82 self.editor.getFileName()) |
80 else: |
83 else: |
81 html += '''<title>{0}</title>\n'''.format( |
84 html += '''<title>{0}</title>\n'''.format( |
82 os.path.basename(self.editor.getFileName())) |
85 os.path.basename(self.editor.getFileName())) |
83 html += '''<meta name="Generator" content="eric5" />\n''' \ |
86 html += '''<meta name="Generator" content="eric5" />\n''' \ |
84 '''<meta http-equiv="Content-Type" ''' \ |
87 '''<meta http-equiv="Content-Type" ''' \ |
85 '''content="text/html; charset=utf-8" />\n''' |
88 '''content="text/html; charset=utf-8" />\n''' |
86 if folding: |
89 if folding: |
87 html += '''<script language="JavaScript" type="text/javascript">\n''' \ |
90 html += \ |
88 '''<!--\n''' \ |
91 '''<script language="JavaScript" type="text/javascript">\n''' \ |
89 '''function symbol(id, sym) {\n''' \ |
92 '''<!--\n''' \ |
90 ''' if (id.textContent == undefined) {\n''' \ |
93 '''function symbol(id, sym) {\n''' \ |
91 ''' id.innerText = sym;\n''' \ |
94 ''' if (id.textContent == undefined) {\n''' \ |
92 ''' } else {\n''' \ |
95 ''' id.innerText = sym;\n''' \ |
93 ''' id.textContent = sym;\n''' \ |
96 ''' } else {\n''' \ |
94 ''' }\n''' \ |
97 ''' id.textContent = sym;\n''' \ |
95 '''}\n''' \ |
98 ''' }\n''' \ |
96 '''function toggle(id) {\n''' \ |
99 '''}\n''' \ |
97 ''' var thislayer = document.getElementById('ln' + id);\n''' \ |
100 '''function toggle(id) {\n''' \ |
98 ''' id -= 1;\n''' \ |
101 ''' var thislayer = document.getElementById('ln' + id);\n''' \ |
99 ''' var togline = document.getElementById('hd' + id);\n''' \ |
102 ''' id -= 1;\n''' \ |
100 ''' var togsym = document.getElementById('bt' + id);\n''' \ |
103 ''' var togline = document.getElementById('hd' + id);\n''' \ |
101 ''' if (thislayer.style.display == 'none') {\n''' \ |
104 ''' var togsym = document.getElementById('bt' + id);\n''' \ |
102 ''' thislayer.style.display = 'block';\n''' \ |
105 ''' if (thislayer.style.display == 'none') {\n''' \ |
103 ''' togline.style.textDecoration = 'none';\n''' \ |
106 ''' thislayer.style.display = 'block';\n''' \ |
104 ''' symbol(togsym, '- ');\n''' \ |
107 ''' togline.style.textDecoration = 'none';\n''' \ |
105 ''' } else {\n''' \ |
108 ''' symbol(togsym, '- ');\n''' \ |
106 ''' thislayer.style.display = 'none';\n''' \ |
109 ''' } else {\n''' \ |
107 ''' togline.style.textDecoration = 'underline';\n''' \ |
110 ''' thislayer.style.display = 'none';\n''' \ |
108 ''' symbol(togsym, '+ ');\n''' \ |
111 ''' togline.style.textDecoration = 'underline';\n''' \ |
109 ''' }\n''' \ |
112 ''' symbol(togsym, '+ ');\n''' \ |
110 '''}\n''' \ |
113 ''' }\n''' \ |
111 '''//-->\n''' \ |
114 '''}\n''' \ |
112 '''</script>\n''' |
115 '''//-->\n''' \ |
|
116 '''</script>\n''' |
113 |
117 |
114 lex = self.editor.getLexer() |
118 lex = self.editor.getLexer() |
115 if lex: |
119 if lex: |
116 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT).name() |
120 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT).name() |
117 else: |
121 else: |
280 html += '''<span id="ln{0:d}">'''.format(line) |
284 html += '''<span id="ln{0:d}">'''.format(line) |
281 levelStack.append(newLevel) |
285 levelStack.append(newLevel) |
282 if self.editor.foldFlagsAt(line) & \ |
286 if self.editor.foldFlagsAt(line) & \ |
283 QsciScintilla.SC_FOLDLEVELHEADERFLAG: |
287 QsciScintilla.SC_FOLDLEVELHEADERFLAG: |
284 html += \ |
288 html += \ |
285 '''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''\ |
289 '''<span id="hd{0:d}"''' \ |
|
290 ''' onclick="toggle('{1:d}')">''' \ |
286 .format(line, line + 1) |
291 .format(line, line + 1) |
287 html += '''<span id="bt{0:d}">- </span>'''.format(line) |
292 html += '''<span id="bt{0:d}">- </span>'''.format(line) |
288 inFoldSpan = True |
293 inFoldSpan = True |
289 else: |
294 else: |
290 html += ''' ''' |
295 html += ''' ''' |
375 tabSize = Preferences.getEditor("TabWidth") |
380 tabSize = Preferences.getEditor("TabWidth") |
376 if tabSize == 0: |
381 if tabSize == 0: |
377 tabSize = 4 |
382 tabSize = 4 |
378 wysiwyg = Preferences.getEditorExporter("HTML/WYSIWYG") |
383 wysiwyg = Preferences.getEditorExporter("HTML/WYSIWYG") |
379 folding = Preferences.getEditorExporter("HTML/Folding") |
384 folding = Preferences.getEditorExporter("HTML/Folding") |
380 onlyStylesUsed = Preferences.getEditorExporter("HTML/OnlyStylesUsed") |
385 onlyStylesUsed = Preferences.getEditorExporter( |
381 titleFullPath = Preferences.getEditorExporter("HTML/FullPathAsTitle") |
386 "HTML/OnlyStylesUsed") |
|
387 titleFullPath = Preferences.getEditorExporter( |
|
388 "HTML/FullPathAsTitle") |
382 tabs = Preferences.getEditorExporter("HTML/UseTabs") |
389 tabs = Preferences.getEditorExporter("HTML/UseTabs") |
383 |
390 |
384 generator = HTMLGenerator(self.editor) |
391 generator = HTMLGenerator(self.editor) |
385 html = generator.generate( |
392 html = generator.generate( |
386 tabSize=tabSize, |
393 tabSize=tabSize, |
395 f = open(filename, "w", encoding="utf-8") |
402 f = open(filename, "w", encoding="utf-8") |
396 f.write(html) |
403 f.write(html) |
397 f.close() |
404 f.close() |
398 except IOError as err: |
405 except IOError as err: |
399 QApplication.restoreOverrideCursor() |
406 QApplication.restoreOverrideCursor() |
400 E5MessageBox.critical(self.editor, |
407 E5MessageBox.critical( |
|
408 self.editor, |
401 self.trUtf8("Export source"), |
409 self.trUtf8("Export source"), |
402 self.trUtf8( |
410 self.trUtf8( |
403 """<p>The source could not be exported to <b>{0}</b>.</p>""" |
411 """<p>The source could not be exported to""" |
404 """<p>Reason: {1}</p>""")\ |
412 """ <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
405 .format(filename, str(err))) |
413 .format(filename, str(err))) |
406 finally: |
414 finally: |
407 QApplication.restoreOverrideCursor() |
415 QApplication.restoreOverrideCursor() |