162 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
162 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
163 else: |
163 else: |
164 extension = "" |
164 extension = "" |
165 if extension in \ |
165 if extension in \ |
166 Preferences.getEditor("PreviewHtmlFileNameExtensions") or \ |
166 Preferences.getEditor("PreviewHtmlFileNameExtensions") or \ |
167 editor.getLanguage() == "HTML": |
167 editor.getLanguage() == "HTML": |
168 language = "HTML" |
168 language = "HTML" |
169 elif extension in \ |
169 elif extension in \ |
170 Preferences.getEditor("PreviewMarkdownFileNameExtensions"): |
170 Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \ |
|
171 editor.getLanguage().lower() == "markdown": |
171 language = "Markdown" |
172 language = "Markdown" |
172 elif extension in \ |
173 elif extension in \ |
173 Preferences.getEditor("PreviewRestFileNameExtensions"): |
174 Preferences.getEditor("PreviewRestFileNameExtensions") or \ |
|
175 editor.getLanguage().lower() == "restructuredtext": |
174 language = "ReST" |
176 language = "ReST" |
175 else: |
177 else: |
176 self.__setHtml(fn, self.tr( |
178 self.__setHtml(fn, self.tr( |
177 "<p>No preview available for this type of file.</p>")) |
179 "<p>No preview available for this type of file.</p>")) |
178 return |
180 return |
184 else: |
186 else: |
185 rootPath = os.path.dirname(os.path.abspath(fn)) |
187 rootPath = os.path.dirname(os.path.abspath(fn)) |
186 else: |
188 else: |
187 rootPath = "" |
189 rootPath = "" |
188 |
190 |
189 self.__processingThread.process( |
191 if bool(editor.text()): |
190 fn, language, editor.text(), |
192 self.__processingThread.process( |
191 self.ssiCheckBox.isChecked(), rootPath, |
193 fn, language, editor.text(), |
192 Preferences.getEditor("PreviewRestUseSphinx")) |
194 self.ssiCheckBox.isChecked(), rootPath, |
|
195 Preferences.getEditor("PreviewRestUseSphinx")) |
193 |
196 |
194 def __setHtml(self, filePath, html): |
197 def __setHtml(self, filePath, html): |
195 """ |
198 """ |
196 Private method to set the HTML to the view and restore the scroll bars |
199 Private method to set the HTML to the view and restore the scroll bars |
197 positions. |
200 positions. |
336 @signal htmlReady(str,str) emitted with the file name and processed HTML |
339 @signal htmlReady(str,str) emitted with the file name and processed HTML |
337 to signal the availability of the processed HTML |
340 to signal the availability of the processed HTML |
338 """ |
341 """ |
339 htmlReady = pyqtSignal(str, str) |
342 htmlReady = pyqtSignal(str, str) |
340 |
343 |
341 DefaultStaticPath = os.path.join( |
|
342 os.path.abspath(os.path.dirname(__file__)), 'sphinx_default') |
|
343 StaticRegexp = re.compile(r'(src|href)=["\']_static([\s\w/\.]+?)["\']', |
|
344 re.IGNORECASE) |
|
345 |
|
346 def __init__(self, parent=None): |
344 def __init__(self, parent=None): |
347 """ |
345 """ |
348 Constructor |
346 Constructor |
349 |
347 |
350 @param parent reference to the parent object (QObject) |
348 @param parent reference to the parent object (QObject) |
535 fh = open(basePath + '.html', 'r', encoding='utf-8') |
533 fh = open(basePath + '.html', 'r', encoding='utf-8') |
536 html = fh.read() |
534 html = fh.read() |
537 fh.close() |
535 fh.close() |
538 finally: |
536 finally: |
539 shutil.rmtree(tempDir) |
537 shutil.rmtree(tempDir) |
540 |
|
541 # Replace the "_static/..." references inserted by Sphinx with absolute |
|
542 # links to the specified DefaultStaticPath replacement. |
|
543 def replace(m): |
|
544 return '{0}="file://{1}{2}"'.format( |
|
545 m.group(1), self.DefaultStaticPath, m.group(2)) |
|
546 html = re.sub(self.StaticRegexp, replace, html) |
|
547 |
538 |
548 return html |
539 return html |
549 |
540 |
550 def __convertReSTDocutils(self, text): |
541 def __convertReSTDocutils(self, text): |
551 """ |
542 """ |