diff options
Diffstat (limited to 'docutils/tools')
| -rwxr-xr-x | docutils/tools/buildhtml.py | 227 | ||||
| -rwxr-xr-x | docutils/tools/docutils-xml.py | 25 | ||||
| -rw-r--r-- | docutils/tools/docutils.conf | 15 | ||||
| -rw-r--r-- | docutils/tools/editors/README.txt | 12 | ||||
| -rw-r--r-- | docutils/tools/editors/emacs/restructuredtext.el | 149 | ||||
| -rw-r--r-- | docutils/tools/editors/emacs/rst-html.el | 129 | ||||
| -rw-r--r-- | docutils/tools/editors/emacs/rst-mode.el | 696 | ||||
| -rwxr-xr-x | docutils/tools/html.py | 25 | ||||
| -rw-r--r-- | docutils/tools/pep-html-template | 27 | ||||
| -rwxr-xr-x | docutils/tools/pep.py | 27 | ||||
| -rwxr-xr-x | docutils/tools/pep2html.py | 531 | ||||
| -rwxr-xr-x | docutils/tools/publish.py | 25 | ||||
| -rwxr-xr-x | docutils/tools/quicktest.py | 211 | ||||
| -rwxr-xr-x | docutils/tools/rst2latex.py | 25 | ||||
| -rw-r--r-- | docutils/tools/stylesheets/default.css | 224 | ||||
| -rw-r--r-- | docutils/tools/stylesheets/pep.css | 240 | ||||
| -rwxr-xr-x | docutils/tools/unicode2rstsubs.py | 195 |
17 files changed, 0 insertions, 2783 deletions
diff --git a/docutils/tools/buildhtml.py b/docutils/tools/buildhtml.py deleted file mode 100755 index dfba99945..000000000 --- a/docutils/tools/buildhtml.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -Generates .html from all the .txt files in a directory. - -Ordinary .txt files are understood to be standalone reStructuredText. -Files named ``pep-*.txt`` are interpreted as PEPs (either old-style or -new reStructuredText PEPs). -""" -# Once PySource is here, build .html from .py as well. - -__docformat__ = 'reStructuredText' - - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -import sys -import os -import os.path -import copy -import docutils -from docutils import ApplicationError -from docutils import core, frontend -from docutils.parsers import rst -from docutils.readers import standalone, pep -from docutils.writers import html4css1, pep_html - - -usage = '%prog [options] [<directory> ...]' -description = ('Generates .html from all the .txt files (including PEPs) ' - 'in each <directory> (default is the current directory).') - - -class SettingsSpec(docutils.SettingsSpec): - - """ - Runtime settings & command-line options for the front end. - """ - - # Can't be included in OptionParser below because we don't want to - # override the base class. - settings_spec = ( - 'Build-HTML Options', - None, - (('Recursively scan subdirectories for files to process. This is ' - 'the default.', - ['--recurse'], {'action': 'store_true', 'default': 1}), - ('Do not scan subdirectories for files to process.', - ['--local'], {'dest': 'recurse', 'action': 'store_false'}), - ('Work silently (no progress messages). Independent of "--quiet".', - ['--silent'], {'action': 'store_true'}),)) - - -class OptionParser(frontend.OptionParser): - - """ - Command-line option processing for the ``buildhtml.py`` front end. - """ - - def check_values(self, values, args): - frontend.OptionParser.check_values(self, values, args) - values._source = None - return values - - def check_args(self, args): - source = destination = None - if args: - self.values._directories = args - else: - self.values._directories = [os.getcwd()] - return source, destination - - -class Struct: - - """Stores data attributes for dotted-attribute access.""" - - def __init__(self, **keywordargs): - self.__dict__.update(keywordargs) - - -class Builder: - - def __init__(self): - self.publishers = { - '': Struct(components=(SettingsSpec, pep.Reader, rst.Parser, - pep_html.Writer)), - '.txt': Struct(components=(rst.Parser, standalone.Reader, - html4css1.Writer)), - 'PEPs': Struct(components=(rst.Parser, pep.Reader, - pep_html.Writer))} - """Publisher-specific settings. Key '' is for the front-end script - itself. ``self.publishers[''].components`` must contain a superset of - all components used by individual publishers.""" - - self.setup_publishers() - - def setup_publishers(self): - """ - Manage configurations for individual publishers. - - Each publisher (combination of parser, reader, and writer) may have - its own configuration defaults, which must be kept separate from those - of the other publishers. Setting defaults are combined with the - config file settings and command-line options by - `self.get_settings()`. - """ - for name, publisher in self.publishers.items(): - option_parser = OptionParser( - components=publisher.components, - usage=usage, description=description) - publisher.option_parser = option_parser - publisher.setting_defaults = option_parser.get_default_values() - frontend.make_paths_absolute(publisher.setting_defaults.__dict__, - option_parser.relative_path_settings) - config_parser = frontend.ConfigParser() - config_parser.read_standard_files(option_parser) - self.config_settings = config_parser.get_section('options') - frontend.make_paths_absolute( - self.config_settings, - self.publishers[''].option_parser.relative_path_settings) - self.settings_spec = self.publishers[''].option_parser.parse_args( - values=frontend.Values()) # no defaults; just the cmdline opts - self.initial_settings = self.get_settings('') - - def get_settings(self, publisher_name, directory=None): - """ - Return a settings object, from multiple sources. - - Copy the setting defaults, overlay the startup config file settings, - then the local config file settings, then the command-line options. - Assumes the current directory has been set. - """ - publisher = self.publishers[publisher_name] - settings = copy.deepcopy(publisher.setting_defaults) - settings.__dict__.update(self.config_settings) - if directory: - config_parser = frontend.ConfigParser() - config_parser.read(os.path.join(directory, 'docutils.conf'), - publisher.option_parser) - local_config = config_parser.get_section('options') - frontend.make_paths_absolute( - local_config, publisher.option_parser.relative_path_settings, - directory) - settings.__dict__.update(local_config) - settings.__dict__.update(self.settings_spec.__dict__) - return settings - - def run(self, directory=None, recurse=1): - recurse = recurse and self.initial_settings.recurse - if directory: - self.directories = [directory] - elif self.settings_spec._directories: - self.directories = self.settings_spec._directories - else: - self.directories = [os.getcwd()] - for directory in self.directories: - os.path.walk(directory, self.visit, recurse) - - def visit(self, recurse, directory, names): - if not self.initial_settings.silent: - print >>sys.stderr, '/// Processing directory:', directory - sys.stderr.flush() - peps_found = 0 - for name in names: - if name.endswith('.txt'): - if name.startswith('pep-'): - peps_found = 1 - else: - self.process_txt(directory, name) - if peps_found: - self.process_peps(directory) - if not recurse: - del names[:] - - def process_txt(self, directory, name): - settings = self.get_settings('.txt', directory) - settings._source = os.path.normpath(os.path.join(directory, name)) - settings._destination = settings._source[:-4]+'.html' - if not self.initial_settings.silent: - print >>sys.stderr, ' ::: Processing .txt:', name - sys.stderr.flush() - try: - core.publish_file(source_path=settings._source, - destination_path=settings._destination, - reader_name='standalone', - parser_name='restructuredtext', - writer_name='html', - settings=settings) - except ApplicationError, error: - print >>sys.stderr, (' Error (%s): %s' - % (error.__class__.__name__, error)) - - def process_peps(self, directory): - # only import PEP module/script if we need it. - import pep2html - - settings = self.get_settings('PEPs', directory) - old_directory = os.getcwd() - os.chdir(directory) - if self.initial_settings.silent: - argv = ['-q'] - else: - print >>sys.stderr, ' ::: Processing PEPs:' - sys.stderr.flush() - argv = [] - pep2html.docutils_settings = settings - try: - pep2html.main(argv) - except Exception, error: - print >>sys.stderr, (' Error (%s): %s' - % (error.__class__.__name__, error)) - os.chdir(old_directory) - - -if __name__ == "__main__": - Builder().run() diff --git a/docutils/tools/docutils-xml.py b/docutils/tools/docutils-xml.py deleted file mode 100755 index 42c879cc8..000000000 --- a/docutils/tools/docutils-xml.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -A minimal front end to the Docutils Publisher, producing Docutils XML. -""" - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -from docutils.core import publish_cmdline, default_description - - -description = ('Generates Docutils-native XML from standalone ' - 'reStructuredText sources. ' + default_description) - -publish_cmdline(writer_name='xml', description=description) diff --git a/docutils/tools/docutils.conf b/docutils/tools/docutils.conf deleted file mode 100644 index 63d8f4f5b..000000000 --- a/docutils/tools/docutils.conf +++ /dev/null @@ -1,15 +0,0 @@ -[options] - -# These entries affect all processing: -source-link: 1 -datestamp: %Y-%m-%d %H:%M UTC -generator: 1 - -# These entries affect HTML output: -stylesheet-path: stylesheets/default.css - -# These entries affect reStructuredText-style PEPs: -pep-template: pep-html-template -pep-stylesheet-path: stylesheets/pep.css -python-home: http://www.python.org -no-random: 1 diff --git a/docutils/tools/editors/README.txt b/docutils/tools/editors/README.txt deleted file mode 100644 index 8e489f447..000000000 --- a/docutils/tools/editors/README.txt +++ /dev/null @@ -1,12 +0,0 @@ -====================================== - Editor Support for reStructuredText_ -====================================== - -:Date: $Date$ - -The files in this directory contain support code for reStructuredText -editing for the following editors: - -* `Emacs <emacs>`__ - -.. _reStructuredText: http://docutils.sf.net/rst.html diff --git a/docutils/tools/editors/emacs/restructuredtext.el b/docutils/tools/editors/emacs/restructuredtext.el deleted file mode 100644 index 15cd4054e..000000000 --- a/docutils/tools/editors/emacs/restructuredtext.el +++ /dev/null @@ -1,149 +0,0 @@ -;; Authors: David Goodger <goodger@python.org>; -;; Martin Blais -;; Date: $Date$ -;; Copyright: This module has been placed in the public domain. -;; -;; Support code for editing reStructuredText with Emacs indented-text mode. -;; The goal is to create an integrated reStructuredText editing mode. -;; -;; Updates -;; ------- -;; -;; 2003-02-25 (blais): updated repeat-last-character function and added -;; a few routines for navigating between titles. - -(defun replace-lines (fromchar tochar) - ;; by David Goodger - "Replace flush-left lines, consisting of multiple FROMCHAR characters, -with equal-length lines of TOCHAR." - (interactive "\ -cSearch for flush-left lines of char: -cand replace with char: ") - (save-excursion - (let* ((fromstr (string fromchar)) - (searchre (concat "^" (regexp-quote fromstr) "+ *$")) - (found 0)) - (condition-case err - (while t - (search-forward-regexp searchre) - (setq found (1+ found)) - (search-backward fromstr) ;; point will be *before* last char - (setq p (1+ (point))) - (beginning-of-line) - (setq l (- p (point))) - (kill-line) - (insert-char tochar l)) - (search-failed - (message (format "%d lines replaced." found))))))) - -(defun repeat-last-character () - ;; by Martin Blais - "Fills the current line up to the length of the preceding line (if not empty), -using the last character on the current line. If the preceding line is empty, -or if a prefix argument is provided, fill up to the fill-column. - -If the current line is longer than the desired length, shave the characters off -the current line to fit the desired length. - -As an added convenience, if the command is repeated immediately, the alternative -behaviour is performed." - -;; TODO -;; ---- -;; It would be useful if only these characters were repeated: -;; =-`:.'"~^_*+#<>!$%&(),/;?@[\]{|} -;; Especially, empty lines shouldn't be repeated. - - (interactive) - (let* ((curcol (current-column)) - (curline (+ (count-lines (point-min) (point)) (if (eq curcol 0) 1 0))) - (lbp (line-beginning-position 0)) - (prevcol (if (= curline 1) - fill-column - (save-excursion - (forward-line -1) - (end-of-line) - (skip-chars-backward " \t" lbp) - (let ((cc (current-column))) - (if (= cc 0) fill-column cc))))) - (rightmost-column - (cond (current-prefix-arg fill-column) - ((equal last-command 'repeat-last-character) - (if (= curcol fill-column) prevcol fill-column)) - (t (save-excursion - (if (= prevcol 0) fill-column prevcol))) )) ) - (end-of-line) - (if (> (current-column) rightmost-column) - ;; shave characters off the end - (delete-region (- (point) - (- (current-column) rightmost-column)) - (point)) - ;; fill with last characters - (insert-char (preceding-char) - (- rightmost-column (current-column)))) )) - -(defun reST-title-char-p (c) - ;; by Martin Blais - "Returns true if the given character is a valid title char." - (and (string-match "[-=`:\\.'\"~^_*+#<>!$%&(),/;?@\\\|]" - (char-to-string c)) t)) - -(defun reST-forward-title () - ;; by Martin Blais - "Skip to the next restructured text section title." - (interactive) - (let* ( (newpoint - (save-excursion - (forward-char) ;; in case we're right on a title - (while - (not - (and (re-search-forward "^[A-Za-z0-9].*[ \t]*$" nil t) - (reST-title-char-p (char-after (+ (point) 1))) - (looking-at (format "\n%c\\{%d,\\}[ \t]*$" - (char-after (+ (point) 1)) - (current-column)))))) - (beginning-of-line) - (point))) ) - (if newpoint (goto-char newpoint)) )) - -(defun reST-backward-title () - ;; by Martin Blais - "Skip to the previous restructured text section title." - (interactive) - (let* ( (newpoint - (save-excursion - ;;(forward-char) ;; in case we're right on a title - (while - (not - (and (or (backward-char) t) - (re-search-backward "^[A-Za-z0-9].*[ \t]*$" nil t) - (or (end-of-line) t) - (reST-title-char-p (char-after (+ (point) 1))) - (looking-at (format "\n%c\\{%d,\\}[ \t]*$" - (char-after (+ (point) 1)) - (current-column)))))) - (beginning-of-line) - (point))) ) - (if newpoint (goto-char newpoint)) )) - -(defun join-paragraph () - ;; by David Goodger - "Join lines in current paragraph into one line, removing end-of-lines." - (interactive) - (save-excursion - (backward-paragraph 1) - (forward-char 1) - (let ((start (point))) ; remember where we are - (forward-paragraph 1) ; go to the end of the paragraph - (beginning-of-line 0) ; go to the beginning of the previous line - (while (< start (point)) ; as long as we haven't passed where we started - (delete-indentation) ; join this line to the line before - (beginning-of-line))))) ; and go back to the beginning of the line - -(defun force-fill-paragraph () - ;; by David Goodger - "Fill paragraph at point, first joining the paragraph's lines into one. -This is useful for filling list item paragraphs." - (interactive) - (join-paragraph) - (fill-paragraph nil)) diff --git a/docutils/tools/editors/emacs/rst-html.el b/docutils/tools/editors/emacs/rst-html.el deleted file mode 100644 index c9ebf33ef..000000000 --- a/docutils/tools/editors/emacs/rst-html.el +++ /dev/null @@ -1,129 +0,0 @@ -;;; rst-mode.el --- Goodies to automate converting reST documents to HTML. - -;; Copyright 2003 Martin Blais <blais@iro.umontreal.ca> -;; -;; 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 of the License, 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, write to the Free Software -;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -;;; Commentary: - -;; This package provides a few functions and variables that can help in -;; automating converting reST documents to HTML from within emacs. You could -;; use a makefile to do this, of use the compile command that this package -;; provides. - -;; You can also bind a command to automate converting to HTML: -;; (defun user-rst-mode-hook () -;; (local-set-key [(control c)(?9)] 'rst-html-compile)) -;; (add-hook 'rst-mode-hook 'user-rst-mode-hook) - -;;; Code: - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Customization: - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defgroup rst-html nil - "Settings for conversion to HTML available by \\[rst-html-compile]. Use of -this functionality is discouraged. Get a proper `Makefile' instead." - :group 'rst - :version "21.1") - -(defcustom rst-html-command "docutils-html" - "Command to convert an reST file to HTML." - :group 'rst-html - :type '(string)) - -(defcustom rst-html-stylesheet "" - "Stylesheet for reST to HTML conversion. Empty for no special stylesheet." - :group 'rst-html - :type '(string)) - -(defcustom rst-html-options "" - "Local file options for reST to HTML conversion. -Stylesheets are set by an own option." - :group 'rst-html - :type '(string)) - -(defcustom rst-html-extension ".html" - "Extension for HTML output file." - :group 'rst-html - :type '(string)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Conversion to HTML - -(defun rst-html-compile () - "Compile command to convert reST document into HTML." - (interactive) - (let* ((bufname (file-name-nondirectory buffer-file-name)) - (outname (file-name-sans-extension bufname)) - (ssheet - (or (and (not (zerop (length rst-html-stylesheet))) - (concat "--stylesheet=\"" rst-html-stylesheet "\"")) - ""))) - (set (make-local-variable 'compile-command) - (mapconcat 'identity - (list rst-html-command - ssheet rst-html-options - bufname (concat outname rst-html-extension)) - " ")) - (if (or compilation-read-command current-prefix-arg) - (call-interactively 'compile) - (compile compile-command)) - )) - -(defun rst-html-compile-with-conf () - "Compile command to convert reST document into HTML. Attempts to find -configuration file, if it can, overrides the options." - (interactive) - (let ((conffile (rst-html-find-conf))) - (if conffile - (let* ((bufname (file-name-nondirectory buffer-file-name)) - (outname (file-name-sans-extension bufname))) - (set (make-local-variable 'compile-command) - (mapconcat 'identity - (list rst-html-command - (concat "--config=\"" conffile "\"") - bufname (concat outname rst-html-extension)) - " ")) - (if (or compilation-read-command current-prefix-arg) - (call-interactively 'compile) - (compile compile-command))) - (call-interactively 'rst-html-compile) - ))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Find the configuration file in the parents. - -(defun rst-html-find-conf () - "Look for the configuration file in the parents of the current path." - (interactive) - (let ((file-name "docutils.conf") - (buffer-file (buffer-file-name))) - ;; Move up in the dir hierarchy till we find a change log file. - (let ((dir (file-name-directory buffer-file))) - (while (and (or (not (string= "/" dir)) (setq dir nil) nil) - (not (file-exists-p (concat dir file-name)))) - ;; Move up to the parent dir and try again. - (setq dir (expand-file-name (file-name-directory - (directory-file-name - (file-name-directory dir))))) ) - (or (and dir (concat dir file-name)) nil) - ))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; rst-mode.el ends here diff --git a/docutils/tools/editors/emacs/rst-mode.el b/docutils/tools/editors/emacs/rst-mode.el deleted file mode 100644 index 3f81da39c..000000000 --- a/docutils/tools/editors/emacs/rst-mode.el +++ /dev/null @@ -1,696 +0,0 @@ -;;; rst-mode.el --- Mode for viewing and editing reStructuredText-documents. - -;; Copyright 2003 Stefan Merten <smerten@oekonux.de> -;; -;; 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 of the License, 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, write to the Free Software -;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -;;; Commentary: - -;; This package provides support for documents marked up using the -;; reStructuredText format -;; [http://docutils.sourceforge.net/spec/rst/reStructuredText.html]. Support -;; includes font locking as well as some convenience functions for editing. - -;; The package is based on `text-mode' and inherits some things from it. -;; Particularly `text-mode-hook' is run before `rst-mode-hook'. - -;; Add the following lines to your `.emacs' file: -;; -;; (autoload 'rst-mode "rst-mode" "mode for editing reStructuredText documents" t) -;; (setq auto-mode-alist -;; (append '(("\\.rst$" . rst-mode) -;; ("\\.rest$" . rst-mode)) auto-mode-alist)) -;; -;; If you are using `.txt' as a standard extension for reST files as -;; http://docutils.sourceforge.net/FAQ.html#what-s-the-standard-filename-extension-for-a-restructuredtext-file -;; suggests you may use one of the `Local Variables in Files' mechanism Emacs -;; provides to set the major mode automatically. For instance you may use -;; -;; .. -*- mode: rst -*- -;; -;; in the very first line of your file. However, because this is a major -;; security breach you or your administrator may have chosen to switch that -;; feature off. See `Local Variables in Files' in the Emacs documentation for a -;; more complete discussion. - -;;; Code: - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Customization: - -(defgroup rst nil "Support for reStructuredText documents" - :group 'wp - :version "21.1" - :link '(url-link "http://docutils.sourceforge.net/spec/rst/reStructuredText.html")) - -(defcustom rst-mode-hook nil - "Hook run when Rst Mode is turned on. The hook for Text Mode is run before - this one." - :group 'rst - :type '(hook)) - -(defcustom rst-mode-lazy t - "*If non-nil Rst Mode font-locks comment, literal blocks, and section titles -correctly. Because this is really slow it switches on Lazy Lock Mode -automatically. You may increase Lazy Lock Defer Time for reasonable results. - -If nil comments and literal blocks are font-locked only on the line they start. - -The value of this variable is used when Rst Mode is turned on." - :group 'rst - :type '(boolean)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defgroup rst-faces nil "Faces used in Rst Mode" - :group 'rst - :group 'faces - :version "21.1") - -(defcustom rst-block-face 'font-lock-keyword-face - "All syntax marking up a special block" - :group 'rst-faces - :type '(face)) - -(defcustom rst-external-face 'font-lock-type-face - "Field names and interpreted text" - :group 'rst-faces - :type '(face)) - -(defcustom rst-definition-face 'font-lock-function-name-face - "All other defining constructs" - :group 'rst-faces - :type '(face)) - -(defcustom rst-directive-face - ;; XEmacs compatibility - (if (boundp 'font-lock-builtin-face) - 'font-lock-builtin-face - 'font-lock-preprocessor-face) - "Directives and roles" - :group 'rst-faces - :type '(face)) - -(defcustom rst-comment-face 'font-lock-comment-face - "Comments" - :group 'rst-faces - :type '(face)) - -(defcustom rst-emphasis1-face - ;; XEmacs compatibility - (if (facep 'italic) - ''italic - 'italic) - "Simple emphasis" - :group 'rst-faces - :type '(face)) - -(defcustom rst-emphasis2-face - ;; XEmacs compatibility - (if (facep 'bold) - ''bold - 'bold) - "Double emphasis" - :group 'rst-faces - :type '(face)) - -(defcustom rst-literal-face 'font-lock-string-face - "Literal text" - :group 'rst-faces - :type '(face)) - -(defcustom rst-reference-face 'font-lock-variable-name-face - "References to a definition" - :group 'rst-faces - :type '(face)) - -;; Faces for displaying items on several levels; these definitions define -;; different shades of grey where the lightest one is used for level 1 -(defconst rst-level-face-max 6 - "Maximum depth of level faces defined") -(defconst rst-level-face-base-color "grey" - "The base color to be used for creating level faces") -(defconst rst-level-face-base-light 85 - "The lightness factor for the base color") -(defconst rst-level-face-format-light "%2d" - "The format for the lightness factor for the base color") -(defconst rst-level-face-step-light -7 - "The step width to use for next color") - -;; Define the faces -(let ((i 1)) - (while (<= i rst-level-face-max) - (let ((sym (intern (format "rst-level-%d-face" i))) - (doc (format "Face for showing section title text at level %d" i)) - (col (format (concat "%s" rst-level-face-format-light) - rst-level-face-base-color - (+ (* (1- i) rst-level-face-step-light) - rst-level-face-base-light)))) - (make-empty-face sym) - (set-face-doc-string sym doc) - (set-face-background sym col) - (set sym sym) - (setq i (1+ i))))) - -(defcustom rst-adornment-faces-alist - '((1 . rst-level-1-face) - (2 . rst-level-2-face) - (3 . rst-level-3-face) - (4 . rst-level-4-face) - (5 . rst-level-5-face) - (6 . rst-level-6-face) - (t . font-lock-keyword-face) - (nil . font-lock-keyword-face)) - "Provides faces for the various adornment types. Key is a number (for the -section title text of that level), t (for transitions) or nil (for section -title adornment)." - :group 'rst-faces - :type '(alist :key-type (choice (integer :tag "Section level") - (boolean :tag "transitions (on) / section title adornment (off)")) - :value-type (face))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; FIXME: Code from `restructuredtext.el' should be integrated - -(defvar rst-mode-syntax-table nil - "Syntax table used while in rst mode.") - -(unless rst-mode-syntax-table - (setq rst-mode-syntax-table (make-syntax-table text-mode-syntax-table)) - (modify-syntax-entry ?$ "." rst-mode-syntax-table) - (modify-syntax-entry ?% "." rst-mode-syntax-table) - (modify-syntax-entry ?& "." rst-mode-syntax-table) - (modify-syntax-entry ?' "." rst-mode-syntax-table) - (modify-syntax-entry ?* "." rst-mode-syntax-table) - (modify-syntax-entry ?+ "." rst-mode-syntax-table) - (modify-syntax-entry ?. "_" rst-mode-syntax-table) - (modify-syntax-entry ?/ "." rst-mode-syntax-table) - (modify-syntax-entry ?< "." rst-mode-syntax-table) - (modify-syntax-entry ?= "." rst-mode-syntax-table) - (modify-syntax-entry ?> "." rst-mode-syntax-table) - (modify-syntax-entry ?\\ "\\" rst-mode-syntax-table) - (modify-syntax-entry ?| "." rst-mode-syntax-table) - ) - -(defvar rst-mode-abbrev-table nil - "Abbrev table used while in rst mode.") -(define-abbrev-table 'rst-mode-abbrev-table ()) - -;; FIXME: Movement keys to skip forward / backward over or mark an indented -;; block could be defined; keys to markup section titles based on -;; `rst-adornment-level-alist' would be useful -(defvar rst-mode-map nil - "Keymap for rst mode. This inherits from Text mode.") - -(unless rst-mode-map - (setq rst-mode-map (copy-keymap text-mode-map))) - -(defun rst-mode () - "Major mode for editing reStructuredText documents. - -You may customize `rst-mode-lazy' to switch font-locking of blocks. - -\\{rst-mode-map} -Turning on `rst-mode' calls the normal hooks `text-mode-hook' and -`rst-mode-hook'." - (interactive) - (kill-all-local-variables) - - ;; Maps and tables - (use-local-map rst-mode-map) - (setq local-abbrev-table rst-mode-abbrev-table) - (set-syntax-table rst-mode-syntax-table) - - ;; For editing text - ;; - ;; FIXME: It would be better if this matches more exactly the start of a reST - ;; paragraph; however, this not always possible with a simple regex because - ;; paragraphs are determined by indentation of the following line - (set (make-local-variable 'paragraph-start) - (concat page-delimiter "\\|[ \t]*$")) - (if (eq ?^ (aref paragraph-start 0)) - (setq paragraph-start (substring paragraph-start 1))) - (set (make-local-variable 'paragraph-separate) paragraph-start) - (set (make-local-variable 'indent-line-function) 'indent-relative-maybe) - (set (make-local-variable 'adaptive-fill-mode) t) - (set (make-local-variable 'comment-start) ".. ") - - ;; Special variables - (make-local-variable 'rst-adornment-level-alist) - - ;; Font lock - (set (make-local-variable 'font-lock-defaults) - '(rst-font-lock-keywords-function - t nil nil nil - (font-lock-multiline . t) - (font-lock-mark-block-function . mark-paragraph))) - (when (boundp 'font-lock-support-mode) - ;; rst-mode has its own mind about font-lock-support-mode - (make-local-variable 'font-lock-support-mode) - (cond - ((and (not rst-mode-lazy) (not font-lock-support-mode))) - ;; No support mode set and none required - leave it alone - ((or (not font-lock-support-mode) ;; No support mode set (but required) - (symbolp font-lock-support-mode)) ;; or a fixed mode for all - (setq font-lock-support-mode - (list (cons 'rst-mode (and rst-mode-lazy 'lazy-lock-mode)) - (cons t font-lock-support-mode)))) - ((and (listp font-lock-support-mode) - (not (assoc 'rst-mode font-lock-support-mode))) - ;; A list of modes missing rst-mode - (setq font-lock-support-mode - (append '((cons 'rst-mode (and rst-mode-lazy 'lazy-lock-mode))) - font-lock-support-mode))))) - - ;; Names and hooks - (setq mode-name "reST") - (setq major-mode 'rst-mode) - (run-hooks 'text-mode-hook) - (run-hooks 'rst-mode-hook)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Font lock - -(defun rst-font-lock-keywords-function () - "Returns keywords to highlight in rst mode according to current settings." - ;; The reST-links in the comments below all relate to sections in - ;; http://docutils.sourceforge.net/spec/rst/reStructuredText.html - (let* ( ;; This gets big - so let's define some abbreviations - ;; horizontal white space - (re-hws "[\t ]") - ;; beginning of line with possible indentation - (re-bol (concat "^" re-hws "*")) - ;; Separates block lead-ins from their content - (re-blksep1 (concat "\\(" re-hws "+\\|$\\)")) - ;; explicit markup tag - (re-emt "\\.\\.") - ;; explicit markup start - (re-ems (concat re-emt re-hws "+")) - ;; inline markup prefix - (re-imp1 (concat "\\(^\\|" re-hws "\\|[-'\"([{</:]\\)")) - ;; inline markup suffix - (re-ims1 (concat "\\(" re-hws "\\|[]-'\")}>/:.,;!?\\]\\|$\\)")) - ;; symbol character - (re-sym1 "\\(\\sw\\|\\s_\\)") - ;; inline markup content begin - (re-imbeg2 "\\(\\S \\|\\S \\([^") - - ;; There seems to be a bug leading to error "Stack overflow in regexp - ;; matcher" when "|" or "\\*" are the characters searched for - (re-imendbeg - (if (< emacs-major-version 21) - "]" - "\\]\\|\\\\.")) - ;; inline markup content end - (re-imend (concat re-imendbeg "\\)*[^\t \\\\]\\)")) - ;; inline markup content without asterisk - (re-ima2 (concat re-imbeg2 "*" re-imend)) - ;; inline markup content without backquote - (re-imb2 (concat re-imbeg2 "`" re-imend)) - ;; inline markup content without vertical bar - (re-imv2 (concat re-imbeg2 "|" re-imend)) - ;; Supported URI schemes - (re-uris1 "\\(acap\\|cid\\|data\\|dav\\|fax\\|file\\|ftp\\|gopher\\|http\\|https\\|imap\\|ldap\\|mailto\\|mid\\|modem\\|news\\|nfs\\|nntp\\|pop\\|prospero\\|rtsp\\|service\\|sip\\|tel\\|telnet\\|tip\\|urn\\|vemmi\\|wais\\)") - ;; Line starting with adornment and optional whitespace; complete - ;; adornment is in (match-string 1); there must be at least 3 - ;; characters because otherwise explicit markup start would be - ;; recognized - (re-ado2 (concat "^\\(\\([" - (if (or - (< emacs-major-version 21) - (save-match-data - (string-match "XEmacs\\|Lucid" emacs-version))) - "^a-zA-Z0-9 \t\x00-\x1F" - "^[:word:][:space:][:cntrl:]") - "]\\)\\2\\2+\\)" re-hws "*$")) - ) - (list - ;; FIXME: Block markup is not recognized in blocks after explicit markup - ;; start - - ;; Simple `Body Elements`_ - ;; `Bullet Lists`_ - (list - (concat re-bol "\\([-*+]" re-blksep1 "\\)") - 1 rst-block-face) - ;; `Enumerated Lists`_ - (list - (concat re-bol "\\((?\\([0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]" re-blksep1 "\\)") - 1 rst-block-face) - ;; `Definition Lists`_ FIXME: missing - ;; `Field Lists`_ - (list - (concat re-bol "\\(:[^:]+:\\)" re-blksep1) - 1 rst-external-face) - ;; `Option Lists`_ - (list - (concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)") - 1 rst-block-face) - - ;; `Tables`_ FIXME: missing - - ;; All the `Explicit Markup Blocks`_ - ;; `Footnotes`_ / `Citations`_ - (list - (concat re-bol "\\(" re-ems "\\[[^[]+\\]\\)" re-blksep1) - 1 rst-definition-face) - ;; `Directives`_ / `Substitution Definitions`_ - (list - (concat re-bol "\\(" re-ems "\\)\\(\\(|[^|]+|[\t ]+\\)?\\)\\(" re-sym1 "+::\\)" re-blksep1) - (list 1 rst-directive-face) - (list 2 rst-definition-face) - (list 4 rst-directive-face)) - ;; `Hyperlink Targets`_ - (list - (concat re-bol "\\(" re-ems "_\\([^:\\`]\\|\\\\.\\|`[^`]+`\\)+:\\)" re-blksep1) - 1 rst-definition-face) - (list - (concat re-bol "\\(__\\)" re-blksep1) - 1 rst-definition-face) - - ;; All `Inline Markup`_ - ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented - ;; `Strong Emphasis`_ - (list - (concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1) - 2 rst-emphasis2-face) - ;; `Emphasis`_ - (list - (concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1) - 2 rst-emphasis1-face) - ;; `Inline Literals`_ - (list - (concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1) - 2 rst-literal-face) - ;; `Inline Internal Targets`_ - (list - (concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1) - 2 rst-definition-face) - ;; `Hyperlink References`_ - ;; FIXME: `Embedded URIs`_ not considered - (list - (concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\sw+\\)__?\\)" re-ims1) - 2 rst-reference-face) - ;; `Interpreted Text`_ - (list - (concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:" re-sym1 "+:\\)?\\)" re-ims1) - (list 2 rst-directive-face) - (list 5 rst-external-face) - (list 8 rst-directive-face)) - ;; `Footnote References`_ / `Citation References`_ - (list - (concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1) - 2 rst-reference-face) - ;; `Substitution References`_ - (list - (concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1) - 2 rst-reference-face) - ;; `Standalone Hyperlinks`_ - (list - ;; FIXME: This takes it easy by using a whitespace as delimiter - (concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1) - 2 rst-definition-face) - (list - (concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1) - 2 rst-definition-face) - - ;; Do all block fontification as late as possible so 'append works - - ;; Sections_ / Transitions_ - (append - (list - re-ado2) - (if (not rst-mode-lazy) - (list 1 rst-block-face) - (list - (list 'rst-font-lock-handle-adornment - '(progn - (setq rst-font-lock-adornment-point (match-end 1)) - (point-max)) - nil - (list 1 '(cdr (assoc nil rst-adornment-faces-alist)) - 'append t) - (list 2 '(cdr (assoc rst-font-lock-level rst-adornment-faces-alist)) - 'append t) - (list 3 '(cdr (assoc nil rst-adornment-faces-alist)) - 'append t))))) - - ;; `Comments`_ - (append - (list - (concat re-bol "\\(" re-ems "\\)\[^[|_]\\([^:]\\|:\\([^:]\\|$\\)\\)*$") - (list 1 rst-comment-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point (match-end 1)) - (point-max)) - nil - (list 0 rst-comment-face 'append))))) - (append - (list - (concat re-bol "\\(" re-emt "\\)\\(\\s *\\)$") - (list 1 rst-comment-face) - (list 2 rst-comment-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point 'next) - (point-max)) - nil - (list 0 rst-comment-face 'append))))) - - ;; `Literal Blocks`_ - (append - (list - (concat re-bol "\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$") - (list 3 rst-block-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point t) - (point-max)) - nil - (list 0 rst-literal-face 'append))))) - ))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Indented blocks - -(defun rst-forward-indented-block (&optional column limit) - "Move forward across one indented block. -Find the next non-empty line which is not indented at least to COLUMN (defaults -to the column of the point). Moves point to first character of this line or the -first empty line immediately before it and returns that position. If there is -no such line before LIMIT (defaults to the end of the buffer) returns nil and -point is not moved." - (interactive) - (let ((clm (or column (current-column))) - (start (point)) - fnd beg cand) - (if (not limit) - (setq limit (point-max))) - (save-match-data - (while (and (not fnd) (< (point) limit)) - (forward-line 1) - (when (< (point) limit) - (setq beg (point)) - (if (looking-at "\\s *$") - (setq cand (or cand beg)) ; An empty line is a candidate - (move-to-column clm) - ;; FIXME: No indentation [(zerop clm)] must be handled in some - ;; useful way - though it is not clear what this should mean at all - (if (string-match - "^\\s *$" (buffer-substring-no-properties beg (point))) - (setq cand nil) ; An indented line resets a candidate - (setq fnd (or cand beg))))))) - (goto-char (or fnd start)) - fnd)) - -;; Stores the point where the current indentation ends if a number. If `next' -;; indicates `rst-font-lock-find-unindented-line' shall take the indentation -;; from the next line if this is not empty. If non-nil indicates -;; `rst-font-lock-find-unindented-line' shall take the indentation from the -;; next non-empty line. Also used as a trigger for -;; `rst-font-lock-find-unindented-line'. -(defvar rst-font-lock-indentation-point nil) - -(defun rst-font-lock-find-unindented-line (limit) - (let* ((ind-pnt rst-font-lock-indentation-point) - (beg-pnt ind-pnt)) - ;; May run only once - enforce this - (setq rst-font-lock-indentation-point nil) - (when (and ind-pnt (not (numberp ind-pnt))) - ;; Find indentation point in next line if any - (setq ind-pnt - (save-excursion - (save-match-data - (if (eq ind-pnt 'next) - (when (and (zerop (forward-line 1)) (< (point) limit)) - (setq beg-pnt (point)) - (when (not (looking-at "\\s *$")) - (looking-at "\\s *") - (match-end 0))) - (while (and (zerop (forward-line 1)) (< (point) limit) - (looking-at "\\s *$"))) - (when (< (point) limit) - (setq beg-pnt (point)) - (looking-at "\\s *") - (match-end 0))))))) - (when ind-pnt - (goto-char ind-pnt) - ;; Always succeeds because the limit set by PRE-MATCH-FORM is the - ;; ultimate point to find - (goto-char (or (rst-forward-indented-block nil limit) limit)) - (set-match-data (list beg-pnt (point))) - t))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Adornments - -;; Stores the point where the current adornment ends. Also used as a trigger -;; for `rst-font-lock-handle-adornment'. -(defvar rst-font-lock-adornment-point nil) - -;; Here `rst-font-lock-handle-adornment' stores the section level of the -;; current adornment or t for a transition. -(defvar rst-font-lock-level nil) - -;; FIXME: It would be good if this could be used to markup section titles of -;; given level with a special key; it would be even better to be able to -;; customize this so it can be used for a generally available personal style -;; -;; FIXME: There should be some way to reset and reload this variable - probably -;; a special key -;; -;; FIXME: Some support for `outline-mode' would be nice which should be based -;; on this information -(defvar rst-adornment-level-alist nil - "Associates adornments with section levels. -The key is a two character string. The first character is the adornment -character. The second character distinguishes underline section titles (`u') -from overline/underline section titles (`o'). The value is the section level. - -This is made buffer local on start and adornments found during font lock are -entered.") - -;; Returns section level for adornment key KEY. Adds new section level if KEY -;; is not found and ADD. If KEY is not a string it is simply returned. -(defun rst-adornment-level (key &optional add) - (let ((fnd (assoc key rst-adornment-level-alist)) - (new 1)) - (cond - ((not (stringp key)) - key) - (fnd - (cdr fnd)) - (add - (while (rassoc new rst-adornment-level-alist) - (setq new (1+ new))) - (setq rst-adornment-level-alist - (append rst-adornment-level-alist (list (cons key new)))) - new)))) - -;; Classifies adornment for section titles and transitions. ADORNMENT is the -;; complete adornment string as found in the buffer. END is the point after the -;; last character of ADORNMENT. For overline section adornment LIMIT limits the -;; search for the matching underline. Returns a list. The first entry is t for -;; a transition, or a key string for `rst-adornment-level' for a section title. -;; The following eight values forming four match groups as can be used for -;; `set-match-data'. First match group contains the maximum points of the whole -;; construct. Second and last match group matched pure section title adornment -;; while third match group matched the section title text or the transition. -;; Each group but the first may or may not exist. -(defun rst-classify-adornment (adornment end limit) - (save-excursion - (save-match-data - (goto-char end) - (let ((ado-ch (aref adornment 0)) - (ado-re (regexp-quote adornment)) - (end-pnt (point)) - (beg-pnt (progn - (forward-line 0) - (point))) - (nxt-emp - (save-excursion - (or (not (zerop (forward-line 1))) - (looking-at "\\s *$")))) - (prv-emp - (save-excursion - (or (not (zerop (forward-line -1))) - (looking-at "\\s *$")))) - key beg-ovr end-ovr beg-txt end-txt beg-und end-und) - (cond - ((and nxt-emp prv-emp) - ;; A transition - (setq key t) - (setq beg-txt beg-pnt) - (setq end-txt end-pnt)) - (prv-emp - ;; An overline - (setq key (concat (list ado-ch) "o")) - (setq beg-ovr beg-pnt) - (setq end-ovr end-pnt) - (forward-line 1) - (setq beg-txt (point)) - (while (and (< (point) limit) (not end-txt)) - (if (looking-at "\\s *$") - ;; No underline found - (setq end-txt (1- (point))) - (when (looking-at (concat "\\(" ado-re "\\)\\s *$")) - (setq end-und (match-end 1)) - (setq beg-und (point)) - (setq end-txt (1- beg-und)))) - (forward-line 1))) - (t - ;; An underline - (setq key (concat (list ado-ch) "u")) - (setq beg-und beg-pnt) - (setq end-und end-pnt) - (setq end-txt (1- beg-und)) - (setq beg-txt (progn - (if (re-search-backward "^\\s *$" 1 'move) - (forward-line 1)) - (point))))) - (list key - (or beg-ovr beg-txt beg-und) - (or end-und end-txt end-und) - beg-ovr end-ovr beg-txt end-txt beg-und end-und))))) - -;; Handles adornments for font-locking section titles and transitions. Returns -;; three match groups. First and last match group matched pure overline / -;; underline adornment while second group matched section title text. Each -;; group may not exist. -(defun rst-font-lock-handle-adornment (limit) - (let ((ado-pnt rst-font-lock-adornment-point)) - ;; May run only once - enforce this - (setq rst-font-lock-adornment-point nil) - (if ado-pnt - (let* ((ado (rst-classify-adornment (match-string-no-properties 1) - ado-pnt limit)) - (key (car ado)) - (mtc (cdr ado))) - (setq rst-font-lock-level (rst-adornment-level key t)) - (goto-char (nth 1 mtc)) - (set-match-data mtc) - t)))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; rst-mode.el ends here diff --git a/docutils/tools/html.py b/docutils/tools/html.py deleted file mode 100755 index 98293b3a1..000000000 --- a/docutils/tools/html.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -A minimal front end to the Docutils Publisher, producing HTML. -""" - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -from docutils.core import publish_cmdline, default_description - - -description = ('Generates (X)HTML documents from standalone reStructuredText ' - 'sources. ' + default_description) - -publish_cmdline(writer_name='html', description=description) diff --git a/docutils/tools/pep-html-template b/docutils/tools/pep-html-template deleted file mode 100644 index 94ecafb70..000000000 --- a/docutils/tools/pep-html-template +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="%(encoding)s" ?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<!-- -This HTML is auto-generated. DO NOT EDIT THIS FILE! If you are writing a new -PEP, see http://www.python.org/peps/pep-0001.html for instructions and links -to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE! ---> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=%(encoding)s" /> - <meta name="generator" content="Docutils %(version)s: http://docutils.sourceforge.net/" /> - <title>PEP %(pep)s -- %(title)s</title> - %(stylesheet)s</head> -<body bgcolor="white"> -<table class="navigation" cellpadding="0" cellspacing="0" - width="100%%" border="0"> -<tr><td class="navicon" width="150" height="35"> -<a href="%(pyhome)s/" title="Python Home Page"> -<img src="%(pyhome)s/pics/PyBanner%(banner)03d.gif" alt="[Python]" - border="0" width="150" height="35" /></a></td> -<td class="textlinks" align="left"> -[<b><a href="%(pyhome)s/">Python Home</a></b>] -[<b><a href="%(pepindex)s">PEP Index</a></b>] -[<b><a href="%(pephome)s/pep-%(pepnum)s.txt">PEP Source</a></b>] -</td></tr></table> -%(body)s -%(body_suffix)s diff --git a/docutils/tools/pep.py b/docutils/tools/pep.py deleted file mode 100755 index 4c38980b6..000000000 --- a/docutils/tools/pep.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -A minimal front end to the Docutils Publisher, producing HTML from PEP -(Python Enhancement Proposal) documents. -""" - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -from docutils.core import publish_cmdline, default_description - - -description = ('Generates (X)HTML from reStructuredText-format PEP files. ' - + default_description) - -publish_cmdline(reader_name='pep', writer_name='pep_html', - description=description) diff --git a/docutils/tools/pep2html.py b/docutils/tools/pep2html.py deleted file mode 100755 index fb82a4718..000000000 --- a/docutils/tools/pep2html.py +++ /dev/null @@ -1,531 +0,0 @@ -#!/usr/bin/env python -"""Convert PEPs to (X)HTML - courtesy of /F - -Usage: %(PROGRAM)s [options] [peps] - -Options: - - -u/--user - python.org username - - -b/--browse - After generating the HTML, direct your web browser to view it - (using the Python webbrowser module). If both -i and -b are - given, this will browse the on-line HTML; otherwise it will - browse the local HTML. If no pep arguments are given, this - will browse PEP 0. - - -i/--install - After generating the HTML, install it and the plaintext source file - (.txt) on python.org. In that case the user's name is used in the scp - and ssh commands, unless "-u username" is given (in which case, it is - used instead). Without -i, -u is ignored. - - -l/--local - Same as -i/--install, except install on the local machine. Use this - when logged in to the python.org machine (creosote). - - -q/--quiet - Turn off verbose messages. - - -h/--help - Print this help message and exit. - -The optional argument `peps' is a list of either pep numbers or .txt files. -""" - -import sys -import os -import re -import cgi -import glob -import getopt -import errno -import random -import time - -REQUIRES = {'python': '2.2', - 'docutils': '0.2.7'} -PROGRAM = sys.argv[0] -RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html' -PEPURL = 'pep-%04d.html' -PEPCVSURL = ('http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python' - '/nondist/peps/pep-%04d.txt') -PEPDIRRUL = 'http://www.python.org/peps/' - - -HOST = "www.python.org" # host for update -HDIR = "/ftp/ftp.python.org/pub/www.python.org/peps" # target host directory -LOCALVARS = "Local Variables:" - -COMMENT = """<!-- -This HTML is auto-generated. DO NOT EDIT THIS FILE! If you are writing a new -PEP, see http://www.python.org/peps/pep-0001.html for instructions and links -to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE! --->""" - -# The generated HTML doesn't validate -- you cannot use <hr> and <h3> inside -# <pre> tags. But if I change that, the result doesn't look very nice... -DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n' - ' "http://www.w3.org/TR/REC-html40/loose.dtd">') - -fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|" - "(RFC[- ]?(?P<rfcnum>\d+))|" - "(PEP\s+(?P<pepnum>\d+))|" - ".") - -EMPTYSTRING = '' -SPACE = ' ' -COMMASPACE = ', ' - - - -def usage(code, msg=''): - print >> sys.stderr, __doc__ % globals() - if msg: - print >> sys.stderr, msg - sys.exit(code) - - - -def fixanchor(current, match): - text = match.group(0) - link = None - if text.startswith('http:') or text.startswith('ftp:'): - # Strip off trailing punctuation. Pattern taken from faqwiz. - ltext = list(text) - while ltext: - c = ltext.pop() - if c not in '();:,.?\'"<>': - ltext.append(c) - break - link = EMPTYSTRING.join(ltext) - elif text.startswith('pep-') and text <> current: - link = os.path.splitext(text)[0] + ".html" - elif text.startswith('PEP'): - pepnum = int(match.group('pepnum')) - link = PEPURL % pepnum - elif text.startswith('RFC'): - rfcnum = int(match.group('rfcnum')) - link = RFCURL % rfcnum - if link: - return '<a href="%s">%s</a>' % (cgi.escape(link), cgi.escape(text)) - return cgi.escape(match.group(0)) # really slow, but it works... - - - -NON_MASKED_EMAILS = [ - 'peps@python.org', - 'python-list@python.org', - 'python-dev@python.org', - ] - -def fixemail(address, pepno): - if address.lower() in NON_MASKED_EMAILS: - # return hyperlinked version of email address - return linkemail(address, pepno) - else: - # return masked version of email address - parts = address.split('@', 1) - return '%s at %s' % (parts[0], parts[1]) - - -def linkemail(address, pepno): - parts = address.split('@', 1) - return ('<a href="mailto:%s@%s?subject=PEP%%20%s">' - '%s at %s</a>' - % (parts[0], parts[1], pepno, parts[0], parts[1])) - - -def fixfile(inpath, input_lines, outfile): - from email.Utils import parseaddr - basename = os.path.basename(inpath) - infile = iter(input_lines) - # convert plaintext pep to minimal XHTML markup - print >> outfile, DTD - print >> outfile, '<html>' - print >> outfile, COMMENT - print >> outfile, '<head>' - # head - header = [] - pep = "" - title = "" - for line in infile: - if not line.strip(): - break - if line[0].strip(): - if ":" not in line: - break - key, value = line.split(":", 1) - value = value.strip() - header.append((key, value)) - else: - # continuation line - key, value = header[-1] - value = value + line - header[-1] = key, value - if key.lower() == "title": - title = value - elif key.lower() == "pep": - pep = value - if pep: - title = "PEP " + pep + " -- " + title - if title: - print >> outfile, ' <title>%s</title>' % cgi.escape(title) - r = random.choice(range(64)) - print >> outfile, ( - ' <link rel="STYLESHEET" href="style.css" type="text/css" />\n' - '</head>\n' - '<body bgcolor="white">\n' - '<table class="navigation" cellpadding="0" cellspacing="0"\n' - ' width="100%%" border="0">\n' - '<tr><td class="navicon" width="150" height="35">\n' - '<a href="../" title="Python Home Page">\n' - '<img src="../pics/PyBanner%03d.gif" alt="[Python]"\n' - ' border="0" width="150" height="35" /></a></td>\n' - '<td class="textlinks" align="left">\n' - '[<b><a href="../">Python Home</a></b>]' % r) - if basename <> 'pep-0000.txt': - print >> outfile, '[<b><a href=".">PEP Index</a></b>]' - if pep: - try: - print >> outfile, ('[<b><a href="pep-%04d.txt">PEP Source</a>' - '</b>]' % int(pep)) - except ValueError, error: - print >> sys.stderr, ('ValueError (invalid PEP number): %s' - % error) - print >> outfile, '</td></tr></table>' - print >> outfile, '<div class="header">\n<table border="0">' - for k, v in header: - if k.lower() in ('author', 'discussions-to'): - mailtos = [] - for part in re.split(',\s*', v): - if '@' in part: - realname, addr = parseaddr(part) - if k.lower() == 'discussions-to': - m = linkemail(addr, pep) - else: - m = fixemail(addr, pep) - mailtos.append('%s <%s>' % (realname, m)) - elif part.startswith('http:'): - mailtos.append( - '<a href="%s">%s</a>' % (part, part)) - else: - mailtos.append(part) - v = COMMASPACE.join(mailtos) - elif k.lower() in ('replaces', 'replaced-by', 'requires'): - otherpeps = '' - for otherpep in re.split(',?\s+', v): - otherpep = int(otherpep) - otherpeps += '<a href="pep-%04d.html">%i</a> ' % (otherpep, - otherpep) - v = otherpeps - elif k.lower() in ('last-modified',): - date = v or time.strftime('%d-%b-%Y', - time.localtime(os.stat(inpath)[8])) - try: - url = PEPCVSURL % int(pep) - v = '<a href="%s">%s</a> ' % (url, cgi.escape(date)) - except ValueError, error: - v = date - elif k.lower() in ('content-type',): - url = PEPURL % 9 - pep_type = v or 'text/plain' - v = '<a href="%s">%s</a> ' % (url, cgi.escape(pep_type)) - else: - v = cgi.escape(v) - print >> outfile, ' <tr><th>%s: </th><td>%s</td></tr>' \ - % (cgi.escape(k), v) - print >> outfile, '</table>' - print >> outfile, '</div>' - print >> outfile, '<hr />' - print >> outfile, '<div class="content">' - need_pre = 1 - for line in infile: - if line[0] == '\f': - continue - if line.strip() == LOCALVARS: - break - if line[0].strip(): - if not need_pre: - print >> outfile, '</pre>' - print >> outfile, '<h3>%s</h3>' % line.strip() - need_pre = 1 - elif not line.strip() and need_pre: - continue - else: - # PEP 0 has some special treatment - if basename == 'pep-0000.txt': - parts = line.split() - if len(parts) > 1 and re.match(r'\s*\d{1,4}', parts[1]): - # This is a PEP summary line, which we need to hyperlink - url = PEPURL % int(parts[1]) - if need_pre: - print >> outfile, '<pre>' - need_pre = 0 - print >> outfile, re.sub( - parts[1], - '<a href="%s">%s</a>' % (url, parts[1]), - line, 1), - continue - elif parts and '@' in parts[-1]: - # This is a pep email address line, so filter it. - url = fixemail(parts[-1], pep) - if need_pre: - print >> outfile, '<pre>' - need_pre = 0 - print >> outfile, re.sub( - parts[-1], url, line, 1), - continue - line = fixpat.sub(lambda x, c=inpath: fixanchor(c, x), line) - if need_pre: - print >> outfile, '<pre>' - need_pre = 0 - outfile.write(line) - if not need_pre: - print >> outfile, '</pre>' - print >> outfile, '</div>' - print >> outfile, '</body>' - print >> outfile, '</html>' - - -docutils_settings = None -"""Runtime settings object used by Docutils. Can be set by the client -application when this module is imported.""" - -def fix_rst_pep(inpath, input_lines, outfile): - from docutils import core - output = core.publish_string( - source=''.join(input_lines), - source_path=inpath, - destination_path=outfile.name, - reader_name='pep', - parser_name='restructuredtext', - writer_name='pep_html', - settings=docutils_settings) - outfile.write(output) - - -def get_pep_type(input_lines): - """ - Return the Content-Type of the input. "text/plain" is the default. - Return ``None`` if the input is not a PEP. - """ - pep_type = None - for line in input_lines: - line = line.rstrip().lower() - if not line: - # End of the RFC 2822 header (first blank line). - break - elif line.startswith('content-type: '): - pep_type = line.split()[1] or 'text/plain' - break - elif line.startswith('pep: '): - # Default PEP type, used if no explicit content-type specified: - pep_type = 'text/plain' - return pep_type - - -def get_input_lines(inpath): - try: - infile = open(inpath) - except IOError, e: - if e.errno <> errno.ENOENT: raise - print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename - sys.stderr.flush() - return None, None - lines = infile.read().splitlines(1) # handles x-platform line endings - infile.close() - return lines - - -def find_pep(pep_str): - """Find the .txt file indicated by a cmd line argument""" - if os.path.exists(pep_str): - return pep_str - num = int(pep_str) - return "pep-%04d.txt" % num - -def make_html(inpath, verbose=0): - input_lines = get_input_lines(inpath) - pep_type = get_pep_type(input_lines) - if pep_type is None: - print >> sys.stderr, 'Error: Input file %s is not a PEP.' % inpath - sys.stdout.flush() - return None - elif not PEP_TYPE_DISPATCH.has_key(pep_type): - print >> sys.stderr, ('Error: Unknown PEP type for input file %s: %s' - % (inpath, pep_type)) - sys.stdout.flush() - return None - elif PEP_TYPE_DISPATCH[pep_type] == None: - pep_type_error(inpath, pep_type) - return None - outpath = os.path.splitext(inpath)[0] + ".html" - if verbose: - print inpath, "(%s)" % pep_type, "->", outpath - sys.stdout.flush() - outfile = open(outpath, "w") - PEP_TYPE_DISPATCH[pep_type](inpath, input_lines, outfile) - outfile.close() - os.chmod(outfile.name, 0664) - return outpath - -def push_pep(htmlfiles, txtfiles, username, verbose, local=0): - quiet = "" - if local: - if verbose: - quiet = "-v" - target = HDIR - copy_cmd = "cp" - chmod_cmd = "chmod" - else: - if not verbose: - quiet = "-q" - if username: - username = username + "@" - target = username + HOST + ":" + HDIR - copy_cmd = "scp" - chmod_cmd = "ssh %s%s chmod" % (username, HOST) - files = htmlfiles[:] - files.extend(txtfiles) - files.append("style.css") - files.append("pep.css") - filelist = SPACE.join(files) - rc = os.system("%s %s %s %s" % (copy_cmd, quiet, filelist, target)) - if rc: - sys.exit(rc) - rc = os.system("%s 664 %s/*" % (chmod_cmd, HDIR)) - if rc: - sys.exit(rc) - - -PEP_TYPE_DISPATCH = {'text/plain': fixfile, - 'text/x-rst': fix_rst_pep} -PEP_TYPE_MESSAGES = {} - -def check_requirements(): - # Check Python: - try: - from email.Utils import parseaddr - except ImportError: - PEP_TYPE_DISPATCH['text/plain'] = None - PEP_TYPE_MESSAGES['text/plain'] = ( - 'Python %s or better required for "%%(pep_type)s" PEP ' - 'processing; %s present (%%(inpath)s).' - % (REQUIRES['python'], sys.version.split()[0])) - # Check Docutils: - try: - import docutils - except ImportError: - PEP_TYPE_DISPATCH['text/x-rst'] = None - PEP_TYPE_MESSAGES['text/x-rst'] = ( - 'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. ' - 'See README.txt for installation.') - else: - installed = [int(part) for part in docutils.__version__.split('.')] - required = [int(part) for part in REQUIRES['docutils'].split('.')] - if installed < required: - PEP_TYPE_DISPATCH['text/x-rst'] = None - PEP_TYPE_MESSAGES['text/x-rst'] = ( - 'Docutils must be reinstalled for "%%(pep_type)s" PEP ' - 'processing (%%(inpath)s). Version %s or better required; ' - '%s present. See README.txt for installation.' - % (REQUIRES['docutils'], docutils.__version__)) - -def pep_type_error(inpath, pep_type): - print >> sys.stderr, 'Error: ' + PEP_TYPE_MESSAGES[pep_type] % locals() - sys.stdout.flush() - - -def browse_file(pep): - import webbrowser - file = find_pep(pep) - if file.endswith(".txt"): - file = file[:-3] + "html" - file = os.path.abspath(file) - url = "file:" + file - webbrowser.open(url) - -def browse_remote(pep): - import webbrowser - file = find_pep(pep) - if file.endswith(".txt"): - file = file[:-3] + "html" - url = PEPDIRRUL + file - webbrowser.open(url) - - -def main(argv=None): - # defaults - update = 0 - local = 0 - username = '' - verbose = 1 - browse = 0 - - check_requirements() - - if argv is None: - argv = sys.argv[1:] - - try: - opts, args = getopt.getopt( - argv, 'bilhqu:', - ['browse', 'install', 'local', 'help', 'quiet', 'user=']) - except getopt.error, msg: - usage(1, msg) - - for opt, arg in opts: - if opt in ('-h', '--help'): - usage(0) - elif opt in ('-i', '--install'): - update = 1 - elif opt in ('-l', '--local'): - update = 1 - local = 1 - elif opt in ('-u', '--user'): - username = arg - elif opt in ('-q', '--quiet'): - verbose = 0 - elif opt in ('-b', '--browse'): - browse = 1 - - if args: - peptxt = [] - html = [] - for pep in args: - file = find_pep(pep) - peptxt.append(file) - newfile = make_html(file, verbose=verbose) - if newfile: - html.append(newfile) - if browse and not update: - browse_file(pep) - else: - # do them all - peptxt = [] - html = [] - files = glob.glob("pep-*.txt") - files.sort() - for file in files: - peptxt.append(file) - newfile = make_html(file, verbose=verbose) - if newfile: - html.append(newfile) - if browse and not update: - browse_file("0") - - if update: - push_pep(html, peptxt, username, verbose, local=local) - if browse: - if args: - for pep in args: - browse_remote(pep) - else: - browse_remote("0") - - - -if __name__ == "__main__": - main() diff --git a/docutils/tools/publish.py b/docutils/tools/publish.py deleted file mode 100755 index d360cd124..000000000 --- a/docutils/tools/publish.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -A minimal front end to the Docutils Publisher, producing pseudo-XML. -""" - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -from docutils.core import publish_cmdline, default_description - - -description = ('Generates pseudo-XML from standalone reStructuredText ' - 'sources (for testing purposes). ' + default_description) - -publish_cmdline(description=description) diff --git a/docutils/tools/quicktest.py b/docutils/tools/quicktest.py deleted file mode 100755 index 04e3209fa..000000000 --- a/docutils/tools/quicktest.py +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env python - -# Author: Garth Kidd -# Contact: garth@deadlybloodyserious.com -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -import sys -import os -import getopt -import docutils -from docutils.frontend import OptionParser -from docutils.utils import new_document -from docutils.parsers.rst import Parser - - -usage_header = """\ -quicktest.py: quickly test the restructuredtext parser. - -Usage:: - - quicktest.py [options] [<source> [<destination>]] - -``source`` is the name of the file to use as input (default is stdin). -``destination`` is the name of the file to create as output (default is -stdout). - -Options: -""" - -options = [('pretty', 'p', - 'output pretty pseudo-xml: no "&abc;" entities (default)'), - ('test', 't', 'output test-ready data (input & expected output, ' - 'ready to be copied to a parser test module)'), - ('rawxml', 'r', 'output raw XML'), - ('styledxml=', 's', 'output raw XML with XSL style sheet ' - 'reference (filename supplied in the option argument)'), - ('xml', 'x', 'output pretty XML (indented)'), - ('attributes', 'A', 'dump document attributes after processing'), - ('debug', 'd', 'debug mode (lots of output)'), - ('version', 'V', 'show Docutils version then exit'), - ('help', 'h', 'show help text then exit')] -"""See ``distutils.fancy_getopt.FancyGetopt.__init__`` for a description of -the data structure: (long option, short option, description).""" - -def usage(): - print usage_header - for longopt, shortopt, description in options: - if longopt[-1:] == '=': - opts = '-%s arg, --%sarg' % (shortopt, longopt) - else: - opts = '-%s, --%s' % (shortopt, longopt) - print '%-15s' % opts, - if len(opts) > 14: - print '%-16s' % '\n', - while len(description) > 60: - limit = description.rindex(' ', 0, 60) - print description[:limit].strip() - description = description[limit + 1:] - print '%-15s' % ' ', - print description - -def _pretty(input, document, optargs): - return document.pformat() - -def _rawxml(input, document, optargs): - return document.asdom().toxml() - -def _styledxml(input, document, optargs): - docnode = document.asdom().childNodes[0] - return '%s\n%s\n%s' % ( - '<?xml version="1.0" encoding="ISO-8859-1"?>', - '<?xml-stylesheet type="text/xsl" href="%s"?>' - % optargs['styledxml'], docnode.toxml()) - -def _prettyxml(input, document, optargs): - return document.asdom().toprettyxml(' ', '\n') - -def _test(input, document, optargs): - tq = '"""' - output = document.pformat() # same as _pretty() - return """\ - totest['change_this_test_name'] = [ -[%s\\ -%s -%s, -%s\\ -%s -%s], -] -""" % ( tq, escape(input.rstrip()), tq, tq, escape(output.rstrip()), tq ) - -def escape(text): - """ - Return `text` in triple-double-quoted Python string form. - """ - text = text.replace('\\', '\\\\') # escape backslashes - text = text.replace('"""', '""\\"') # break up triple-double-quotes - text = text.replace(' \n', ' \\n\\\n') # protect trailing whitespace - return text - -_outputFormatters = { - 'rawxml': _rawxml, - 'styledxml': _styledxml, - 'xml': _prettyxml, - 'pretty' : _pretty, - 'test': _test - } - -def format(outputFormat, input, document, optargs): - formatter = _outputFormatters[outputFormat] - return formatter(input, document, optargs) - -def getArgs(): - if os.name == 'mac' and len(sys.argv) <= 1: - return macGetArgs() - else: - return posixGetArgs(sys.argv[1:]) - -def posixGetArgs(argv): - outputFormat = 'pretty' - # convert fancy_getopt style option list to getopt.getopt() arguments - shortopts = ''.join([option[1] + ':' * (option[0][-1:] == '=') - for option in options if option[1]]) - longopts = [option[0] for option in options if option[0]] - try: - opts, args = getopt.getopt(argv, shortopts, longopts) - except getopt.GetoptError: - usage() - sys.exit(2) - optargs = {'debug': 0, 'attributes': 0} - for o, a in opts: - if o in ['-h', '--help']: - usage() - sys.exit() - elif o in ['-V', '--version']: - print >>sys.stderr, ('quicktest.py (Docutils %s)' - % docutils.__version__) - sys.exit() - elif o in ['-r', '--rawxml']: - outputFormat = 'rawxml' - elif o in ['-s', '--styledxml']: - outputFormat = 'styledxml' - optargs['styledxml'] = a - elif o in ['-x', '--xml']: - outputFormat = 'xml' - elif o in ['-p', '--pretty']: - outputFormat = 'pretty' - elif o in ['-t', '--test']: - outputFormat = 'test' - elif o == '--attributes': - optargs['attributes'] = 1 - elif o in ['-d', '--debug']: - optargs['debug'] = 1 - else: - raise getopt.GetoptError, "getopt should have saved us!" - if len(args) > 2: - print 'Maximum 2 arguments allowed.' - usage() - sys.exit(1) - inputFile = sys.stdin - outputFile = sys.stdout - if args: - inputFile = open(args.pop(0)) - if args: - outputFile = open(args.pop(0), 'w') - return inputFile, outputFile, outputFormat, optargs - -def macGetArgs(): - import EasyDialogs - EasyDialogs.Message("""\ -Use the next dialog to build a command line: - -1. Choose an output format from the [Option] list -2. Click [Add] -3. Choose an input file: [Add existing file...] -4. Save the output: [Add new file...] -5. [OK]""") - optionlist = [(longopt, description) - for (longopt, shortopt, description) in options] - argv = EasyDialogs.GetArgv(optionlist=optionlist, addfolder=0) - return posixGetArgs(argv) - -def main(): - # process cmdline arguments: - inputFile, outputFile, outputFormat, optargs = getArgs() - settings = OptionParser(components=(Parser,)).get_default_values() - settings.debug = optargs['debug'] - parser = Parser() - input = inputFile.read() - document = new_document(inputFile.name, settings) - parser.parse(input, document) - output = format(outputFormat, input, document, optargs) - outputFile.write(output) - if optargs['attributes']: - import pprint - pprint.pprint(document.__dict__) - - -if __name__ == '__main__': - sys.stderr = sys.stdout - main() diff --git a/docutils/tools/rst2latex.py b/docutils/tools/rst2latex.py deleted file mode 100755 index 3b7fdae82..000000000 --- a/docutils/tools/rst2latex.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -A minimal front end to the Docutils Publisher, producing LaTeX. -""" - -import locale -try: - locale.setlocale(locale.LC_ALL, '') -except: - pass - -from docutils.core import publish_cmdline, default_description - - -description = ('Generates LaTeX documents from standalone reStructuredText ' - 'sources. ' + default_description) - -publish_cmdline(writer_name='latex', description=description) diff --git a/docutils/tools/stylesheets/default.css b/docutils/tools/stylesheets/default.css deleted file mode 100644 index 5b2e1be96..000000000 --- a/docutils/tools/stylesheets/default.css +++ /dev/null @@ -1,224 +0,0 @@ -/* -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:date: $Date$ -:version: $Revision$ -:copyright: This stylesheet has been placed in the public domain. - -Default cascading style sheet for the HTML output of Docutils. -*/ - -.first { - margin-top: 0 } - -.last { - margin-bottom: 0 } - -a.toc-backref { - text-decoration: none ; - color: black } - -dd { - margin-bottom: 0.5em } - -div.abstract { - margin: 2em 5em } - -div.abstract p.topic-title { - font-weight: bold ; - text-align: center } - -div.attention, div.caution, div.danger, div.error, div.hint, -div.important, div.note, div.tip, div.warning, div.admonition { - margin: 2em ; - border: medium outset ; - padding: 1em } - -div.attention p.admonition-title, div.caution p.admonition-title, -div.danger p.admonition-title, div.error p.admonition-title, -div.warning p.admonition-title { - color: red ; - font-weight: bold ; - font-family: sans-serif } - -div.hint p.admonition-title, div.important p.admonition-title, -div.note p.admonition-title, div.tip p.admonition-title, -div.admonition p.admonition-title { - font-weight: bold ; - font-family: sans-serif } - -div.dedication { - margin: 2em 5em ; - text-align: center ; - font-style: italic } - -div.dedication p.topic-title { - font-weight: bold ; - font-style: normal } - -div.figure { - margin-left: 2em } - -div.footer, div.header { - font-size: smaller } - -div.sidebar { - margin-left: 1em ; - border: medium outset ; - padding: 0em 1em ; - background-color: #ffffee ; - width: 40% ; - float: right ; - clear: right } - -div.sidebar p.rubric { - font-family: sans-serif ; - font-size: medium } - -div.system-messages { - margin: 5em } - -div.system-messages h1 { - color: red } - -div.system-message { - border: medium outset ; - padding: 1em } - -div.system-message p.system-message-title { - color: red ; - font-weight: bold } - -div.topic { - margin: 2em } - -h1.title { - text-align: center } - -h2.subtitle { - text-align: center } - -hr { - width: 75% } - -ol.simple, ul.simple { - margin-bottom: 1em } - -ol.arabic { - list-style: decimal } - -ol.loweralpha { - list-style: lower-alpha } - -ol.upperalpha { - list-style: upper-alpha } - -ol.lowerroman { - list-style: lower-roman } - -ol.upperroman { - list-style: upper-roman } - -p.attribution { - text-align: right ; - margin-left: 50% } - -p.caption { - font-style: italic } - -p.credits { - font-style: italic ; - font-size: smaller } - -p.label { - white-space: nowrap } - -p.rubric { - font-weight: bold ; - font-size: larger ; - color: darkred ; - text-align: center } - -p.sidebar-title { - font-family: sans-serif ; - font-weight: bold ; - font-size: larger } - -p.sidebar-subtitle { - font-family: sans-serif ; - font-weight: bold } - -p.topic-title { - font-weight: bold } - -pre.address { - margin-bottom: 0 ; - margin-top: 0 ; - font-family: serif ; - font-size: 100% } - -pre.line-block { - font-family: serif ; - font-size: 100% } - -pre.literal-block, pre.doctest-block { - margin-left: 2em ; - margin-right: 2em ; - background-color: #eeeeee } - -span.classifier { - font-family: sans-serif ; - font-style: oblique } - -span.classifier-delimiter { - font-family: sans-serif ; - font-weight: bold } - -span.interpreted { - font-family: sans-serif } - -span.option { - white-space: nowrap } - -span.option-argument { - font-style: italic } - -span.pre { - white-space: pre } - -span.problematic { - color: red } - -table { - margin-top: 0.5em ; - margin-bottom: 0.5em } - -table.citation { - border-left: solid thin gray ; - padding-left: 0.5ex } - -table.docinfo { - margin: 2em 4em } - -table.footnote { - border-left: solid thin black ; - padding-left: 0.5ex } - -td, th { - padding-left: 0.5em ; - padding-right: 0.5em ; - vertical-align: top } - -th.docinfo-name, th.field-name { - font-weight: bold ; - text-align: left ; - white-space: nowrap } - -h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { - font-size: 100% } - -tt { - background-color: #eeeeee } - -ul.auto-toc { - list-style-type: none } diff --git a/docutils/tools/stylesheets/pep.css b/docutils/tools/stylesheets/pep.css deleted file mode 100644 index a82045bc9..000000000 --- a/docutils/tools/stylesheets/pep.css +++ /dev/null @@ -1,240 +0,0 @@ -/* -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:date: $Date$ -:version: $Revision$ -:copyright: This stylesheet has been placed in the public domain. - -Default cascading style sheet for the PEP HTML output of Docutils. -*/ - -.first { - margin-top: 0 } - -.last { - margin-bottom: 0 } - -.navigation { - width: 100% ; - background: #99ccff ; - margin-top: 0px ; - margin-bottom: 0px } - -.navigation .navicon { - width: 150px ; - height: 35px } - -.navigation .textlinks { - padding-left: 1em ; - text-align: left } - -.navigation td, .navigation th { - padding-left: 0em ; - padding-right: 0em ; - vertical-align: middle } - -.rfc2822 { - margin-top: 0.5em ; - margin-left: 0.5em ; - margin-right: 0.5em ; - margin-bottom: 0em } - -.rfc2822 td { - text-align: left } - -.rfc2822 th.field-name { - text-align: right ; - font-family: sans-serif ; - padding-right: 0.5em ; - font-weight: bold ; - margin-bottom: 0em } - -a.toc-backref { - text-decoration: none ; - color: black } - -body { - margin: 0px ; - margin-bottom: 1em ; - padding: 0px } - -dd { - margin-bottom: 0.5em } - -div.section { - margin-left: 1em ; - margin-right: 1em ; - margin-bottom: 1.5em } - -div.section div.section { - margin-left: 0em ; - margin-right: 0em ; - margin-top: 1.5em } - -div.abstract { - margin: 2em 5em } - -div.abstract p.topic-title { - font-weight: bold ; - text-align: center } - -div.attention, div.caution, div.danger, div.error, div.hint, -div.important, div.note, div.tip, div.warning { - margin: 2em ; - border: medium outset ; - padding: 1em } - -div.attention p.admonition-title, div.caution p.admonition-title, -div.danger p.admonition-title, div.error p.admonition-title, -div.warning p.admonition-title { - color: red ; - font-weight: bold ; - font-family: sans-serif } - -div.hint p.admonition-title, div.important p.admonition-title, -div.note p.admonition-title, div.tip p.admonition-title { - font-weight: bold ; - font-family: sans-serif } - -div.figure { - margin-left: 2em } - -div.footer, div.header { - font-size: smaller } - -div.footer { - margin-left: 1em ; - margin-right: 1em } - -div.system-messages { - margin: 5em } - -div.system-messages h1 { - color: red } - -div.system-message { - border: medium outset ; - padding: 1em } - -div.system-message p.system-message-title { - color: red ; - font-weight: bold } - -div.topic { - margin: 2em } - -h1 { - font-family: sans-serif ; - font-size: large } - -h2 { - font-family: sans-serif ; - font-size: medium } - -h3 { - font-family: sans-serif ; - font-size: small } - -h4 { - font-family: sans-serif ; - font-style: italic ; - font-size: small } - -h5 { - font-family: sans-serif; - font-size: x-small } - -h6 { - font-family: sans-serif; - font-style: italic ; - font-size: x-small } - -.section hr { - width: 75% } - -ol.simple, ul.simple { - margin-bottom: 1em } - -ol.arabic { - list-style: decimal } - -ol.loweralpha { - list-style: lower-alpha } - -ol.upperalpha { - list-style: upper-alpha } - -ol.lowerroman { - list-style: lower-roman } - -ol.upperroman { - list-style: upper-roman } - -p.caption { - font-style: italic } - -p.credits { - font-style: italic ; - font-size: smaller } - -p.label { - white-space: nowrap } - -p.topic-title { - font-family: sans-serif ; - font-weight: bold } - -pre.line-block { - font-family: serif ; - font-size: 100% } - -pre.literal-block, pre.doctest-block { - margin-left: 2em ; - margin-right: 2em ; - background-color: #eeeeee } - -span.classifier { - font-family: sans-serif ; - font-style: oblique } - -span.classifier-delimiter { - font-family: sans-serif ; - font-weight: bold } - -span.interpreted { - font-family: sans-serif } - -span.option-argument { - font-style: italic } - -span.pre { - white-space: pre } - -span.problematic { - color: red } - -table { - margin-top: 0.5em ; - margin-bottom: 0.5em } - -td, th { - padding-left: 0.5em ; - padding-right: 0.5em ; - vertical-align: top } - -td.num { - text-align: right } - -th.field-name { - font-weight: bold ; - text-align: left ; - white-space: nowrap } - -h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { - font-size: 100% } - -tt { - background-color: #eeeeee } - -ul.auto-toc { - list-style-type: none } diff --git a/docutils/tools/unicode2rstsubs.py b/docutils/tools/unicode2rstsubs.py deleted file mode 100755 index d5e259863..000000000 --- a/docutils/tools/unicode2rstsubs.py +++ /dev/null @@ -1,195 +0,0 @@ -#! /usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This program has been placed in the public domain. - -""" -unicode2subfiles.py -- produce character entity files (reSructuredText -substitutions) from the MathML master unicode.xml file. - -This program extracts character entity and entity set information from a -unicode.xml file and produces multiple reStructuredText files (in the current -directory) containing substitutions. Entity sets are from ISO 8879 & ISO -9573-13 (combined), MathML, and HTML4. One or two files are produced for each -entity set; a second file with a "-wide.txt" suffix is produced if there are -wide-Unicode characters in the set. - -The input file, unicode.xml, is maintained as part of the MathML 2 -Recommentation XML source, and is available at -<http://www.w3.org/Math/characters/unicode.xml> (as of 2003-06-22). -""" - -import sys -import os -import optparse -import re -from xml.parsers.expat import ParserCreate - - -usage_msg = """Usage: %s [unicode.xml]""" - -def usage(prog, status=0, msg=None): - print >>sys.stderr, usage_msg % prog - if msg: - print >>sys.stderr, msg - sys.exit(status) - -def main(argv=None): - if argv is None: - argv = sys.argv - if len(argv) == 2: - inpath = argv[1] - elif len(argv) > 2: - usage(argv[0], 2, - 'Too many arguments (%s): only 1 expected.' % (len(argv) - 1)) - else: - inpath = 'unicode.xml' - if not os.path.isfile(inpath): - usage(argv[0], 1, 'No such file: "%s".' % inpath) - infile = open(inpath) - process(infile) - -def process(infile): - grouper = CharacterEntitySetExtractor(infile) - grouper.group() - grouper.write_sets() - - -class CharacterEntitySetExtractor: - - """ - Extracts character entity information from unicode.xml file, groups it by - entity set, and writes out reStructuredText substitution files. - """ - - unwanted_entity_sets = ['stix', # unknown, buggy set - 'predefined'] - - def __init__(self, infile): - self.infile = infile - """Input unicode.xml file.""" - - self.parser = self.setup_parser() - """XML parser.""" - - self.elements = [] - """Stack of element names. Last is current element.""" - - self.sets = {} - """Mapping of charent set name to set dict.""" - - self.charid = None - """Current character's "id" attribute value.""" - - self.descriptions = {} - """Mapping of character ID to description.""" - - def setup_parser(self): - parser = ParserCreate() - parser.StartElementHandler = self.StartElementHandler - parser.EndElementHandler = self.EndElementHandler - parser.CharacterDataHandler = self.CharacterDataHandler - return parser - - def group(self): - self.parser.ParseFile(self.infile) - - def StartElementHandler(self, name, attributes): - self.elements.append(name) - handler = name + '_start' - if hasattr(self, handler): - getattr(self, handler)(name, attributes) - - def EndElementHandler(self, name): - assert self.elements[-1] == name, \ - 'unknown end-tag %r (%r)' % (name, self.element) - self.elements.pop() - handler = name + '_end' - if hasattr(self, handler): - getattr(self, handler)(name) - - def CharacterDataHandler(self, data): - handler = self.elements[-1] + '_data' - if hasattr(self, handler): - getattr(self, handler)(data) - - def character_start(self, name, attributes): - self.charid = attributes['id'] - - def entity_start(self, name, attributes): - set = self.entity_set_name(attributes['set']) - if not set: - return - if not self.sets.has_key(set): - print 'bad set: %r' % set - return - entity = attributes['id'] - assert (not self.sets[set].has_key(entity) - or self.sets[set][entity] == self.charid), \ - ('sets[%r][%r] == %r (!= %r)' - % (set, entity, self.sets[set][entity], self.charid)) - self.sets[set][entity] = self.charid - - def description_data(self, data): - self.descriptions.setdefault(self.charid, '') - self.descriptions[self.charid] += data - - entity_set_name_pat = re.compile(r'[0-9-]*(.+)$') - """Pattern to strip ISO numbers off the beginning of set names.""" - - def entity_set_name(self, name): - """ - Return lowcased and standard-number-free entity set name. - Return ``None`` for unwanted entity sets. - """ - match = self.entity_set_name_pat.match(name) - name = match.group(1).lower() - if name in self.unwanted_entity_sets: - return None - self.sets.setdefault(name, {}) - return name - - def write_sets(self): - sets = self.sets.keys() - sets.sort() - for set_name in sets: - self.write_set(set_name) - - def write_set(self, set_name, wide=None): - if wide: - outname = set_name + '-wide.txt' - else: - outname = set_name + '.txt' - outfile = open(outname, 'w') - print 'writing file "%s"' % outname - set = self.sets[set_name] - entities = [(e.lower(), e) for e in set.keys()] - entities.sort() - longest = 0 - for _, entity_name in entities: - longest = max(longest, len(entity_name)) - has_wide = None - for _, entity_name in entities: - has_wide = self.write_entity( - set, set_name, entity_name, outfile, longest, wide) or has_wide - if has_wide and not wide: - self.write_set(set_name, 1) - - def write_entity(self, set, set_name, entity_name, outfile, longest, - wide=None): - charid = set[entity_name] - if not wide: - for code in charid[1:].split('-'): - if int(code, 16) > 0xFFFF: - return 1 # wide-Unicode character - codes = ' '.join(['U+%s' % code for code in charid[1:].split('-')]) - print >>outfile, ('.. %-*s unicode:: %s .. %s' - % (longest + 2, '|' + entity_name + '|', - codes, self.descriptions[charid])) - - -if __name__ == '__main__': - sys.exit(main()) |
