Sat, 23 Dec 2023 15:48:12 +0100
Updated copyright for 2024.
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 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10433
diff
changeset
|
3 | # Copyright (c) 2014 - 2024 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 | |
10331
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
10 | import importlib |
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: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
63 | from PyQt6.QtWebEngineWidgets import ( # __IGNORE_WARNING_I10__ |
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) |
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
|
69 | except ImportError: |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
70 | self.__previewAvailable = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
71 | self.titleLabel.setText( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
73 | "<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
|
74 | "Install PyQt6-WebEngine.</b>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | ) |
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
|
77 | 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
|
78 | self.__layout.addStretch() |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
79 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
81 | sizePolicy = QSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | 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
|
83 | ) |
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
|
84 | 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
|
85 | sizePolicy.setVerticalStretch(0) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | 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
|
87 | self.previewView.setSizePolicy(sizePolicy) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | |
9447 | 92 | self.__footerLayout = QGridLayout() |
93 | sizePolicy = QSizePolicy( | |
94 | QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred | |
95 | ) | |
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
|
96 | self.jsCheckBox = QCheckBox(self.tr("Enable JavaScript"), self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
97 | self.jsCheckBox.setToolTip( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | self.tr("Select to enable JavaScript for HTML previews") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
99 | ) |
9447 | 100 | self.jsCheckBox.setSizePolicy(sizePolicy) |
101 | self.__footerLayout.addWidget(self.jsCheckBox, 0, 0) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | 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
|
104 | self.ssiCheckBox.setToolTip( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | 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
|
106 | ) |
9447 | 107 | self.ssiCheckBox.setSizePolicy(sizePolicy) |
108 | self.__footerLayout.addWidget(self.ssiCheckBox, 1, 0) | |
109 | self.__htmlButton = QPushButton(self.tr("Copy HTML"), self) | |
110 | self.__htmlButton.setToolTip( | |
111 | self.tr("Press to copy the HTML text of the preview to the clipboard") | |
112 | ) | |
113 | self.__htmlButton.setEnabled(False) | |
114 | self.__footerLayout.addWidget(self.__htmlButton, 1, 1) | |
115 | 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
|
116 | |
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
|
117 | self.jsCheckBox.clicked[bool].connect(self.on_jsCheckBox_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
|
118 | 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
|
119 | self.previewView.titleChanged.connect(self.on_previewView_titleChanged) |
9447 | 120 | 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
|
121 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
122 | self.jsCheckBox.setChecked(Preferences.getUI("ShowFilePreviewJS")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | 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
|
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.__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
|
126 | 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
|
127 | self.__hScrollBarAtEnd = {} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
128 | |
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
|
129 | 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
|
130 | 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
|
131 | |
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 | 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
|
133 | self.__previewedEditor = None |
9447 | 134 | self.__previewedHtml = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | |
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
|
136 | 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
|
137 | """ |
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
|
138 | 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
|
139 | """ |
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
|
140 | 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
|
141 | self.__processingThread.wait() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
142 | |
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
|
143 | @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
|
144 | def on_jsCheckBox_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
|
145 | """ |
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 | Private slot to enable/disable JavaScript. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
147 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
148 | @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
|
149 | @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
|
150 | """ |
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
|
151 | Preferences.setUI("ShowFilePreviewJS", 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
|
152 | self.__setJavaScriptEnabled(checked) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
153 | |
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
|
154 | def __setJavaScriptEnabled(self, enable): |
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
|
155 | """ |
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
|
156 | Private method to enable/disable JavaScript. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
157 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
158 | @param enable flag indicating the enable state |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
159 | @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
|
160 | """ |
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 | self.jsCheckBox.setChecked(enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | |
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
|
163 | settings = self.previewView.settings() |
9824
f3c46e684ffe
Fixed an issue caused by incorrect usage of PyQt6 enum (see issue486).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
164 | settings.setAttribute(settings.WebAttribute.JavascriptEnabled, enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
165 | |
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 | self.processEditor() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | |
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
|
168 | @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
|
169 | 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
|
170 | """ |
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 | 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
|
172 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
173 | @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
|
174 | @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
|
175 | """ |
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 | 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
|
177 | self.processEditor() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
178 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
179 | @pyqtSlot(str) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
180 | def __showLink(self, urlStr): |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
181 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
182 | 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
|
183 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
184 | @param urlStr hovered URL |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
185 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
186 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
187 | 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
|
188 | |
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
|
189 | 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
|
190 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
191 | 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
|
192 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
193 | @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
|
194 | @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
|
195 | """ |
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
|
196 | 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
|
197 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
198 | |
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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | self.__previewedEditor = editor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
203 | |
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
|
204 | 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
|
205 | fn = editor.getFileName() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
206 | |
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
|
207 | 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
|
208 | 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
|
209 | 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
|
210 | extension = "" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
211 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
212 | extension in Preferences.getEditor("PreviewHtmlFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
213 | or editor.getLanguage() == "HTML" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
214 | ): |
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
|
215 | language = "HTML" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
216 | elif ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
217 | extension in Preferences.getEditor("PreviewMarkdownFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
218 | or editor.getLanguage().lower() == "markdown" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
219 | ): |
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
|
220 | language = "Markdown" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
221 | elif ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
222 | extension in Preferences.getEditor("PreviewRestFileNameExtensions") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
223 | or editor.getLanguage().lower() == "restructuredtext" |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
224 | ): |
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
|
225 | 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
|
226 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
227 | self.__setHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
228 | 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
|
229 | ) |
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
|
230 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
231 | |
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
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | rootPath = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
236 | |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
237 | if bool(editor.text()): |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
238 | self.__processingThread.process( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
239 | fn, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
241 | editor.text(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
242 | self.ssiCheckBox.isChecked(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
243 | rootPath, |
5837 | 244 | Preferences.getEditor("PreviewRestUseSphinx"), |
245 | Preferences.getEditor("PreviewMarkdownNLtoBR"), | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
246 | Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions"), |
5837 | 247 | Preferences.getEditor("PreviewMarkdownHTMLFormat"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
248 | Preferences.getEditor("PreviewRestDocutilsHTMLFormat"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
249 | ) |
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
|
250 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
251 | 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
|
252 | """ |
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 | 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
|
254 | positions. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
255 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
256 | @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
|
257 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
258 | @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
|
259 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
260 | @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
|
261 | @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
|
262 | """ |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
263 | 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
|
264 | FileSystemUtilities.fromNativeSeparators(filePath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
265 | ) |
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
|
266 | self.__saveScrollBarPositions() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
267 | 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
|
268 | if not filePath: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
269 | 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
|
270 | 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
|
271 | 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
|
272 | if rootPath |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
273 | 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
|
274 | ) |
9447 | 275 | self.__previewedHtml = html |
276 | self.__htmlButton.setEnabled(bool(html)) | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
277 | 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
|
278 | 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
|
279 | self.__previewedEditor.setFocus() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
280 | |
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
|
281 | @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
|
282 | 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
|
283 | """ |
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
|
284 | 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
|
285 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
286 | @param title new title |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
287 | @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
|
288 | """ |
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 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | |
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
|
294 | 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
|
295 | """ |
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
|
296 | 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
|
297 | """ |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
298 | try: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
299 | pos = self.previewView.scrollPosition() |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
300 | except AttributeError: |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
301 | pos = self.__execJavaScript( |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
302 | "(function() {" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
303 | "var res = {" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
304 | " x: 0," |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
305 | " y: 0," |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
306 | "};" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
307 | "res.x = window.scrollX;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
308 | "res.y = window.scrollY;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
309 | "return res;" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
310 | "})()" |
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
311 | ) |
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
|
312 | 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
|
313 | 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
|
314 | 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
|
315 | 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
|
316 | |
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
|
317 | 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
|
318 | """ |
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
|
319 | 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
|
320 | """ |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
321 | 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
|
322 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
323 | |
7196
ab0a91b82b37
Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7192
diff
changeset
|
324 | 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
|
325 | self.previewView.page().runJavaScript( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | "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
|
327 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
328 | |
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
|
329 | 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
|
330 | """ |
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
|
331 | 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
|
332 | |
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
|
333 | @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
|
334 | @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
|
335 | @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
|
336 | @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
|
337 | """ |
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
|
338 | 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
|
339 | resultDict = {"res": None} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | |
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
|
341 | 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
|
342 | 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
|
343 | 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
|
344 | loop.quit() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
345 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
346 | 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
|
347 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7724
diff
changeset
|
348 | 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
|
349 | 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
|
350 | |
9447 | 351 | @pyqtSlot() |
352 | def on_htmlButton_clicked(self): | |
353 | """ | |
354 | Private slot to copy the HTML contents to the clipboard. | |
355 | """ | |
356 | if self.__previewedHtml: | |
357 | QGuiApplication.clipboard().setText(self.__previewedHtml) | |
358 | ||
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
|
359 | |
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
|
360 | 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
|
361 | """ |
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
|
362 | 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
|
363 | previewer view. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
365 | @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
|
366 | 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
|
367 | 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
|
368 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
370 | 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
|
371 | |
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
|
372 | 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
|
373 | """ |
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
|
374 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
375 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
376 | @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
|
377 | @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
|
378 | """ |
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
|
379 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
380 | |
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
|
381 | self.__lock = threading.Lock() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
382 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
383 | def process( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
384 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
385 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
386 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
387 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
388 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
389 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
390 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
391 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
392 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
393 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
394 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
395 | ): |
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
|
396 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
397 | 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
|
398 | |
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
|
399 | @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
|
400 | @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
|
401 | @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
|
402 | @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
|
403 | @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
|
404 | @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
|
405 | @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
|
406 | @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
|
407 | @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
|
408 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
409 | @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
|
410 | 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
|
411 | @type bool |
5837 | 412 | @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
|
413 | 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
|
414 | @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
|
415 | @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
|
416 | 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
|
417 | @type bool |
5837 | 418 | @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
|
419 | @type str |
5837 | 420 | @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
|
421 | @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
|
422 | """ |
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
|
423 | 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
|
424 | 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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | self.__haveData = True |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
430 | self.__useSphinx = useSphinx |
5837 | 431 | 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
|
432 | self.__usePyMdownExtensions = usePyMdownExtensions |
5837 | 433 | self.__markdownHtmlFormat = markdownHtmlFormat |
434 | 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
|
435 | 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
|
436 | 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
|
437 | |
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
|
438 | 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
|
439 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
440 | 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
|
441 | """ |
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 | 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
|
443 | # 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
|
444 | 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
|
445 | 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
|
446 | 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
|
447 | 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
|
448 | 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
|
449 | rootPath = self.__rootPath |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
450 | useSphinx = self.__useSphinx |
5837 | 451 | 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
|
452 | usePyMdownExtensions = self.__usePyMdownExtensions |
5837 | 453 | markdownHtmlFormat = self.__markdownHtmlFormat |
454 | restDocutilsHtmlFormat = self.__restDocutilsHtmlFormat | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
455 | |
5837 | 456 | self.__haveData = False |
457 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
458 | html = self.__getHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
459 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
461 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
462 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
463 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
464 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
465 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
466 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
467 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
468 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
469 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
470 | |
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
|
471 | 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
|
472 | if not self.__haveData: |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
473 | 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
|
474 | 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
|
475 | # else - next iteration |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
476 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
477 | def __getHtml( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
478 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
479 | language, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
480 | text, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
481 | ssiEnabled, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
482 | filePath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
483 | rootPath, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
484 | useSphinx, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
485 | convertNewLineToBreak, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
486 | usePyMdownExtensions, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
487 | markdownHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
488 | restDocutilsHtmlFormat, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
489 | ): |
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 | 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
|
492 | language. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
493 | |
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
|
494 | @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
|
495 | @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
|
496 | @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
|
497 | @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
|
498 | @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
|
499 | @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
|
500 | @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
|
501 | @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
|
502 | @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
|
503 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
504 | @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
|
505 | 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
|
506 | @type bool |
5837 | 507 | @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
|
508 | 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
|
509 | @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
|
510 | @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
|
511 | 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
|
512 | @type bool |
5837 | 513 | @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
|
514 | @type str |
5837 | 515 | @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
|
516 | @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
|
517 | @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
|
518 | @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
|
519 | """ |
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 | 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
|
521 | 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
|
522 | 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
|
523 | 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
|
524 | 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
|
525 | 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
|
526 | 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
|
527 | return self.__convertMarkdown( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
528 | text, convertNewLineToBreak, usePyMdownExtensions, markdownHtmlFormat |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
529 | ) |
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
|
530 | elif language == "ReST": |
5837 | 531 | 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
|
532 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
533 | 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
|
534 | |
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
|
535 | 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
|
536 | """ |
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
|
537 | 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
|
538 | |
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
|
539 | 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
|
540 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
541 | @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
|
542 | @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
|
543 | @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
|
544 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
545 | @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
|
546 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
547 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
548 | @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
|
549 | """ |
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 | 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
|
551 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
552 | |
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
|
553 | # 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
|
554 | 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
|
555 | 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
|
556 | re.IGNORECASE, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
557 | ) |
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
|
558 | 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
|
559 | 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
|
560 | 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
|
561 | 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
|
562 | 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
|
563 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
564 | |
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
|
565 | 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
|
566 | 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
|
567 | 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
|
568 | 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
|
569 | 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
|
570 | 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
|
571 | 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
|
572 | try: |
7785
9978016560ec
Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7781
diff
changeset
|
573 | 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
|
574 | 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
|
575 | 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
|
576 | # 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
|
577 | 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
|
578 | 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
|
579 | # 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
|
580 | incTxt = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
581 | 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
|
582 | |
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
|
583 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
584 | |
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
|
585 | 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
|
586 | """ |
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
|
587 | 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
|
588 | |
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
|
589 | @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
|
590 | @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
|
591 | @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
|
592 | @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
|
593 | @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
|
594 | @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
|
595 | """ |
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
|
596 | 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
|
597 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
598 | |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9573
diff
changeset
|
599 | 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
|
600 | 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
|
601 | 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
|
602 | rootLen = len(root) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
603 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
604 | 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
|
605 | 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
|
606 | 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
|
607 | 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
|
608 | 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
|
609 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
610 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
611 | txt = ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
612 | txt[: refMatch.start(0)] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
613 | + refMatch.group(1) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
614 | + '="' |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
615 | + root |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
616 | + refMatch.group(2) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
617 | + '"' |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
618 | + txt[refMatch.end(0) :] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
619 | ) |
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
|
620 | 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
|
621 | |
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
|
622 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
623 | |
5837 | 624 | 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
|
625 | """ |
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
|
626 | 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
|
627 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
628 | @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
|
629 | @type str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
630 | @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
|
631 | ReST preview |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
632 | @type bool |
5837 | 633 | @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
|
634 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
635 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
636 | @rtype str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
637 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
638 | if useSphinx: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
639 | return self.__convertReSTSphinx(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
640 | else: |
5837 | 641 | 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
|
642 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
643 | def __convertReSTSphinx(self, text): |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
644 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
645 | 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
|
646 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
647 | @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
|
648 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
649 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
650 | @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
|
651 | """ |
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
|
652 | try: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
653 | 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
|
654 | Sphinx, |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
655 | ) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
656 | except ImportError: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
657 | return self.tr( |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
658 | """<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
|
659 | """ <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
|
660 | """ 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
|
661 | """ <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
|
662 | """this page.</a></p>""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
663 | """<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
|
664 | """ 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
|
665 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
666 | |
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
|
667 | 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
|
668 | 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
|
669 | 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
|
670 | try: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
671 | 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
|
672 | 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
|
673 | 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
|
674 | fh.write(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
675 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
676 | overrides = { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
677 | "html_add_permalinks": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
678 | "html_copy_source": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
679 | "html_title": "Sphinx preview", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
680 | "html_use_index": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
681 | "html_use_modindex": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
682 | "html_use_smartypants": True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
683 | "master_doc": filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
684 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
685 | app = Sphinx( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
686 | srcdir=srcTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
687 | confdir=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
688 | outdir=outTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
689 | doctreedir=doctreeTempDir, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
690 | buildername="html", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
691 | confoverrides=overrides, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
692 | status=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
693 | warning=io.StringIO(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
694 | ) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
695 | 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
|
696 | |
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
|
697 | 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
|
698 | 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
|
699 | html = fh.read() |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
700 | 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
|
701 | 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
|
702 | 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
|
703 | shutil.rmtree(doctreeTempDir) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
704 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
705 | return html |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
706 | |
5837 | 707 | 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
|
708 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
709 | 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
|
710 | |
10433
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
711 | @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
|
712 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
713 | @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
|
714 | @type str |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
715 | @return processed HTML |
328f3ec4b77a
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10373
diff
changeset
|
716 | @rtype str |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
717 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
718 | 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
|
719 | # 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
|
720 | unloadKeys = [ |
10373
093dcebe5ecb
Corrected some uses of dict.keys(), dict.values() and dict.items().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10331
diff
changeset
|
721 | 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
|
722 | ] |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
723 | for key in unloadKeys: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
724 | sys.modules.pop(key) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
725 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
726 | try: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
727 | import docutils.core # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I10__ |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
728 | import docutils.utils # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I10__ |
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
|
729 | 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
|
730 | 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
|
731 | """<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
|
732 | """ <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
|
733 | """ 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
|
734 | """ <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
|
735 | """this page.</a></p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
736 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
737 | |
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
|
738 | # 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
|
739 | 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
|
740 | 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
|
741 | try: |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
742 | 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
|
743 | text, writer_name=htmlFormat.lower() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
744 | ).decode("utf-8") |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
745 | 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
|
746 | 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
|
747 | 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
|
748 | errStr |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
749 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
750 | |
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
|
751 | 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
|
752 | return html |
9221
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 | def __convertMarkdown( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
755 | self, text, convertNewLineToBreak, usePyMdownExtensions, htmlFormat |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
756 | ): |
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
|
757 | """ |
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
|
758 | 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
|
759 | |
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
|
760 | @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
|
761 | @type str |
5837 | 762 | @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
|
763 | 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
|
764 | @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
|
765 | @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
|
766 | 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
|
767 | @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
|
768 | @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
|
769 | @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
|
770 | @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
|
771 | @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
|
772 | """ |
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
|
773 | try: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
774 | import markdown # __IGNORE_EXCEPTION__ __IGNORE_WARNING_I10__ |
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
|
775 | 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
|
776 | return self.tr( |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
777 | """<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
|
778 | """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
|
779 | """ '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
|
780 | """<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
|
781 | """installation instructions.</a></p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
782 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
783 | |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
784 | from . import MarkdownExtensions, PreviewerHTMLStyles # __IGNORE_WARNING_I101__ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
785 | |
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
|
786 | extensions = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
787 | |
7314
c32c24345ca7
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7309
diff
changeset
|
788 | mermaidNeeded = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
789 | if Preferences.getEditor( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
790 | "PreviewMarkdownMermaid" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
791 | ) 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
|
792 | 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
|
793 | mermaidNeeded = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
794 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
795 | if convertNewLineToBreak: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
796 | extensions.append("nl2br") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
797 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
798 | pyMdown = False |
10331
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
799 | 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
|
800 | # 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
|
801 | |
10331
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
802 | extensions.extend( |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
803 | [ |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
804 | "toc", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
805 | "pymdownx.extra", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
806 | "pymdownx.caret", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
807 | "pymdownx.emoji", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
808 | "pymdownx.mark", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
809 | "pymdownx.tilde", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
810 | "pymdownx.keys", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
811 | "pymdownx.tasklist", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
812 | "pymdownx.smartsymbols", |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
813 | ] |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
814 | ) |
c1a2ff7e3575
Modernized some code and corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9824
diff
changeset
|
815 | pyMdown = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
816 | |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
817 | if not pyMdown: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
818 | 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
|
819 | 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
|
820 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
821 | 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
|
822 | mathjax = ( |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
823 | "<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
|
824 | " 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
|
825 | "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
|
826 | "</script>\n" |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
827 | ) |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
828 | # prepare text for mathjax |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
829 | text = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
830 | text.replace(r"\(", r"\\(") |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
831 | .replace(r"\)", r"\\)") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
832 | .replace(r"\[", r"\\[") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
833 | .replace(r"\]", r"\\]") |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
834 | ) |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
835 | else: |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
836 | mathjax = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
837 | |
7314
c32c24345ca7
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7309
diff
changeset
|
838 | if mermaidNeeded: |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
839 | mermaid = ( |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
840 | "<script type='text/javascript' id='Mermaid-script'" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
841 | " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
842 | "</script>\n" |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
843 | ) |
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
|
844 | 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
|
845 | mermaid_initialize = ( |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
846 | "<script>mermaid.initialize({" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
847 | "theme: 'dark', " |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
848 | "startOnLoad:true" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
849 | "});</script>" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
850 | ) |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
851 | else: |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
852 | mermaid_initialize = ( |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
853 | "<script>mermaid.initialize({" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
854 | "theme: 'default', " |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
855 | "startOnLoad:true" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
856 | "});</script>" |
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
857 | ) |
7309
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
858 | else: |
5a434813eef3
PreviewerHTML, ExporterHTML:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7304
diff
changeset
|
859 | mermaid = "" |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
860 | mermaid_initialize = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
861 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
862 | 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
|
863 | body = markdown.markdown( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
864 | 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
|
865 | ) |
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
|
866 | style = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
867 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
868 | PreviewerHTMLStyles.css_markdown_dark |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
869 | + PreviewerHTMLStyles.css_pygments_dark |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
870 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
871 | if ericApp().usesDarkPalette() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
872 | else ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
873 | PreviewerHTMLStyles.css_markdown_light |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
874 | + PreviewerHTMLStyles.css_pygments_light |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
875 | ) |
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
|
876 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
877 | |
7304
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
878 | if htmlFormat == "xhtml1": |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
879 | head = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
880 | """<!DOCTYPE html PUBLIC "-//W3C//DTD""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
881 | """ 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
|
882 | """ "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
|
883 | """.dtd">\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
884 | """<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
|
885 | ) |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
886 | 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
|
887 | 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
|
888 | else: |
b072a364dd8d
PreviewerHTML: more enhancments for the Markdown previewer related to MathJax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7301
diff
changeset
|
889 | 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
|
890 | 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
|
891 | head += ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
892 | """<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
|
893 | """<meta http-equiv="Content-Type" """ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
894 | """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
|
895 | """{0}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
896 | """{1}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
897 | """<style type="text/css">""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
898 | """{2}""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
899 | """</style>\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
900 | """</head>\n""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
901 | """<body>\n""" |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
902 | ).format(mathjax, mermaid, style) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
903 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
904 | 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
|
905 | |
7524
282680dae446
HTML Preview and Exporter: added support for dark color schemes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
906 | return head + body + mermaid_initialize + foot |