forked from fpoirotte/reSTPlugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete refactoring (PythonConsole plugin as example)
- Loading branch information
Showing
5 changed files
with
90 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
[Plugin] | ||
Loader=python3 | ||
Module=reST | ||
IAge=3 | ||
Name=reStructuredText Preview | ||
Description=Preview panel for reStructuredText (.rst) | ||
Authors=Christophe Kibleur <kib2@free.fr>;Matěj Cepl <mcepl@cepl.eu>;Peter Bittner <django@bittner.it>;François Poirotte | ||
Copyright=Copyright © 2008 Christophe Kibleur <kib2@free.fr> | ||
Authors=Peter Bittner <django@bittner.it>;Christophe Kibleur <kib2@free.fr>;Matěj Cepl <mcepl@cepl.eu>;François Poirotte | ||
Copyright=Copyright © 2015 Peter Bittner | ||
Website=https://github.com/bittner/gedit-reST-plugin | ||
Version=3.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# restructuredtext.py - reStructuredText HTML preview panel | ||
# | ||
# Copyright (C) 2015 - Peter Bittner | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2, or (at your option) | ||
# any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
from gi.repository import Gtk, WebKit | ||
from os.path import abspath, dirname, join | ||
|
||
|
||
class RestructuredtextHtmlPanel(Gtk.ScrolledWindow): | ||
""" | ||
A Gtk panel displaying HTML rendered from ``.rst`` source code. | ||
""" | ||
|
||
START_HTML = """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Language" content="English"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<style type="text/css"> | ||
%s | ||
</style> | ||
</head> | ||
<body>""" | ||
|
||
END_HTML = """</body> | ||
</html> | ||
""" | ||
|
||
def __init__(self, styles_filename='restructuredtext.css'): | ||
Gtk.ScrolledWindow.__init__(self) # TODO: replace by super() | ||
|
||
module_dir = dirname(abspath(__file__)) | ||
css_file = join(module_dir, styles_filename) | ||
with open(css_file, 'r') as styles: | ||
self.START_HTML = self.START_HTML % styles.read() | ||
|
||
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) | ||
self.set_shadow_type(Gtk.ShadowType.NONE) | ||
self.view = WebKit.WebView() | ||
self.add(self.view) | ||
self.view.show() | ||
|
||
def update_view(self): | ||
self.view.load_string("%s\n<p>reStructuredText Viewer</p>\n%s" % | ||
(self.START_HTML, self.END_HTML), 'text/html', 'utf8', '') | ||
|
||
def clear_view(self): | ||
self.view.load_string("", 'text/html', 'utf8', '') |