Mon, 24 Feb 2025 15:43:49 +0100
Adjusted the code to the modified issue codes.
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11059
diff
changeset
|
3 | # Copyright (c) 2014 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
3459
275cb00c83e2
Continued adding QSS preview support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3458
diff
changeset
|
7 | Module implementing a previewer widget for HTML, Markdown and ReST files. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
10496
f9925e08dbce
Changed some import statements for 'importlib' to 'importlib.util' because sometimes the first doesn't work properly (reason unknown but somewhere in the interpreter).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
10 | import importlib.util |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
11 | import io |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | import os |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | import re |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
14 | import shutil |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
15 | import sys |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
16 | import tempfile |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
17 | import threading |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
19 | from PyQt6.QtCore import QEventLoop, QPoint, Qt, QThread, QUrl, pyqtSignal, pyqtSlot |
9447 | 20 | from PyQt6.QtGui import QCursor, QGuiApplication |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
21 | from PyQt6.QtWidgets import ( |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
22 | QCheckBox, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
23 | QGridLayout, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | QLabel, |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
25 | QPushButton, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
26 | QSizePolicy, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
27 | QToolTip, |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
28 | QVBoxLayout, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9447
diff
changeset
|
29 | QWidget, |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
30 | ) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
32 | from eric7 import Preferences |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9268
diff
changeset
|
33 | from eric7.EricWidgets.EricApplication import ericApp |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
34 | from eric7.SystemUtilities import FileSystemUtilities |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
37 | class PreviewerHTML(QWidget): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Class implementing a previewer widget for HTML, Markdown and ReST files. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | def __init__(self, parent=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
46 | @param parent reference to the parent widget |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
47 | @type QWidget |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
49 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
51 | self.__layout = QVBoxLayout(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
53 | self.titleLabel = QLabel(self) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
54 | self.titleLabel.setWordWrap(True) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7960
diff
changeset
|
55 | self.titleLabel.setTextInteractionFlags( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
56 | Qt.TextInteractionFlag.NoTextInteraction |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
57 | ) |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
58 | self.__layout.addWidget(self.titleLabel) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
59 | |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
60 | self.__previewAvailable = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
62 | try: |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
63 | from PyQt6.QtWebEngineWidgets import ( # __IGNORE_WARNING_I-10__ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
64 | QWebEngineView, |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
65 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
67 | self.previewView = QWebEngineView(self) |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
68 | self.previewView.page().linkHovered.connect(self.__showLink) |
11059
ecc945948048
Changed code of the HTML previewer to have JavaScript always enabled because that is needed for its functionality (see issue 570).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10496
diff
changeset
|
69 | |
ecc945948048
Changed code of the HTML previewer to have JavaScript always enabled because that is needed for its functionality (see issue 570).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10496
diff
changeset
|
70 | settings = self.previewView.settings() |
ecc945948048
Changed code of the HTML previewer to have JavaScript always enabled because that is needed for its functionality (see issue 570).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10496
diff
changeset
|
71 | settings.setAttribute(settings.WebAttribute.JavascriptEnabled, True) |
ecc945948048
Changed code of the HTML previewer to have JavaScript always enabled because that is needed for its functionality (see issue 570).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10496
diff
changeset
|
72 | # JavaScript needs to be enabled. |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
73 | except ImportError: |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
74 | self.__previewAvailable = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | self.titleLabel.setText( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | "<b>HTML Preview is not available!<br/>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | "Install PyQt6-WebEngine.</b>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7960
diff
changeset
|
81 | self.titleLabel.setAlignment(Qt.AlignmentFlag.AlignHCenter) |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
82 | self.__layout.addStretch() |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
83 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
84 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
85 | sizePolicy = QSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | ) |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
88 | sizePolicy.setHorizontalStretch(0) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
89 | sizePolicy.setVerticalStretch(0) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
90 | sizePolicy.setHeightForWidth(self.previewView.sizePolicy().hasHeightForWidth()) |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
91 | self.previewView.setSizePolicy(sizePolicy) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | self.previewView.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu) |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
93 | self.previewView.setUrl(QUrl("about:blank")) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
94 | self.__layout.addWidget(self.previewView) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
95 | |
9447 | 96 | self.__footerLayout = QGridLayout() |
97 | sizePolicy = QSizePolicy( | |
98 | QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred | |
99 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
100 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | self.ssiCheckBox = QCheckBox(self.tr("Enable Server Side Includes"), self) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | self.ssiCheckBox.setToolTip( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | self.tr("Select to enable support for Server Side Includes") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
104 | ) |
9447 | 105 | self.ssiCheckBox.setSizePolicy(sizePolicy) |
106 | self.__footerLayout.addWidget(self.ssiCheckBox, 1, 0) | |
107 | self.__htmlButton = QPushButton(self.tr("Copy HTML"), self) | |
108 | self.__htmlButton.setToolTip( | |
109 | self.tr("Press to copy the HTML text of the preview to the clipboard") | |
110 | ) | |
111 | self.__htmlButton.setEnabled(False) | |
112 | self.__footerLayout.addWidget(self.__htmlButton, 1, 1) | |
113 | self.__layout.addLayout(self.__footerLayout) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
115 | self.ssiCheckBox.clicked[bool].connect(self.on_ssiCheckBox_clicked) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
116 | self.previewView.titleChanged.connect(self.on_previewView_titleChanged) |
9447 | 117 | self.__htmlButton.clicked.connect(self.on_htmlButton_clicked) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
119 | self.ssiCheckBox.setChecked(Preferences.getUI("ShowFilePreviewSSI")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | self.__scrollBarPositions = {} |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | self.__vScrollBarAtEnd = {} |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | self.__hScrollBarAtEnd = {} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | self.__processingThread = PreviewProcessingThread() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | self.__processingThread.htmlReady.connect(self.__setHtml) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | self.__previewedPath = None |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | self.__previewedEditor = None |
9447 | 130 | self.__previewedHtml = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | def shutdown(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | Public method to perform shutdown actions. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | """ |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
136 | if self.__previewAvailable: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
137 | self.__processingThread.wait() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
138 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | @pyqtSlot(bool) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | def on_ssiCheckBox_clicked(self, checked): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | Private slot to enable/disable SSI. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
144 | @param checked state of the checkbox |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
145 | @type bool |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | Preferences.setUI("ShowFilePreviewSSI", checked) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | self.processEditor() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
149 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
150 | @pyqtSlot(str) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
151 | def __showLink(self, urlStr): |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
152 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
153 | Private slot to show the hovered link in a tooltip. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
154 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
155 | @param urlStr hovered URL |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
156 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
157 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
158 | QToolTip.showText(QCursor.pos(), urlStr, self.previewView) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
159 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | def processEditor(self, editor=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
162 | Public slot to process an editor's text. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
163 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
164 | @param editor editor to be processed |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
165 | @type Editor |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | """ |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
167 | if not self.__previewAvailable: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
168 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
169 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | if editor is None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | editor = self.__previewedEditor |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | self.__previewedEditor = editor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
174 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | if editor is not None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | fn = editor.getFileName() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
177 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | if fn: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | extension = "" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
182 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
183 | extension in Preferences.getEditor("PreviewHtmlFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
184 | or editor.getLanguage() == "HTML" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
185 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | language = "HTML" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
187 | elif ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
188 | extension in Preferences.getEditor("PreviewMarkdownFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | or editor.getLanguage().lower() == "markdown" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
190 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | language = "Markdown" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
192 | elif ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
193 | extension in Preferences.getEditor("PreviewRestFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
194 | or editor.getLanguage().lower() == "restructuredtext" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
195 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | language = "ReST" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
198 | self.__setHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
199 | fn, self.tr("<p>No preview available for this type of file.</p>") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
200 | ) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
202 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | if fn: |
8600
f95586787d90
PreviewerHTML: changed the determination of the root path for the editor to be previewed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
204 | rootPath = os.path.dirname(os.path.abspath(fn)) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | rootPath = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
207 | |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
208 | if bool(editor.text()): |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
209 | self.__processingThread.process( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
210 | fn, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
211 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
212 | editor.text(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
213 | self.ssiCheckBox.isChecked(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
214 | rootPath, |
5837 | 215 | Preferences.getEditor("PreviewRestUseSphinx"), |
216 | Preferences.getEditor("PreviewMarkdownNLtoBR"), | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
217 | Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions"), |
5837 | 218 | Preferences.getEditor("PreviewMarkdownHTMLFormat"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | Preferences.getEditor("PreviewRestDocutilsHTMLFormat"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
220 | ) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
222 | def __setHtml(self, filePath, html, rootPath): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | Private method to set the HTML to the view and restore the scroll bars |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | positions. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
226 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
227 | @param filePath file path of the previewed editor |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
228 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
229 | @param html processed HTML text ready to be shown |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
230 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
231 | @param rootPath path of the web site root |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
232 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | """ |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
234 | self.__previewedPath = FileSystemUtilities.normcasepath( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
235 | FileSystemUtilities.fromNativeSeparators(filePath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
236 | ) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
237 | self.__saveScrollBarPositions() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
238 | self.previewView.page().loadFinished.connect(self.__restoreScrollBarPositions) |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
239 | if not filePath: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
240 | filePath = "/" |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
241 | baseUrl = ( |
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
242 | QUrl.fromLocalFile(rootPath + "/index.html") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
243 | if rootPath |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
244 | else QUrl.fromLocalFile(filePath) |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
245 | ) |
9447 | 246 | self.__previewedHtml = html |
247 | self.__htmlButton.setEnabled(bool(html)) | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
248 | self.previewView.setHtml(html, baseUrl=baseUrl) |
4929
fcab21c80811
Fixed the focus stealing issue with the QtWebEngine based HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
249 | if self.__previewedEditor: |
fcab21c80811
Fixed the focus stealing issue with the QtWebEngine based HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
250 | self.__previewedEditor.setFocus() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
251 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | @pyqtSlot(str) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | def on_previewView_titleChanged(self, title): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | Private slot to handle a change of the title. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
257 | @param title new title |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
258 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | if title: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | self.titleLabel.setText(self.tr("Preview - {0}").format(title)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | self.titleLabel.setText(self.tr("Preview")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
264 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | def __saveScrollBarPositions(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | Private method to save scroll bar positions for a previewed editor. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | """ |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
269 | try: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
270 | pos = self.previewView.scrollPosition() |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
271 | except AttributeError: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
272 | pos = self.__execJavaScript( |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
273 | "(function() {" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
274 | "var res = {" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
275 | " x: 0," |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
276 | " y: 0," |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
277 | "};" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
278 | "res.x = window.scrollX;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
279 | "res.y = window.scrollY;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
280 | "return res;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
281 | "})()" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
282 | ) |
8235
78e6d29eb773
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 3).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8227
diff
changeset
|
283 | pos = QPoint(0, 0) if pos is None else QPoint(pos["x"], pos["y"]) |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
284 | self.__scrollBarPositions[self.__previewedPath] = pos |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
285 | self.__hScrollBarAtEnd[self.__previewedPath] = False |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
286 | self.__vScrollBarAtEnd[self.__previewedPath] = False |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | def __restoreScrollBarPositions(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | Private method to restore scroll bar positions for a previewed editor. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | """ |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
292 | if self.__previewedPath not in self.__scrollBarPositions: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
293 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
294 | |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
295 | pos = self.__scrollBarPositions[self.__previewedPath] |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
296 | self.previewView.page().runJavaScript( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
297 | "window.scrollTo({0}, {1});".format(pos.x(), pos.y()) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
298 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
299 | |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
300 | def __execJavaScript(self, script): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
301 | """ |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
302 | Private function to execute a JavaScript function Synchroneously. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
303 | |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
304 | @param script JavaScript script source to be executed |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
305 | @type str |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
306 | @return result of the script |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
307 | @rtype depending upon script result |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
308 | """ |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
309 | loop = QEventLoop() |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
310 | resultDict = {"res": None} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
311 | |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
312 | def resultCallback(res, resDict=resultDict): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
313 | if loop and loop.isRunning(): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
314 | resDict["res"] = res |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
315 | loop.quit() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
316 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
317 | self.previewView.page().runJavaScript(script, resultCallback) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
318 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7724
diff
changeset
|
319 | loop.exec() |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
320 | return resultDict["res"] |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | |
9447 | 322 | @pyqtSlot() |
323 | def on_htmlButton_clicked(self): | |
324 | """ | |
325 | Private slot to copy the HTML contents to the clipboard. | |
326 | """ | |
327 | if self.__previewedHtml: | |
328 | QGuiApplication.clipboard().setText(self.__previewedHtml) | |
329 | ||
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | class PreviewProcessingThread(QThread): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | Class implementing a thread to process some text into HTML usable by the |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | previewer view. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
335 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
336 | @signal htmlReady(str, str, str) emitted with the file name, the processed |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
337 | HTML and the web site root path to signal the availability of the |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
338 | processed HTML |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
341 | htmlReady = pyqtSignal(str, str, str) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
342 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | def __init__(self, parent=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
346 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
347 | @param parent reference to the parent object |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
348 | @type QObject |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
350 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
351 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | self.__lock = threading.Lock() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
353 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
354 | def process( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
355 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
356 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
357 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
358 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
359 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
360 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
361 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
362 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
363 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
365 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
366 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
368 | Public method to convert the given text to HTML. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
370 | @param filePath file path of the text |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
371 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
372 | @param language language of the text |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
373 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
374 | @param text text to be processed |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
375 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | @param ssiEnabled flag indicating to do some (limited) SSI processing |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
377 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
378 | @param rootPath root path to be used for SSI processing |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
379 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
380 | @param useSphinx flag indicating to use Sphinx to generate the |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
381 | ReST preview |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
382 | @type bool |
5837 | 383 | @param convertNewLineToBreak flag indicating to convert new lines |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
384 | to HTML break (Markdown only) |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
385 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
386 | @param usePyMdownExtensions flag indicating to enable the PyMdown |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
387 | extensions, if they are available |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
388 | @type bool |
5837 | 389 | @param markdownHtmlFormat HTML format to be generated by markdown |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
390 | @type str |
5837 | 391 | @param restDocutilsHtmlFormat HTML format to be generated by docutils |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
392 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | self.__filePath = filePath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | self.__language = language |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | self.__text = text |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | self.__ssiEnabled = ssiEnabled |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
399 | self.__rootPath = rootPath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | self.__haveData = True |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
401 | self.__useSphinx = useSphinx |
5837 | 402 | self.__convertNewLineToBreak = convertNewLineToBreak |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
403 | self.__usePyMdownExtensions = usePyMdownExtensions |
5837 | 404 | self.__markdownHtmlFormat = markdownHtmlFormat |
405 | self.__restDocutilsHtmlFormat = restDocutilsHtmlFormat | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | if not self.isRunning(): |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7960
diff
changeset
|
407 | self.start(QThread.Priority.LowPriority) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
408 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | def run(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
411 | Public thread method to convert the stored data. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | while True: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | # exits with break |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | filePath = self.__filePath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | language = self.__language |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
418 | text = self.__text |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | ssiEnabled = self.__ssiEnabled |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | rootPath = self.__rootPath |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
421 | useSphinx = self.__useSphinx |
5837 | 422 | convertNewLineToBreak = self.__convertNewLineToBreak |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
423 | usePyMdownExtensions = self.__usePyMdownExtensions |
5837 | 424 | markdownHtmlFormat = self.__markdownHtmlFormat |
425 | restDocutilsHtmlFormat = self.__restDocutilsHtmlFormat | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
426 | |
5837 | 427 | self.__haveData = False |
428 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
429 | html = self.__getHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
430 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
431 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
432 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
433 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
434 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
435 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
436 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
437 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
438 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
439 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
440 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
441 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | if not self.__haveData: |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
444 | self.htmlReady.emit(filePath, html, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | break |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | # else - next iteration |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
447 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
448 | def __getHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
449 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
450 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
451 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
452 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
453 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
454 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
455 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
456 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
457 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
458 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
459 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | Private method to process the given text depending upon the given |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | language. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
464 | |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
465 | @param language language of the text |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
466 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
467 | @param text to be processed |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
468 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | @param ssiEnabled flag indicating to do some (limited) SSI processing |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
470 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
471 | @param filePath file path of the text |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
472 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
473 | @param rootPath root path to be used for SSI processing |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
474 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
475 | @param useSphinx flag indicating to use Sphinx to generate the |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
476 | ReST preview |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
477 | @type bool |
5837 | 478 | @param convertNewLineToBreak flag indicating to convert new lines |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
479 | to HTML break (Markdown only) |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
480 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
481 | @param usePyMdownExtensions flag indicating to enable the PyMdown |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
482 | extensions, if they are available |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
483 | @type bool |
5837 | 484 | @param markdownHtmlFormat HTML format to be generated by markdown |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
485 | @type str |
5837 | 486 | @param restDocutilsHtmlFormat HTML format to be generated by docutils |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
487 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
488 | @return processed HTML text |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
489 | @rtype str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | if language == "HTML": |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | if ssiEnabled: |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
493 | html = self.__processSSI(text, filePath, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | else: |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
495 | html = text |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
496 | return self.__processRootPath(html, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | elif language == "Markdown": |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
498 | return self.__convertMarkdown( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
499 | text, convertNewLineToBreak, usePyMdownExtensions, markdownHtmlFormat |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
500 | ) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | elif language == "ReST": |
5837 | 502 | return self.__convertReST(text, useSphinx, restDocutilsHtmlFormat) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
504 | return self.tr("<p>No preview available for this type of file.</p>") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
505 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | def __processSSI(self, txt, filename, root): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | Private method to process the given text for SSI statements. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
509 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | Note: Only a limited subset of SSI statements are supported. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
511 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
512 | @param txt text to be processed |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
513 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
514 | @param filename name of the file associated with the given text |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
515 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
516 | @param root directory of the document root |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
517 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
518 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
519 | @rtype str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
521 | if not filename: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
523 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | # SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | incRe = re.compile( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | r"""<!--#include[ \t]+(virtual|file)=[\"']([^\"']+)[\"']\s*-->""", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
527 | re.IGNORECASE, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
528 | ) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | baseDir = os.path.dirname(os.path.abspath(filename)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | docRoot = root if root != "" else baseDir |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
531 | while True: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | incMatch = incRe.search(txt) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | if incMatch is None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
535 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | if incMatch.group(1) == "virtual": |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
537 | incFile = FileSystemUtilities.normjoinpath(docRoot, incMatch.group(2)) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | elif incMatch.group(1) == "file": |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
539 | incFile = FileSystemUtilities.normjoinpath(baseDir, incMatch.group(2)) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
541 | incFile = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | if os.path.exists(incFile): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | try: |
7785
9978016560ec
Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7781
diff
changeset
|
544 | with open(incFile, "r") as f: |
9978016560ec
Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7781
diff
changeset
|
545 | incTxt = f.read() |
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
|
546 | except OSError: |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
547 | # remove SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
548 | incTxt = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
549 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | # remove SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
551 | incTxt = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
552 | txt = txt[: incMatch.start(0)] + incTxt + txt[incMatch.end(0) :] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
553 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
554 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
555 | |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
556 | def __processRootPath(self, txt, root): |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
557 | """ |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
558 | Private method to adjust absolute references to the given root path. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
559 | |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
560 | @param txt text to be processed |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
561 | @type str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
562 | @param root directory of the document root |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
563 | @type str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
564 | @return processed HTML |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
565 | @rtype str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
566 | """ |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
567 | if not root: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
568 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
569 | |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
570 | root = FileSystemUtilities.fromNativeSeparators(root) |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
571 | if not root.endswith("/"): |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
572 | root += "/" |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
573 | rootLen = len(root) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
574 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
575 | refRe = re.compile(r"""(href|src)=[\\"']/([^\\"']+)[\\"']""", re.IGNORECASE) |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
576 | pos = 0 |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
577 | while True: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
578 | refMatch = refRe.search(txt, pos) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
579 | if refMatch is None: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
580 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
581 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
582 | txt = ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
583 | txt[: refMatch.start(0)] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
584 | + refMatch.group(1) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
585 | + '="' |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
586 | + root |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
587 | + refMatch.group(2) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
588 | + '"' |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
589 | + txt[refMatch.end(0) :] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
590 | ) |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
591 | pos = refMatch.end(0) + rootLen |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
592 | |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
593 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
594 | |
5837 | 595 | def __convertReST(self, text, useSphinx, restDocutilsHtmlFormat): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | Private method to convert ReST text into HTML. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
598 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
599 | @param text text to be processed |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
600 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
601 | @param useSphinx flag indicating to use Sphinx to generate the |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
602 | ReST preview |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
603 | @type bool |
5837 | 604 | @param restDocutilsHtmlFormat HTML format to be generated by docutils |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
605 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
606 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
607 | @rtype str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
608 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
609 | if useSphinx: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
610 | return self.__convertReSTSphinx(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
611 | else: |
5837 | 612 | return self.__convertReSTDocutils(text, restDocutilsHtmlFormat) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
613 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
614 | def __convertReSTSphinx(self, text): |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
615 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
616 | Private method to convert ReST text into HTML using 'sphinx'. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
617 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
618 | @param text text to be processed |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
619 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
620 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
621 | @rtype str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | try: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
624 | from sphinx.application import ( # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
625 | Sphinx, |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
626 | ) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
627 | except ImportError: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
628 | return self.tr( |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
629 | """<p>ReStructuredText preview requires the""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
630 | """ <b>sphinx</b> package.<br/>Install it with""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
631 | """ your package manager,'pip install Sphinx' or see""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
632 | """ <a href="http://pypi.python.org/pypi/Sphinx">""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
633 | """this page.</a></p>""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
634 | """<p>Alternatively you may disable Sphinx usage""" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
635 | """ on the Editor, Filehandling configuration page.</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
636 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
637 | |
7675
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
638 | srcTempDir = tempfile.mkdtemp(prefix="eric-rest-src-") |
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
639 | outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-") |
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
640 | doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-") |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
641 | try: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
642 | filename = "sphinx_preview" |
7675
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
643 | basePath = os.path.join(srcTempDir, filename) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
644 | with open(basePath + ".rst", "w", encoding="utf-8") as fh: |
7785
9978016560ec
Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7781
diff
changeset
|
645 | fh.write(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
646 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
647 | overrides = { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
648 | "html_add_permalinks": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
649 | "html_copy_source": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
650 | "html_title": "Sphinx preview", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
651 | "html_use_index": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
652 | "html_use_modindex": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
653 | "html_use_smartypants": True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
654 | "master_doc": filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
655 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
656 | app = Sphinx( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
657 | srcdir=srcTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
658 | confdir=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
659 | outdir=outTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
660 | doctreedir=doctreeTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
661 | buildername="html", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
662 | confoverrides=overrides, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
663 | status=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
664 | warning=io.StringIO(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
665 | ) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
666 | app.build(force_all=True, filenames=None) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
667 | |
7675
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
668 | basePath = os.path.join(outTempDir, filename) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
669 | with open(basePath + ".html", "r", encoding="utf-8") as fh: |
7785
9978016560ec
Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7781
diff
changeset
|
670 | html = fh.read() |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
671 | finally: |
7675
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
672 | shutil.rmtree(srcTempDir) |
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
673 | shutil.rmtree(outTempDir) |
7d23e502fe85
PreviewerHTML: fixed an issue raised by Sphinx when converting .rst files to .html.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7524
diff
changeset
|
674 | shutil.rmtree(doctreeTempDir) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
675 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
676 | return html |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
677 | |
5837 | 678 | def __convertReSTDocutils(self, text, htmlFormat): |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
679 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
680 | Private method to convert ReST text into HTML using 'docutils'. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
681 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
682 | @param text text to be processed |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
683 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
684 | @param htmlFormat HTML format to be generated |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
685 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
686 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
687 | @rtype str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
688 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
689 | if "sphinx" in sys.modules: |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
690 | # Make sure any Sphinx polution of docutils has been removed. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
691 | unloadKeys = [ |
10373
093dcebe5ecb
Corrected some uses of dict.keys(), dict.values() and dict.items().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10331
diff
changeset
|
692 | k for k in sys.modules if k.startswith(("docutils", "sphinx")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
693 | ] |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
694 | for key in unloadKeys: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
695 | sys.modules.pop(key) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
696 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
697 | try: |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
698 | import docutils.core # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I-10__ |
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
699 | import docutils.utils # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I-10__ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | except ImportError: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
701 | return self.tr( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
702 | """<p>ReStructuredText preview requires the""" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
703 | """ <b>python-docutils</b> package.<br/>Install it with""" |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
704 | """ your package manager, 'pip install docutils' or see""" |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
705 | """ <a href="http://pypi.python.org/pypi/docutils">""" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
706 | """this page.</a></p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
707 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
708 | |
3981
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
709 | # redirect sys.stderr because we are not interested in it here |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
710 | origStderr = sys.stderr |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
711 | sys.stderr = io.StringIO() |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
712 | try: |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
713 | html = docutils.core.publish_string( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
714 | text, writer_name=htmlFormat.lower() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
715 | ).decode("utf-8") |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
716 | except docutils.utils.SystemMessage as err: |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
717 | errStr = str(err).split(":")[-1].replace("\n", "<br/>") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
718 | return self.tr("""<p>Docutils returned an error:</p><p>{0}</p>""").format( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
719 | errStr |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
720 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
721 | |
3981
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
722 | sys.stderr = origStderr |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
723 | return html |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
724 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
725 | def __convertMarkdown( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
726 | self, text, convertNewLineToBreak, usePyMdownExtensions, htmlFormat |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
727 | ): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
728 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
729 | Private method to convert Markdown text into HTML. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
730 | |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
731 | @param text text to be processed |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
732 | @type str |
5837 | 733 | @param convertNewLineToBreak flag indicating to convert new lines |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
734 | to HTML break (Markdown only) |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
735 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
736 | @param usePyMdownExtensions flag indicating to enable the PyMdown |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
737 | extensions, if they are available |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
738 | @type bool |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
739 | @param htmlFormat HTML format to be generated by markdown |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
740 | @type str |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
741 | @return processed HTML |
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
742 | @rtype str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
743 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
744 | try: |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
745 | import markdown # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I-10__ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
746 | except ImportError: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
747 | return self.tr( |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
748 | """<p>Markdown preview requires the <b>Markdown</b> """ |
5394
b2c6179184f6
Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
749 | """package.<br/>Install it with your package manager,""" |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
750 | """ 'pip install Markdown' or see """ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
751 | """<a href="http://pythonhosted.org/Markdown/install.html">""" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
752 | """installation instructions.</a></p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
753 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
754 | |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
755 | from . import MarkdownExtensions, PreviewerHTMLStyles # noqa: I-101 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
756 | |
7301
6df711503ec0
PreviewerHTML: enhanced the Markdown previewer by using the PyMdown extensions, if they are available and have been enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7264
diff
changeset
|
757 | extensions = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
758 | |
7314
c32c24345ca7
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7309
diff
changeset
|
759 | mermaidNeeded = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
760 | if Preferences.getEditor( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
761 | "PreviewMarkdownMermaid" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
762 | ) and MarkdownExtensions.MermaidRegexFullText.search(text): |
8227
349308e84eeb
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
763 | extensions.append(MarkdownExtensions.MermaidExtension()) |
349308e84eeb
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
764 | mermaidNeeded = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
765 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
766 | if convertNewLineToBreak: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
767 | extensions.append("nl2br") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
768 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
769 | pyMdown = False |
10331
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
770 | if usePyMdownExtensions and bool(importlib.util.find_spec("pymdownx")): |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
771 | # PyPI package is 'pymdown-extensions' |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
772 | |
10331
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
773 | extensions.extend( |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
774 | [ |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
775 | "toc", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
776 | "pymdownx.extra", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
777 | "pymdownx.caret", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
778 | "pymdownx.emoji", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
779 | "pymdownx.mark", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
780 | "pymdownx.tilde", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
781 | "pymdownx.keys", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
782 | "pymdownx.tasklist", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
783 | "pymdownx.smartsymbols", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
784 | ] |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
785 | ) |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
786 | pyMdown = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
787 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
788 | if not pyMdown: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
789 | extensions.extend(["extra", "toc"]) |
9268
0d414630a28e
Changed PreviewerHTML.py to no longer support ancient 'Markdown' package versions (i.e. before 2.1.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
790 | extensions.append(MarkdownExtensions.SimplePatternExtension()) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
791 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
792 | if Preferences.getEditor("PreviewMarkdownMathJax"): |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
793 | mathjax = ( |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
794 | "<script type='text/javascript' id='MathJax-script' async" |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
795 | " src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/" |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
796 | "tex-chtml.js'>\n" |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
797 | "</script>\n" |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
798 | ) |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
799 | # prepare text for mathjax |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
800 | text = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
801 | text.replace(r"\(", r"\\(") |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
802 | .replace(r"\)", r"\\)") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
803 | .replace(r"\[", r"\\[") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
804 | .replace(r"\]", r"\\]") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
805 | ) |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
806 | else: |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
807 | mathjax = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
808 | |
7314
c32c24345ca7
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7309
diff
changeset
|
809 | if mermaidNeeded: |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
810 | mermaid = ( |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
811 | "<script type='text/javascript' id='Mermaid-script'" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
812 | " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
813 | "</script>\n" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
814 | ) |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
815 | if ericApp().usesDarkPalette(): |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
816 | mermaid_initialize = ( |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
817 | "<script>mermaid.initialize({" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
818 | "theme: 'dark', " |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
819 | "startOnLoad:true" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
820 | "});</script>" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
821 | ) |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
822 | else: |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
823 | mermaid_initialize = ( |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
824 | "<script>mermaid.initialize({" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
825 | "theme: 'default', " |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
826 | "startOnLoad:true" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
827 | "});</script>" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
828 | ) |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
829 | else: |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
830 | mermaid = "" |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
831 | mermaid_initialize = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
832 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
833 | htmlFormat = Preferences.getEditor("PreviewMarkdownHTMLFormat").lower() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
834 | body = markdown.markdown( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
835 | text, extensions=extensions, output_format=htmlFormat.lower() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
836 | ) |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
837 | style = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
838 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
839 | PreviewerHTMLStyles.css_markdown_dark |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
840 | + PreviewerHTMLStyles.css_pygments_dark |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
841 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
842 | if ericApp().usesDarkPalette() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
843 | else ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
844 | PreviewerHTMLStyles.css_markdown_light |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
845 | + PreviewerHTMLStyles.css_pygments_light |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
846 | ) |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
847 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
848 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
849 | if htmlFormat == "xhtml1": |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
850 | head = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
851 | """<!DOCTYPE html PUBLIC "-//W3C//DTD""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
852 | """ XHTML 1.0 Transitional//EN"\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
853 | """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
854 | """.dtd">\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
855 | """<html xmlns="http://www.w3.org/1999/xhtml">\n""" |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
856 | ) |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
857 | elif htmlFormat == "html5": |
9573
9960d19d66b5
Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
858 | head = """<!DOCTYPE html>\n<html lang="EN">\n""" |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
859 | else: |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
860 | head = '<html lang="EN">\n' |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
861 | head += """<head>\n""" |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
862 | head += ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
863 | """<meta name="Generator" content="eric" />\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
864 | """<meta http-equiv="Content-Type" """ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
865 | """content="text/html; charset=utf-8" />\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
866 | """{0}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
867 | """{1}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
868 | """<style type="text/css">""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
869 | """{2}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
870 | """</style>\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
871 | """</head>\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
872 | """<body>\n""" |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
873 | ).format(mathjax, mermaid, style) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
874 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
875 | foot = """\n</body>\n</html>\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
876 | |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
877 | return head + body + mermaid_initialize + foot |