eric6/QScintilla/Exporters/ExporterHTML.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7836
2f0d208b8137
child 8043
0acf98cd089a
permissions
-rw-r--r--

Updated copyright for 2021.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
3 # Copyright (c) 2007 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an exporter for HTML.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 # This code is a port of the C++ code found in SciTE 1.74
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 # Original code: Copyright 1998-2006 by Neil Hodgson <neilh@scintilla.org>
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import os
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
14 import sys
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
15 import io
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
17 from PyQt5.QtGui import QFontInfo
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
18 from PyQt5.QtWidgets import QInputDialog
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
19 from PyQt5.Qsci import QsciScintilla
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
21 from E5Gui import E5MessageBox
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
22 from E5Gui.E5OverrideCursor import E5OverrideCursor
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
23
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
24 from .ExporterBase import ExporterBase
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
29
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
30 class HTMLGenerator(object):
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
31 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
32 Class implementing an HTML generator for exporting source code.
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
33 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
34 def __init__(self, editor):
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
35 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
36 Constructor
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
37
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
38 @param editor reference to the editor object (QScintilla.Editor.Editor)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
39 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
40 self.editor = editor
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
41
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 def generate(self, tabSize=4, useTabs=False, wysiwyg=True, folding=False,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
43 onlyStylesUsed=False, titleFullPath=False):
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
44 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
45 Public method to generate HTML for the source editor.
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
46
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
47 @keyparam tabSize size of tabs (integer)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
48 @keyparam useTabs flag indicating the use of tab characters (boolean)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
49 @keyparam wysiwyg flag indicating colorization (boolean)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
50 @keyparam folding flag indicating usage of fold markers
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 @keyparam onlyStylesUsed flag indicating to include only style
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
52 definitions for styles used in the source (boolean)
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
53 @keyparam titleFullPath flag indicating to include the full file path
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
54 in the title tag (boolean)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
55 @return generated HTML text (string)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
56 """
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
57 self.editor.recolor(0, -1)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
58
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
59 lengthDoc = self.editor.length()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
60 styleIsUsed = {}
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
61 if onlyStylesUsed:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
62 for index in range(QsciScintilla.STYLE_MAX + 1):
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
63 styleIsUsed[index] = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
64 # check the used styles
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
65 pos = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
66 while pos < lengthDoc:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
67 styleIsUsed[self.editor.styleAt(pos) & 0x7F] = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
68 pos += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
69 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
70 for index in range(QsciScintilla.STYLE_MAX + 1):
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
71 styleIsUsed[index] = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
72 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
73
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
74 html = (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
75 '''<!DOCTYPE html PUBLIC "-//W3C//DTD'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
76 ''' XHTML 1.0 Transitional//EN"\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
77 ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
78 '''\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
79 '''<html xmlns="http://www.w3.org/1999/xhtml">\n'''
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
80 '''<head>\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
81 )
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
82 if titleFullPath:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
83 html += '''<title>{0}</title>\n'''.format(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
84 self.editor.getFileName())
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
85 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
86 html += '''<title>{0}</title>\n'''.format(
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
87 os.path.basename(self.editor.getFileName()))
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
88 html += (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
89 '''<meta name="Generator" content="eric6" />\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
90 '''<meta http-equiv="Content-Type" '''
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
91 '''content="text/html; charset=utf-8" />\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
92 )
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
93 if folding:
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
94 html += (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
95 '''<script language="JavaScript" type="text/javascript">\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
96 '''<!--\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
97 '''function symbol(id, sym) {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
98 ''' if (id.textContent == undefined) {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
99 ''' id.innerText = sym;\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
100 ''' } else {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
101 ''' id.textContent = sym;\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
102 ''' }\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
103 '''}\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
104 '''function toggle(id) {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
105 ''' var thislayer = document.getElementById('ln' + id);\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
106 ''' id -= 1;\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
107 ''' var togline = document.getElementById('hd' + id);\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
108 ''' var togsym = document.getElementById('bt' + id);\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
109 ''' if (thislayer.style.display == 'none') {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
110 ''' thislayer.style.display = 'block';\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
111 ''' togline.style.textDecoration = 'none';\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
112 ''' symbol(togsym, '- ');\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
113 ''' } else {\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
114 ''' thislayer.style.display = 'none';\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
115 ''' togline.style.textDecoration = 'underline';\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
116 ''' symbol(togsym, '+ ');\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
117 ''' }\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
118 '''}\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
119 '''//-->\n'''
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
120 '''</script>\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
121 )
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
122
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
123 lex = self.editor.getLexer()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
124 if lex:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
125 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT).name()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
126 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
127 bgColour = self.editor.paper().name()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
128
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
129 html += '''<style type="text/css">\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
130 if lex:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
131 istyle = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
132 while istyle <= QsciScintilla.STYLE_MAX:
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
133 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
134 (istyle <= QsciScintilla.STYLE_DEFAULT or
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
135 istyle > QsciScintilla.STYLE_LASTPREDEFINED) and
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
136 styleIsUsed[istyle]
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
137 ):
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
138 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
139 lex.description(istyle) or
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
140 istyle == QsciScintilla.STYLE_DEFAULT
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 ):
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
142 font = lex.font(istyle)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
143 colour = lex.color(istyle)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
144 paper = lex.paper(istyle)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
145 if istyle == QsciScintilla.STYLE_DEFAULT:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
146 html += '''span {\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
147 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
148 html += '''.S{0:d} {{\n'''.format(istyle)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
149 if font.italic():
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
150 html += ''' font-style: italic;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
151 if font.bold():
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
152 html += ''' font-weight: bold;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
153 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
154 html += ''' font-family: '{0}';\n'''.format(
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
155 font.family())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
156 html += ''' color: {0};\n'''.format(colour.name())
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
157 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
158 istyle != QsciScintilla.STYLE_DEFAULT and
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 bgColour != paper.name()
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
160 ):
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
161 html += ''' background: {0};\n'''.format(
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
162 paper.name())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
163 html += ''' text-decoration: inherit;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
164 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
165 html += ''' font-size: {0:d}pt;\n'''.format(
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
166 QFontInfo(font).pointSize())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
167 html += '''}\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
168 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
169 styleIsUsed[istyle] = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
170 istyle += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
171 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
172 colour = self.editor.color()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
173 paper = self.editor.paper()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
174 font = Preferences.getEditorOtherFonts("DefaultFont")
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
175 html += '''.S0 {\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
176 if font.italic():
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
177 html += ''' font-style: italic;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
178 if font.bold():
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
179 html += ''' font-weight: bold;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
180 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
181 html += ''' font-family: '{0}';\n'''.format(font.family())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
182 html += ''' color: {0};\n'''.format(colour.name())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
183 if bgColour != paper.name():
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
184 html += ''' background: {0};\n'''.format(paper.name())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
185 html += ''' text-decoration: inherit;\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
186 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
187 html += ''' font-size: {0:d}pt;\n'''.format(
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
188 QFontInfo(font).pointSize())
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
189 html += '''}\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
190 html += '''</style>\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
191 html += '''</head>\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
192
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
193 html += '''<body bgcolor="{0}">\n'''.format(bgColour)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
194 line = self.editor.lineAt(0)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
195 level = self.editor.foldLevelAt(line) - QsciScintilla.SC_FOLDLEVELBASE
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
196 levelStack = [level]
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
197 styleCurrent = self.editor.styleAt(0)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
198 inStyleSpan = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
199 inFoldSpan = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
200 # Global span for default attributes
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
201 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
202 html += '''<span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
203 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
204 html += '''<pre>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
205
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
206 if folding:
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
207 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
208 self.editor.foldFlagsAt(line) &
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
209 QsciScintilla.SC_FOLDLEVELHEADERFLAG
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
210 ):
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
211 html += (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
212 '''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
213 ).format(line, line + 1)
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
214 html += '''<span id="bt{0:d}">- </span>'''.format(line)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
215 inFoldSpan = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
216 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
217 html += '''&nbsp; '''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
218
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
219 if styleIsUsed[styleCurrent]:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
220 html += '''<span class="S{0:0d}">'''.format(styleCurrent)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
221 inStyleSpan = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
222
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
223 column = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
224 pos = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
225 utf8 = self.editor.isUtf8()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
226 utf8Ch = b""
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
227 utf8Len = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
228
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
229 while pos < lengthDoc:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
230 ch = self.editor.byteAt(pos)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
231 style = self.editor.styleAt(pos)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
232 if style != styleCurrent:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
233 if inStyleSpan:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
234 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
235 inStyleSpan = False
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
236 if ch not in [b'\r', b'\n']: # no need of a span for the EOL
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
237 if styleIsUsed[style]:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
238 html += '''<span class="S{0:d}">'''.format(style)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
239 inStyleSpan = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
240 styleCurrent = style
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
241
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
242 if ch == b' ':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
243 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
244 prevCh = b''
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
245 if column == 0:
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
246 # at start of line, must put a &nbsp;
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
247 # because regular space will be collapsed
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
248 prevCh = b' '
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
249 while pos < lengthDoc and self.editor.byteAt(pos) == b' ':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
250 if prevCh != b' ':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
251 html += ' '
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
252 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
253 html += '''&nbsp;'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
254 prevCh = self.editor.byteAt(pos)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
255 pos += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
256 column += 1
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
257 pos -= 1
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
258 # the last incrementation will be done by the outer loop
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
259 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
260 html += ' '
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
261 column += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
262 elif ch == b'\t':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
263 ts = tabSize - (column % tabSize)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
264 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
265 html += '''&nbsp;''' * ts
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
266 column += ts
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
267 else:
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
268 if useTabs:
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
269 html += '\t'
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
270 column += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
271 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
272 html += ' ' * ts
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
273 column += ts
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
274 elif ch in [b'\r', b'\n']:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
275 if inStyleSpan:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
276 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
277 inStyleSpan = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
278 if inFoldSpan:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
279 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
280 inFoldSpan = False
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
281 if ch == b'\r' and self.editor.byteAt(pos + 1) == b'\n':
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
282 pos += 1 # CR+LF line ending, skip the "extra" EOL char
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
283 column = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
284 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
285 html += '''<br />'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
286
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
287 styleCurrent = self.editor.styleAt(pos + 1)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
288 if folding:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
289 line = self.editor.lineAt(pos + 1)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
290 newLevel = self.editor.foldLevelAt(line)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
291
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
292 if newLevel < level:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
293 while levelStack[-1] > newLevel:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
294 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
295 levelStack.pop()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
296 html += '\n' # here to get clean code
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
297 if newLevel > level:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
298 html += '''<span id="ln{0:d}">'''.format(line)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
299 levelStack.append(newLevel)
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
300 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
301 self.editor.foldFlagsAt(line) &
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
302 QsciScintilla.SC_FOLDLEVELHEADERFLAG
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
303 ):
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
304 html += (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
305 '''<span id="hd{0:d}"'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
306 ''' onclick="toggle('{1:d}')">'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
307 ).format(line, line + 1)
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
308 html += '''<span id="bt{0:d}">- </span>'''.format(line)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
309 inFoldSpan = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
310 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
311 html += '''&nbsp; '''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
312 level = newLevel
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
313 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
314 html += '\n'
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
315
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
316 if (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
317 styleIsUsed[styleCurrent] and
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
318 self.editor.byteAt(pos + 1) not in [b'\r', b'\n']
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
319 ):
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
320 # We know it's the correct next style,
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
321 # but no (empty) span for an empty line
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
322 html += '''<span class="S{0:0d}">'''.format(styleCurrent)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
323 inStyleSpan = True
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
324 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
325 if ch == b'<':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
326 html += '''&lt;'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
327 elif ch == b'>':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
328 html += '''&gt'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
329 elif ch == b'&':
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
330 html += '''&amp;'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
331 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
332 if ord(ch) > 127 and utf8:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
333 utf8Ch += ch
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
334 if utf8Len == 0:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
335 if (utf8Ch[0] & 0xF0) == 0xF0:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
336 utf8Len = 4
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
337 elif (utf8Ch[0] & 0xE0) == 0xE0:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
338 utf8Len = 3
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
339 elif (utf8Ch[0] & 0xC0) == 0xC0:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
340 utf8Len = 2
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
341 column -= 1 # will be incremented again later
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
342 elif len(utf8Ch) == utf8Len:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
343 ch = utf8Ch.decode('utf8')
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
344 html += Utilities.html_encode(ch)
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
345 utf8Ch = b""
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
346 utf8Len = 0
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
347 else:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
348 column -= 1 # will be incremented again later
532
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
349 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
350 html += ch.decode()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
351 column += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
352
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
353 pos += 1
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
354
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
355 if inStyleSpan:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
356 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
357
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
358 if folding:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
359 while levelStack:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
360 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
361 levelStack.pop()
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
362
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
363 if wysiwyg:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
364 html += '''</span>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
365 else:
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
366 html += '''</pre>'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
367
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
368 html += '''</body>\n</html>\n'''
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
369
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
370 return html
a3c0f1e2594a Added a source code exporter for the Open Document Text (ODT) format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
371
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
372
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 class ExporterHTML(ExporterBase):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 Class implementing an exporter for HTML.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
377 def __init__(self, editor, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 @param editor reference to the editor object (QScintilla.Editor.Editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 @param parent parent object of the exporter (QObject)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 ExporterBase.__init__(self, editor, parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 def exportSource(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 Public method performing the export.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 """
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
390 filename = self._getFileName(self.tr("HTML Files (*.html)"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 if not filename:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
394 fn = self.editor.getFileName()
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
395 if fn:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
396 extension = os.path.normcase(os.path.splitext(fn)[1][1:])
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
397 else:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
398 extension = ""
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
399
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
400 if (
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
401 extension in Preferences.getEditor(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
402 "PreviewMarkdownFileNameExtensions") or
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
403 self.editor.getLanguage().lower() == "markdown"
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
404 ):
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
405 # export markdown to HTML
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
406 colorSchemes = [
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
407 self.tr("Light Background Color"),
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
408 self.tr("Dark Background Color"),
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
409 ]
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
410 colorScheme, ok = QInputDialog.getItem(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
411 None,
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
412 self.tr("Markdown Export"),
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
413 self.tr("Select color scheme:"),
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
414 colorSchemes,
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
415 0, False)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
416 if ok:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
417 colorSchemeIndex = colorSchemes.index(colorScheme)
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
418 else:
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
419 # light background as default
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
420 colorSchemeIndex = 0
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
421 with E5OverrideCursor():
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
422 html = self.__generateFromMarkdown(colorSchemeIndex == 1)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
423 elif (
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
424 extension in Preferences.getEditor(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
425 "PreviewRestFileNameExtensions") or
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
426 self.editor.getLanguage().lower() == "restructuredtext"
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
427 ):
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
428 # export ReST to HTML
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
429 with E5OverrideCursor():
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
430 html = self.__generateFromReSTDocutils()
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
431 else:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
432 tabSize = self.editor.getEditorConfig("TabWidth")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
433 if tabSize == 0:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
434 tabSize = 4
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
435 wysiwyg = Preferences.getEditorExporter("HTML/WYSIWYG")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
436 folding = Preferences.getEditorExporter("HTML/Folding")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
437 onlyStylesUsed = Preferences.getEditorExporter(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
438 "HTML/OnlyStylesUsed")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
439 titleFullPath = Preferences.getEditorExporter(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
440 "HTML/FullPathAsTitle")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
441 tabs = Preferences.getEditorExporter("HTML/UseTabs")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
443 with E5OverrideCursor():
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
444 generator = HTMLGenerator(self.editor)
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
445 html = generator.generate(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
446 tabSize=tabSize,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
447 useTabs=tabs,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
448 wysiwyg=wysiwyg,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
449 folding=folding,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
450 onlyStylesUsed=onlyStylesUsed,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
451 titleFullPath=titleFullPath
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
452 )
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
453
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
454 if html:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
455 try:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
456 with E5OverrideCursor():
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
457 with open(filename, "w", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
458 f.write(html)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
459 except OSError as err:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
460 E5MessageBox.critical(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
461 self.editor,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
462 self.tr("Export source"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
463 self.tr(
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
464 """<p>The source could not be exported to"""
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
465 """ <b>{0}</b>.</p><p>Reason: {1}</p>""")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
466 .format(filename, str(err)))
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
467 else:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
468 E5MessageBox.critical(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
469 self.editor,
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
470 self.tr("Export source"),
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
471 self.tr(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
472 """<p>The source could not be exported to"""
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
473 """ <b>{0}</b>.</p><p>Reason: No HTML code"""
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
474 """ generated.</p>""")
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7524
diff changeset
475 .format(filename))
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
476
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
477 def __generateFromReSTDocutils(self):
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
478 """
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
479 Private method to convert ReST text into HTML using 'docutils'.
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
480
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
481 @return processed HTML (string)
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
482 """
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
483 if 'sphinx' in sys.modules:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
484 # Make sure any Sphinx polution of docutils has been removed.
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
485 unloadKeys = [k for k in sys.modules.keys()
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
486 if k.startswith(('docutils', 'sphinx'))]
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
487 for key in unloadKeys:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
488 sys.modules.pop(key)
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
489
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
490 try:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
491 import docutils.core # __IGNORE_EXCEPTION__
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
492 except ImportError:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
493 E5MessageBox.critical(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
494 self.editor,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
495 self.tr("Export source"),
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
496 self.tr(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
497 """<p>ReStructuredText export requires the"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
498 """ <b>python-docutils</b> package.<br/>Install it with"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
499 """ your package manager, 'pip install docutils' or see"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
500 """ <a href="http://pypi.python.org/pypi/docutils">"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
501 """this page.</a></p>""")
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
502 )
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
503 return ""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
504
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
505 htmlFormat = Preferences.getEditor(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
506 "PreviewRestDocutilsHTMLFormat").lower()
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
507 # redirect sys.stderr because we are not interested in it here
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
508 origStderr = sys.stderr
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
509 sys.stderr = io.StringIO()
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
510 html = docutils.core.publish_string(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
511 self.editor.text(), writer_name=htmlFormat).decode("utf-8")
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
512 sys.stderr = origStderr
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
513 return html
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
514
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
515 def __generateFromMarkdown(self, useDarkScheme):
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
516 """
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
517 Private method to convert Markdown text into HTML.
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
518
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
519 @param useDarkScheme flag indicating to export using a dark color
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
520 scheme
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
521 @type bool
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
522 @return processed HTML
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
523 @rtype str
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
524 """
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
525 try:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
526 import markdown # __IGNORE_EXCEPTION__
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
527 except ImportError:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
528 E5MessageBox.critical(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
529 self.editor,
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
530 self.tr("Export source"),
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
531 self.tr(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
532 """<p>Markdown export requires the <b>python-markdown"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
533 """</b> package.<br/>Install it with your package"""
5861
26250d8ff4e4 Fixed some typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5837
diff changeset
534 """ manager, 'pip install docutils' or see """
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
535 """<a href="http://pythonhosted.org/Markdown/install"""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
536 """.html"> installation instructions.</a></p>""")
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
537 )
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
538 return ""
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
539
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
540 from UI.Previewers import PreviewerHTMLStyles
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
541 from UI.Previewers import MarkdownExtensions
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
542
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
543 extensions = []
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
544
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
545 text = self.editor.text()
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
546
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
547 mermaidNeeded = False
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
548 if Preferences.getEditor("PreviewMarkdownMermaid"):
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
549 if MarkdownExtensions.MermaidRegexFullText.search(text):
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
550 extensions.append(MarkdownExtensions.MermaidExtension())
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
551 mermaidNeeded = True
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
552
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
553 if Preferences.getEditor("PreviewMarkdownNLtoBR"):
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
554 extensions.append('nl2br')
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
555
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
556 pyMdown = False
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
557 if Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions"):
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
558 try:
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
559 import pymdownx # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
560 # PyPI package is 'pymdown-extensions'
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
561
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
562 extensions.extend([
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
563 'toc',
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
564 'pymdownx.extra', 'pymdownx.caret', 'pymdownx.emoji',
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
565 'pymdownx.mark', 'pymdownx.tilde', 'pymdownx.keys',
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
566 'pymdownx.tasklist', 'pymdownx.smartsymbols',
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
567 ])
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
568 pyMdown = True
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
569 except ImportError:
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
570 pass
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
571
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
572 if not pyMdown:
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
573 extensions.extend(['extra', 'toc'])
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
574
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
575 # version 2.0 supports only extension names, not instances
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
576 if (
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
577 markdown.version_info[0] > 2 or
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
578 (markdown.version_info[0] == 2 and
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
579 markdown.version_info[1] > 0)
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
580 ):
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
581 extensions.append(MarkdownExtensions.SimplePatternExtension())
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
582
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
583 if Preferences.getEditor("PreviewMarkdownMathJax"):
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
584 mathjax = (
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
585 "<script type='text/javascript' id='MathJax-script' async"
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
586 " src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/"
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
587 "tex-chtml.js'>\n"
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
588 "</script>\n"
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
589 )
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
590 # prepare text for mathjax
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
591 text = (
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
592 text
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
593 .replace(r"\(", r"\\(")
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
594 .replace(r"\)", r"\\)")
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
595 .replace(r"\[", r"\\[")
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
596 .replace(r"\]", r"\\]")
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
597 )
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
598 else:
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
599 mathjax = ""
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
600
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
601 if mermaidNeeded:
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
602 mermaid = (
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
603 "<script type='text/javascript' id='Mermaid-script'"
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
604 " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n"
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
605 "</script>\n"
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
606 )
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
607 if useDarkScheme:
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
608 mermaid_initialize = (
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
609 "<script>mermaid.initialize({"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
610 "theme: 'dark', "
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
611 "startOnLoad:true"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
612 "});</script>"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
613 )
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
614 else:
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
615 mermaid_initialize = (
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
616 "<script>mermaid.initialize({"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
617 "theme: 'default', "
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
618 "startOnLoad:true"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
619 "});</script>"
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
620 )
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
621 else:
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
622 mermaid = ""
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
623 mermaid_initialize = ""
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
624
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
625 htmlFormat = Preferences.getEditor("PreviewMarkdownHTMLFormat").lower()
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
626 body = markdown.markdown(text, extensions=extensions,
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
627 output_format=htmlFormat)
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
628 if useDarkScheme:
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
629 style = (
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
630 PreviewerHTMLStyles.css_markdown_dark +
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
631 PreviewerHTMLStyles.css_pygments_dark
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
632 )
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
633 else:
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
634 style = (
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
635 PreviewerHTMLStyles.css_markdown_light +
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
636 PreviewerHTMLStyles.css_pygments_light
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
637 )
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
638
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
639 if htmlFormat == "xhtml1":
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
640 head = (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
641 '''<!DOCTYPE html PUBLIC "-//W3C//DTD'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
642 ''' XHTML 1.0 Transitional//EN"\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
643 ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
644 '''.dtd">\n'''
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
645 '''<html xmlns="http://www.w3.org/1999/xhtml">\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
646 )
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
647 elif htmlFormat == "html5":
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
648 head = (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
649 '''<!DOCTYPE html>\n'''
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
650 '''<html lang="EN">\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
651 )
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
652 else:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
653 head = '<html lang="EN">\n'
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
654 head += '''<head>\n'''
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
655 if Preferences.getEditorExporter("HTML/FullPathAsTitle"):
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
656 head += '''<title>{0}</title>\n'''.format(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
657 self.editor.getFileName())
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
658 else:
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
659 head += '''<title>{0}</title>\n'''.format(
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
660 os.path.basename(self.editor.getFileName()))
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
661 head += (
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
662 '''<meta name="Generator" content="eric6" />\n'''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
663 '''<meta http-equiv="Content-Type" '''
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
664 '''content="text/html; charset=utf-8" />\n'''
7305
928858251f7a ExporterHTML: copied the Markdown changes to the exporter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
665 '''{0}'''
7309
5a434813eef3 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7305
diff changeset
666 '''{1}'''
7314
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
667 '''<style type="text/css">'''
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
668 '''{2}'''
c32c24345ca7 PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7309
diff changeset
669 '''</style>\n'''
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
670 '''</head>\n'''
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
671 '''<body>\n'''
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
672 ).format(mathjax, mermaid, style)
5837
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
673
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
674 foot = '''\n</body>\n</html>\n'''
9ef6a28f1694 - Exporter
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
675
7524
282680dae446 HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
676 return head + body + mermaid_initialize + foot

eric ide

mercurial