QScintilla/Exporters/ExporterHTML.py

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

eric ide

mercurial