diff --git a/ReadMe.rst b/ReadMe.rst new file mode 100644 index 0000000..59b5e75 --- /dev/null +++ b/ReadMe.rst @@ -0,0 +1,86 @@ +Documentation de reStructuredText plugin +======================================== + +Cette documentation est très restreinte, merci de patienter qu'elle s'étoffe +un peu. + +Dépendances +------------ + +- Python >= 2.5 +- Pygments [http://pygments.org/] +- Docutils [http://docutils.sourceforge.net/] +- OdtWriter [http://www.rexx.com/~dkuhlman/odtwriter.html] + +Installation +------------ + +Placez le fichier ``reSt.gedit-plugin`` dans votre dossier plugins de Gedit. +Le mien se situe ici par exemple : +/home/kib/.gnome2/gedit/plugins + +Ensuite, copier /coller le dossier nommé ``reStPlugin`` dans ce même +répertoire. + +Les fichiers Readme.rst et Readme.odt ne sont là que pour vous aider, vous +pourrez ensuite les placer à la poubelle si le coeur vous en dit ! + +L'arborescence devrait donc être la suivante : :: + + .../plugins/ + reSt.gedit-plugin + reStPlugin/ + __init__.py + makeTable.py + etc. + +Utilisation +----------- + +Activez le plugin via Editions/Préférences onglet Plugins et cochez +``reStructuredText plugin``. + +Le plugin est actif, vous devriez obtenir un nouvel onglet dans votre panneau +inférieur nommé ``reSt Preview``. + +Raccourcis +########## + +Ctrl+Maj+R permet d'afficher le contenu de votre fichier reSt (extension .rst) +dans le nouveau panneau. Si une selection est active, la conversion ne se fera +que sur celle-ci, sinon c'est tout le document qui est pris en charge. + +Menu +#### + +Le menu ``Outils`` dispose maintenant de plusieurs options : + +- ``reSt Preview`` a déjà été détaillé précédemment; +- ``Create table`` permet de réaliser des tableaux simples. + + Exemple : Entrer ces deux lignes, sélectionnez-les et activez ``Create table`` + + un,deux,trois + + premiere,seconde,troisieme + + Cela donne : + +============ =========== ============= + un deux trois +============ =========== ============= +premiere seconde troisieme +============ =========== ============= + +- ``Paste Code`` permet de copier/coller des codes sources façon Pygments. + Selectionnez juste du code à copier, et utilisez cette macro. Vous devrez + ensuite ajuster le langage vous même. + +- ``--> HTML``, ``--> LaTeX``, ``--> OpenOffice``: permettent respectivement + un export de votre document dans ces formats respectifs. L'export à lieu + dans le même dossier que votre document initial. Des feuilles de style sont + fournies, ce sera à vous de les adapter à vos besoins. + +En espérant que ce petit plugin vous aidera, n'hésitez-pas à me contacter : + +Kib. diff --git a/ReadMe_en.rst b/ReadMe_en.rst new file mode 100644 index 0000000..8c46443 --- /dev/null +++ b/ReadMe_en.rst @@ -0,0 +1,98 @@ +reStructuredText plugin +======================= + +This is a little how-to for using the reStructuredText plugin inside +`GEdit `_ . + +.. image:: http://farm3.static.flickr.com/2256/2259897373_d47ecf0983_o_d.png + :scale: 100 + :alt: reSt Plugin Image + :align: center + :target: http://farm3.static.flickr.com/2247/2259897529_aa85f5f540_b.jpg + + +Dépendancies +------------ + +- `Python `_ : version >= 2.5; +- `Pygments `_ : take the latest version; +- `reStructuredText `_ ; +- `odtwriter `_ : a reStructuredText addon to export in OpenOffice format. + +Installation +------------ +Unpack the zip file where you wanted to then : + +- Put ``reSt.gedit-plugin`` file in Gedit's plugins directory. + Mine is (under Ubuntu Gutsy): ``/home/kib/.gnome2/gedit/plugins`` + +- Copy/Paste the ``reStPlugin`` folder inside ``/home/kib/.gnome2/gedit/plugins``. + +Readme.rst and Readme.odt are just help files, you can do whatever you want with them. + +You should then obtain something like this : :: + + .../plugins/ + reSt.gedit-plugin + reStPlugin/ + __init__.py + makeTable.py + etc. + +Using +----- + +Activate the plugin via Edit/Préférences/Plugins and turn the +``reStructuredText plugin`` box on. + +The plugin is now activated, and you should have a new panel inside the +bottom pane named ``reSt Preview``. + +Shortcuts +######### + +There's only one shortcut for the moment, maybe I'll create some others in the +future. + +``Ctrl+Maj+R`` : is used to refresh the generated HTML view inside +``reSt Preview`` pane. If there's some selected text, the conversion process +will only apply on it. If there's no selection, the entire document is +processed. It may be usefull for testing. + +Menu +#### + +The ``Tools`` menu is populated with several options : + +- ``reSt Preview`` is the same as the above; +- ``Create table`` is usefull for creating simple reStructuredText tables. + +Example : Enter the two folling lines in gedit, select them and activate +``Create table`` : :: + + one,two,tree + First,Second,Third + +The output will be : + +========= ========== ========= + one two tree +========= ========== ========= + First Second Third +========= ========== ========= + +- ``Paste Code`` maybe usefull to paste some parts of code using + `Pygments `_'s ``sourcecode`` directive. + Just invoque ``Paste Code`` with something in your clipboard and + you're done. You'll have to adjust the language afterwards. + +- ``--> HTML``, ``--> LaTeX``, ``--> OpenOffice``: are convenient ways to + export your reStructuredText docs to the given formats with custom * + stylesheets. You're free to modify them, even to propose your own because + I'm not a CSS ace :) + +Hoping it helps you, to contact me, drop me a message here : kib2 at free.fr + +See you, + +Kib. diff --git a/doc/ReadMe.html b/doc/ReadMe.html new file mode 100644 index 0000000..32c54c3 --- /dev/null +++ b/doc/ReadMe.html @@ -0,0 +1,408 @@ + + + + + + +Documentation de reStructuredText plugin + + + +
+

Documentation de reStructuredText plugin

+ +

Cette documentation est très restreinte, merci de patienter qu'elle s'étoffe +un peu.

+
+

Dépendances

+ +
+
+

Installation

+

Placez le fichier reSt.gedit-plugin dans votre dossier plugins de Gedit. +Le mien se situe ici par exemple : +/home/kib/.gnome2/gedit/plugins

+

Ensuite, copier /coller le dossier nommé reStPlugin dans ce même +répertoire.

+

Les fichiers Readme.rst et Readme.odt ne sont là que pour vous aider, vous +pourrez ensuite les placer à la poubelle si le coeur vous en dit !

+

L'arborescence devrait donc être la suivante :

+
+.../plugins/
+        reSt.gedit-plugin
+        reStPlugin/
+            __init__.py
+            makeTable.py
+            etc.
+
+
+
+

Utilisation

+

Activez le plugin via Editions/Préférences onglet Plugins et cochez +reStructuredText plugin.

+

Le plugin est actif, vous devriez obtenir un nouvel onglet dans votre panneau +inférieur nommé reSt Preview.

+
+

Raccourcis

+

Ctrl+Maj+R permet d'afficher le contenu de votre fichier reSt (extension .rst) +dans le nouveau panneau. Si une selection est active, la conversion ne se fera +que sur celle-ci, sinon c'est tout le document qui est pris en charge.

+
+ +
+
+ + diff --git a/doc/ReadMe.odt b/doc/ReadMe.odt new file mode 100644 index 0000000..19b0495 Binary files /dev/null and b/doc/ReadMe.odt differ diff --git a/doc/ReadMe.rst b/doc/ReadMe.rst new file mode 100644 index 0000000..59b5e75 --- /dev/null +++ b/doc/ReadMe.rst @@ -0,0 +1,86 @@ +Documentation de reStructuredText plugin +======================================== + +Cette documentation est très restreinte, merci de patienter qu'elle s'étoffe +un peu. + +Dépendances +------------ + +- Python >= 2.5 +- Pygments [http://pygments.org/] +- Docutils [http://docutils.sourceforge.net/] +- OdtWriter [http://www.rexx.com/~dkuhlman/odtwriter.html] + +Installation +------------ + +Placez le fichier ``reSt.gedit-plugin`` dans votre dossier plugins de Gedit. +Le mien se situe ici par exemple : +/home/kib/.gnome2/gedit/plugins + +Ensuite, copier /coller le dossier nommé ``reStPlugin`` dans ce même +répertoire. + +Les fichiers Readme.rst et Readme.odt ne sont là que pour vous aider, vous +pourrez ensuite les placer à la poubelle si le coeur vous en dit ! + +L'arborescence devrait donc être la suivante : :: + + .../plugins/ + reSt.gedit-plugin + reStPlugin/ + __init__.py + makeTable.py + etc. + +Utilisation +----------- + +Activez le plugin via Editions/Préférences onglet Plugins et cochez +``reStructuredText plugin``. + +Le plugin est actif, vous devriez obtenir un nouvel onglet dans votre panneau +inférieur nommé ``reSt Preview``. + +Raccourcis +########## + +Ctrl+Maj+R permet d'afficher le contenu de votre fichier reSt (extension .rst) +dans le nouveau panneau. Si une selection est active, la conversion ne se fera +que sur celle-ci, sinon c'est tout le document qui est pris en charge. + +Menu +#### + +Le menu ``Outils`` dispose maintenant de plusieurs options : + +- ``reSt Preview`` a déjà été détaillé précédemment; +- ``Create table`` permet de réaliser des tableaux simples. + + Exemple : Entrer ces deux lignes, sélectionnez-les et activez ``Create table`` + + un,deux,trois + + premiere,seconde,troisieme + + Cela donne : + +============ =========== ============= + un deux trois +============ =========== ============= +premiere seconde troisieme +============ =========== ============= + +- ``Paste Code`` permet de copier/coller des codes sources façon Pygments. + Selectionnez juste du code à copier, et utilisez cette macro. Vous devrez + ensuite ajuster le langage vous même. + +- ``--> HTML``, ``--> LaTeX``, ``--> OpenOffice``: permettent respectivement + un export de votre document dans ces formats respectifs. L'export à lieu + dans le même dossier que votre document initial. Des feuilles de style sont + fournies, ce sera à vous de les adapter à vos besoins. + +En espérant que ce petit plugin vous aidera, n'hésitez-pas à me contacter : + +Kib. diff --git a/doc/ReadMe_en.html b/doc/ReadMe_en.html new file mode 100644 index 0000000..f161e17 --- /dev/null +++ b/doc/ReadMe_en.html @@ -0,0 +1,416 @@ + + + + + + +reStructuredText plugin + + + +
+

reStructuredText plugin

+ +

This is a little how-to for using the reStructuredText plugin inside +GEdit .

+
reSt Plugin Image
+
+
+

Dépendancies

+ +
+
+

Installation

+

Unpack the zip file where you wanted to then :

+
    +
  • Put reSt.gedit-plugin file in Gedit's plugins directory. +Mine is (under Ubuntu Gutsy): /home/kib/.gnome2/gedit/plugins
  • +
  • Copy/Paste the reStPlugin folder inside /home/kib/.gnome2/gedit/plugins.
  • +
+

Readme.rst and Readme.odt are just help files, you can do whatever you want with them.

+

You should then obtain something like this :

+
+.../plugins/
+        reSt.gedit-plugin
+        reStPlugin/
+            __init__.py
+            makeTable.py
+            etc.
+
+
+
+

Using

+

Activate the plugin via Edit/Préférences/Plugins and turn the +reStructuredText plugin box on.

+

The plugin is now activated, and you should have a new panel inside the +bottom pane named reSt Preview.

+
+

Shortcuts

+

There's only one shortcut for the moment, maybe I'll create some others in the +future.

+

Ctrl+Maj+R : is used to refresh the generated HTML view inside +reSt Preview pane. If there's some selected text, the conversion process +will only apply on it. If there's no selection, the entire document is +processed. It may be usefull for testing.

+
+ +
+
+ + diff --git a/doc/ReadMe_en.odt b/doc/ReadMe_en.odt new file mode 100644 index 0000000..a1e1216 Binary files /dev/null and b/doc/ReadMe_en.odt differ diff --git a/doc/ReadMe_en.rst b/doc/ReadMe_en.rst new file mode 100644 index 0000000..8c46443 --- /dev/null +++ b/doc/ReadMe_en.rst @@ -0,0 +1,98 @@ +reStructuredText plugin +======================= + +This is a little how-to for using the reStructuredText plugin inside +`GEdit `_ . + +.. image:: http://farm3.static.flickr.com/2256/2259897373_d47ecf0983_o_d.png + :scale: 100 + :alt: reSt Plugin Image + :align: center + :target: http://farm3.static.flickr.com/2247/2259897529_aa85f5f540_b.jpg + + +Dépendancies +------------ + +- `Python `_ : version >= 2.5; +- `Pygments `_ : take the latest version; +- `reStructuredText `_ ; +- `odtwriter `_ : a reStructuredText addon to export in OpenOffice format. + +Installation +------------ +Unpack the zip file where you wanted to then : + +- Put ``reSt.gedit-plugin`` file in Gedit's plugins directory. + Mine is (under Ubuntu Gutsy): ``/home/kib/.gnome2/gedit/plugins`` + +- Copy/Paste the ``reStPlugin`` folder inside ``/home/kib/.gnome2/gedit/plugins``. + +Readme.rst and Readme.odt are just help files, you can do whatever you want with them. + +You should then obtain something like this : :: + + .../plugins/ + reSt.gedit-plugin + reStPlugin/ + __init__.py + makeTable.py + etc. + +Using +----- + +Activate the plugin via Edit/Préférences/Plugins and turn the +``reStructuredText plugin`` box on. + +The plugin is now activated, and you should have a new panel inside the +bottom pane named ``reSt Preview``. + +Shortcuts +######### + +There's only one shortcut for the moment, maybe I'll create some others in the +future. + +``Ctrl+Maj+R`` : is used to refresh the generated HTML view inside +``reSt Preview`` pane. If there's some selected text, the conversion process +will only apply on it. If there's no selection, the entire document is +processed. It may be usefull for testing. + +Menu +#### + +The ``Tools`` menu is populated with several options : + +- ``reSt Preview`` is the same as the above; +- ``Create table`` is usefull for creating simple reStructuredText tables. + +Example : Enter the two folling lines in gedit, select them and activate +``Create table`` : :: + + one,two,tree + First,Second,Third + +The output will be : + +========= ========== ========= + one two tree +========= ========== ========= + First Second Third +========= ========== ========= + +- ``Paste Code`` maybe usefull to paste some parts of code using + `Pygments `_'s ``sourcecode`` directive. + Just invoque ``Paste Code`` with something in your clipboard and + you're done. You'll have to adjust the language afterwards. + +- ``--> HTML``, ``--> LaTeX``, ``--> OpenOffice``: are convenient ways to + export your reStructuredText docs to the given formats with custom * + stylesheets. You're free to modify them, even to propose your own because + I'm not a CSS ace :) + +Hoping it helps you, to contact me, drop me a message here : kib2 at free.fr + +See you, + +Kib. diff --git a/doc/reStPlugin.png b/doc/reStPlugin.png new file mode 100644 index 0000000..ed7970c Binary files /dev/null and b/doc/reStPlugin.png differ diff --git a/reStPlugin/RegisterPygment.py b/reStPlugin/RegisterPygment.py old mode 100755 new mode 100644 index 888db55..fdb2af0 --- a/reStPlugin/RegisterPygment.py +++ b/reStPlugin/RegisterPygment.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python + # Copyright (C) 2007 Christophe Kibleur # # This file is part of reSTinPeace (http://kib2.alwaysdata.net). @@ -14,51 +15,38 @@ # GNU General Public License for more details. from docutils import nodes -from docutils.parsers.rst import directives, Directive +from docutils.parsers.rst import directives +from docutils.core import publish_cmdline, publish_file, Publisher, default_description ## Pygments from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter - -class Pygments(Directive): - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = True - option_spec = { - 'linenos': directives.flag, - 'hl_lines': directives.positive_int_list, - 'linenostart': directives.nonnegative_int, - 'linenostep': directives.positive_int, - 'linenospecial': directives.nonnegative_int, - 'nobackground': directives.flag, - 'anchorlinenos': directives.flag, - 'noclasses': directives.flag, - } - has_content = True - - def run(self): - self.assert_has_content() - try: - lexer = get_lexer_by_name(self.arguments[0]) - except ValueError: - # no lexer found - lexer = get_lexer_by_name('text') - - options={} - for (option, converter) in self.option_spec.iteritems(): - if converter == directives.flag: - if option in self.options: - options[option] = True - elif option in self.options: - options[option] = self.options[option] - - formatter = HtmlFormatter(**options) - parsed = highlight(u'\n'.join(self.content), lexer, formatter) - return [nodes.raw('', parsed, format='html')] - -directives.register_directive('code', Pygments) -directives.register_directive('code-block', Pygments) -directives.register_directive('sourcecode', Pygments) -directives.register_directive('sourcecode-block', Pygments) - +from pygments.styles import STYLE_MAP +from pygments.styles import get_style_by_name +from pygments.token import Keyword, Name, Comment, String, Error, \ + Number, Operator, Generic, Whitespace + +PYGMENTS_FORMATTER = HtmlFormatter(option='nowrap') +def pygments_directive(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + try: + lexer = get_lexer_by_name(arguments[0]) + except ValueError: + # no lexer found + lexer = get_lexer_by_name('text') + parsed = highlight(u'\n'.join(content), lexer, PYGMENTS_FORMATTER) + return [nodes.raw('', parsed, format='html')] +pygments_directive.arguments = (1, 0, 1) +pygments_directive.content = 1 +directives.register_directive('sourcecode', pygments_directive) + +import locale +try: + locale.setlocale(locale.LC_ALL, '') +except: + pass + +if __name__ == "__main__": + import docutils.core + publish_string(writer_name='html') diff --git a/reStPlugin/__init__.py b/reStPlugin/__init__.py index e346141..c045fc9 100644 --- a/reStPlugin/__init__.py +++ b/reStPlugin/__init__.py @@ -20,12 +20,11 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import gedit + import os import sys import gtk import gtkhtml2 -import gnomevfs -import subprocess from gettext import gettext as _ from makeTable import toRSTtable @@ -86,8 +85,6 @@ """ -ALLOWED_SCHEME = ('http', 'https', 'ftp', 'ftps', 'mailto', 'file') - class restPlugin(gedit.Plugin): def __init__(self): @@ -109,8 +106,6 @@ def activate(self, window): html_view = gtkhtml2.View() html_doc = gtkhtml2.Document() - html_doc.connect('request-url', self.request_url) - html_doc.connect('link-clicked', self.link_clicked) html_view.set_document(html_doc) html_doc.clear() @@ -131,7 +126,6 @@ def activate(self, window): bottom.add_item(scrolled_window, "reSt Preview", image) windowdata["bottom_panel"] = scrolled_window windowdata["html_doc"] = html_doc - windowdata["html_view"] = html_view manager = window.get_ui_manager() @@ -170,73 +164,13 @@ def deactivate(self, window): # Remove the menu action manager = window.get_ui_manager() - manager.remove_ui(windowdata["ui_id"]) + manager.remove_action_ui(windowdata["ui_id"]) manager.remove_action_group(windowdata["action_group"]) # Remove the bottom panel bottom = window.get_bottom_panel() bottom.remove_item(windowdata["bottom_panel"]) - def request_url(self, doc, url, stream): - gdoc = self._window.get_active_document() - if not gdoc: - source_path = None - else: - source_path = gdoc.get_location() - if source_path: - source_path = gnomevfs.URI(source_path.get_uri()) - - if source_path: - url = source_path.resolve_relative(url) - - try: - f = gnomevfs.open(url, gnomevfs.OPEN_READ) - except: - print "Error opening url", url - stream.close() - return - - while True: - try: - stream.write(f.read (1024)) - except gnomevfs.EOFError: - break - f.close() - stream.close() - - def link_clicked(self, object, link): - # Retreive the data of the window object - windowdata = self._window.get_data("reStPreviewData") - - if link.startswith('#'): - windowdata['html_view'].jump_to_anchor(link) - return - - gdoc = self._window.get_active_document() - if not gdoc: - source_path = None - else: - source_path = gdoc.get_location() - if source_path: - source_path = gnomevfs.URI(source_path.get_uri()) - - if source_path: - url = source_path.resolve_relative(link) - else: - url = gnomevfs.URI(link) - - command = ['gnome-open', str(url)] - - # Avoid to run the browser as user root - if os.getuid() == 0 and os.environ.has_key('SUDO_USER'): - command = ['sudo', '-u', os.environ['SUDO_USER']] + command - - if url.scheme in ALLOWED_SCHEME: - subprocess.Popen(command) - return - - print "clicked = %r" % link - def getSelection(self, window): windowdata = window.get_data("reStPreviewData") @@ -264,14 +198,6 @@ def on_update_preview(self, window): if not view: return - gdoc = self._window.get_active_document() - if not gdoc: - source_path = None - else: - source_path = gdoc.get_location() - if source_path: - source_path = source_path.get_path() - doc = view.get_buffer() start = doc.get_start_iter() @@ -282,7 +208,13 @@ def on_update_preview(self, window): end = doc.get_iter_at_mark(doc.get_selection_bound()) text = doc.get_text(start, end) - html = publish_parts(text, source_path=source_path, writer_name="html")["html_body"] + html = publish_parts(text, writer_name="html")["html_body"] + + ## Sortie + sortie = '\n'.join([START_HTML,html,END_HTML]) + fs = open('sortie.html','w') + fs.write(sortie) + fs.close() p = windowdata["bottom_panel"].get_placement() diff --git a/reStPlugin/default.sty b/reStPlugin/default.sty old mode 100755 new mode 100644 diff --git a/reStPlugin/to_html.py b/reStPlugin/to_html.py old mode 100755 new mode 100644 diff --git a/reStPlugin/to_odt.py b/reStPlugin/to_odt.py old mode 100755 new mode 100644 diff --git a/reStPlugin/to_tex.py b/reStPlugin/to_tex.py old mode 100755 new mode 100644