summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/changelog2rst.sh2
-rw-r--r--scripts/docutils_htmldeco_writer.py71
-rwxr-xr-xscripts/format_c_api_doc.py2
-rwxr-xr-xscripts/format_c_api_docs.py2
-rw-r--r--scripts/html_fragments.py16
-rwxr-xr-xscripts/make_www.py2
-rwxr-xr-xscripts/named_colors.py2
-rwxr-xr-xscripts/omp_decimal_align.py2
-rwxr-xr-xscripts/relpath.py2
-rwxr-xr-xscripts/rst2html5.py393
-rwxr-xr-xscripts/rst2htmldeco.py231
11 files changed, 415 insertions, 310 deletions
diff --git a/scripts/changelog2rst.sh b/scripts/changelog2rst.sh
index 4d5f268..f42354e 100755
--- a/scripts/changelog2rst.sh
+++ b/scripts/changelog2rst.sh
@@ -1,4 +1,4 @@
#!/bin/sh
# Simple filter to filter a ChangeLog to something in reStructuredText.
#
-sed -e 's/ \* / - /g ; s/ / / ; s/\*/\\*/g; s/\_/\\_/g'
+expand | sed -e 's/^ \* / - /g ; s/^ / /g ; s/\*/\\*/g; s/\_/\\_/g'
diff --git a/scripts/docutils_htmldeco_writer.py b/scripts/docutils_htmldeco_writer.py
deleted file mode 100644
index ea3f119..0000000
--- a/scripts/docutils_htmldeco_writer.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# vim:ts=4:sw=4:expandtab:tw=100:
-
-#* Author: Mark Mitchell
-#* Copyright 2005-2008 Mark Mitchell, All Rights Reserved
-#* License: see __license__ below.
-
-__doc__ = """
-A specialized subclass of the docutils html4css1 writer.
-
-It includes some additional HTML in the HTMLTranslator body_prefix and body_suffix
-so as to put a standard banner and navigation menus on the page.
-"""
-
-__copyright__ = "2005, 2008, Mark Mitchell"
-
-__license__ = """
-Copyright 2005, 2008, Mark Mitchell
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this oftware and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-The Software is provided "as is", without warranty of any kind,
-express or implied, including but not limited to the warranties of
-merchantability, fitness for a particular purpose and noninfringement.
-In no event shall the authors or copyright holders be liable for any
-claim, damages or other liability, whether in an action of contract,
-tort or otherwise, arising from, out of or in connection with Software
-or the use or other dealings in the Software.
-"""
-
-
-import sys
-
-from docutils.writers import html4css1
-from docutils import nodes
-# the html fragments for banner, navigation menu, and footer
-import html_fragments
-
-
-class Writer(html4css1.Writer):
- '''My derived Writer class'''
-
- super_init = html4css1.Writer.__init__
- def __init__(self):
- self.super_init()
- self.translator_class = MmHtmlTranslator
-
-
-class MmHtmlTranslator(html4css1.HTMLTranslator):
- """My HTML translator which alters body_prefix to include
- some extra HTML after the body opening tag, and alters body_suffix
- to include a bit more before the body closing tag."""
-
- def __init__(self, document):
- html4css1.HTMLTranslator.__init__(self, document)
-
- self.body_prefix.append(html_fragments.banner)
- self.body_prefix.append(html_fragments.nav)
- self.body_suffix = [html_fragments.footer, '</body>\n</html>\n']
- #self.body_suffix = ['</body>\n</html>\n']
-
diff --git a/scripts/format_c_api_doc.py b/scripts/format_c_api_doc.py
index c222776..2b929c3 100755
--- a/scripts/format_c_api_doc.py
+++ b/scripts/format_c_api_doc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:expandtab:
diff --git a/scripts/format_c_api_docs.py b/scripts/format_c_api_docs.py
index e452f79..495fcc2 100755
--- a/scripts/format_c_api_docs.py
+++ b/scripts/format_c_api_docs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:expandtab:
diff --git a/scripts/html_fragments.py b/scripts/html_fragments.py
index 96c9c5e..3e6223b 100644
--- a/scripts/html_fragments.py
+++ b/scripts/html_fragments.py
@@ -18,6 +18,17 @@ url_sourceforge = "https://sourceforge.net/projects/graphicsmagick/"
banner_logo = 'images/gm-107x76.png' # relative to top directory
+html_head_template = """<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta content="en" name="language">
+ <title>{title}</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link media="screen" href="{url_screen_css}" type="text/css" rel="stylesheet">
+{metas}
+</head>
+"""
# banner_template and nav_template contain chunk which has to be created at
# runtime: the path to the image directory, and the path to the top directory.
@@ -63,10 +74,13 @@ nav_template = """
footer_template = u"""
<hr class="docutils">
<div class="document">
- <p><a href="%(url_prefix)sCopyright.html">Copyright</a> © GraphicsMagick Group 2002 - 2022%(sponsor_logo_html)s</p>
+ <p><a href="%(url_prefix)sCopyright.html">Copyright</a> © GraphicsMagick Group 2002 - 2023%(sponsor_logo_html)s</p>
</div>
"""
+def make_html_head(url_screen_css, title, metas):
+ return html_head_template.format(url_screen_css=url_screen_css, title=title, metas=metas)
+
def make_footer():
return footer_template % { 'url_prefix' : url_prefix,
'sponsor_logo_html' : sponsor_logo_html,
diff --git a/scripts/make_www.py b/scripts/make_www.py
index ebdc025..2efa372 100755
--- a/scripts/make_www.py
+++ b/scripts/make_www.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:expandtab:
diff --git a/scripts/named_colors.py b/scripts/named_colors.py
index 7e9eaa3..b494262 100755
--- a/scripts/named_colors.py
+++ b/scripts/named_colors.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:ts=4:sw=4:expandtab
diff --git a/scripts/omp_decimal_align.py b/scripts/omp_decimal_align.py
index 40d6833..20e0679 100755
--- a/scripts/omp_decimal_align.py
+++ b/scripts/omp_decimal_align.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:expandtab:
diff --git a/scripts/relpath.py b/scripts/relpath.py
index 4163dcf..8f43824 100755
--- a/scripts/relpath.py
+++ b/scripts/relpath.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:expandtab:
diff --git a/scripts/rst2html5.py b/scripts/rst2html5.py
new file mode 100755
index 0000000..b964a26
--- /dev/null
+++ b/scripts/rst2html5.py
@@ -0,0 +1,393 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+#* Author: Mark Mitchell
+#* Copyright 2008-2022 Mark Mitchell, All Rights Reserved
+#* License: see __license__ below.
+
+"""Renders reStructuredText files to HTML with some custom HTML parts included,
+such as a common header and navigation menu at the top of all HTML pages.
+The header and navigation HTML blobs are kept in a separate python file,
+html_fragments.py.
+
+Usage:
+ rst2html5.py [options] <RSTDOC> [<DESTINATION>]
+
+Options:
+ -h, --help display the usage help message
+ -s --stylesheet=<FILE>
+ The path to the stylesheet.
+ -e --embed-stylesheet
+ If specified, the stylesheet will be embedded in the HTML.
+ If unspecified, the HTML will link to the stylesheet.
+
+ -u --url-prefix=<PATH>
+ The value of url-prefix is prefixed to all the URLs in the
+ path to get to the top directory from the OUTFILE
+ directory. Used to create working relative URLs in the custom
+ header and navigation menu. Defaults to empty.
+ Example: --url-prefix=../../
+
+Arguments:
+ <RSTDOC> is the file path of the source reStructuredText document
+
+ <DESTINATION> is the file path where the HTML output will be written.
+
+Reads from <RSTDOC> and writes to <DESTINATION> (default is stdout)
+
+If no <DESTINATION> is specified, output will be written to stdout.
+
+Note:
+
+Images referenced from the stylesheet (such as background images)
+may require different image-dir paths depending on whether the stylesheet is
+embedded or linked. If linked, image URLs in the stylesheet are relative to the
+stylesheet's location. If embedded, image URLs in the stylesheet are relative
+to the HTML file's path.
+"""
+
+__copyright__ = "2008 - 2022, Mark Mitchell"
+
+__license__ = """
+Copyright 2008 - 2022, Mark Mitchell
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+The Software is provided "as is", without warranty of any kind,
+express or implied, including but not limited to the warranties of
+merchantability, fitness for a particular purpose and noninfringement.
+In no event shall the authors or copyright holders be liable for any
+claim, damages or other liability, whether in an action of contract,
+tort or otherwise, arising from, out of or in connection with Software
+or the use or other dealings in the Software.
+"""
+
+import sys
+import os
+
+from docutils import core
+import html_fragments
+
+top_dir = os.path.abspath(os.path.dirname(__file__))
+
+CSS = 'docutils-articles.css'
+ENCODING = 'utf-8'
+
+class Usage (Exception):
+ pass
+
+def loginfo(s):
+ print(s, file=sys.stdout)
+
+def logerror(s):
+ print(s, file=sys.stderr)
+
+
+def assemble_html(doc_parts, stylesheet_screen=None):
+ """Constructs a complete HTML document by assembling various
+ parts created by docutils.core.publish_parts and the
+ templates in html_fragments.py
+ """
+
+ if stylesheet_screen is None:
+ stylesheet_screen = CSS
+
+ def get_metas():
+ metas = doc_parts['meta'].split('\n')
+ metas = [m.strip() for m in metas if 'name="keywords"' in m or 'name="description"' in m]
+ metas = [m.replace('/>', '>') for m in metas]
+ return '\n'.join(metas)
+
+ html_head = html_fragments.make_html_head(stylesheet_screen, doc_parts['title'], get_metas())
+
+ html = '\n'.join([
+ html_head,
+ '<body>',
+ html_fragments.banner,
+ html_fragments.nav,
+ doc_parts['html_body'],
+ html_fragments.footer,
+ doc_parts['body_suffix'],
+ ])
+
+ return html
+
+
+def make_html_parts(input_string, source_path=None, destination_path=None,
+ stylesheet=CSS, embed_stylesheet=False,
+ doctitle=1, initial_header_level=1):
+ """
+ Given an input string which is a reStructuredText document, returns a
+ dictionary of HTML document parts created by docutils.core.publish_parts()
+
+ Dictionary keys are the names of parts, and values are Unicode strings;
+ encoding is up to the client.
+
+ Parameters:
+
+ - `input_string`: A multi-line text string; required.
+ - `source_path`: Path to the source file or object. Optional, but useful
+ for diagnostic output (system messages).
+ - `destination_path`: Path to the file or object which will receive the
+ output; optional. Used for determining relative paths (stylesheets,
+ source links, etc.).
+ - `doctitle`: Disable the promotion of a lone top-level section title to
+ document title (and subsequent section title to document subtitle
+ promotion); enabled by default.
+ - `initial_header_level`: The initial level for header elements (e.g. 1
+ for "<h1>").
+
+
+ Parts Provided By the HTML Writer
+ ---------------------------------
+ body
+ parts['body'] is equivalent to parts['fragment']. It is not equivalent to parts['html_body'].
+
+ body_prefix
+ parts['body_prefix'] contains:
+
+ </head>
+ <body>
+ <div class="document" ...>
+
+ and, if applicable:
+
+ <div class="header">
+ ...
+ </div>
+
+ body_pre_docinfo
+ parts['body_pre_docinfo] contains (as applicable):
+
+ <h1 class="title">...</h1>
+ <h2 class="subtitle" id="...">...</h2>
+
+ body_suffix
+ parts['body_suffix'] contains:
+
+ </div>
+
+ (the end-tag for <div class="document">), the footer division if applicable:
+
+ <div class="footer">
+ ...
+ </div>
+
+ and:
+
+ </body>
+ </html>
+
+ docinfo
+ parts['docinfo'] contains the document bibliographic data, the docinfo
+ field list rendered as a table.
+
+ footer
+ parts['footer'] contains the document footer content, meant to appear
+ at the bottom of a web page, or repeated at the bottom of every printed
+ page.
+
+ fragment
+ parts['fragment'] contains the document body (not the HTML <body>). In
+ other words, it contains the entire document, less the document title,
+ subtitle, docinfo, header, and footer.
+
+ head
+ parts['head'] contains <meta ... /> tags and the document <title>...</title>.
+
+ head_prefix
+ parts['head_prefix'] contains the XML declaration, the DOCTYPE
+ declaration, the <html ...> start tag and the <head> start tag.
+
+ header
+ parts['header'] contains the document header content, meant to appear at
+ the top of a web page, or repeated at the top of every printed page.
+
+ html_body
+ parts['html_body'] contains the HTML <body> content, less the <body> and </body> tags themselves.
+
+ html_head
+ parts['html_head'] contains the HTML <head> content, less the stylesheet
+ link and the <head> and </head> tags themselves. Since publish_parts
+ returns Unicode strings and does not know about the output encoding, the
+ "Content-Type" meta tag's "charset" value is left unresolved, as "%s":
+
+ <meta http-equiv="Content-Type" content="text/html; charset=%s" />
+
+ The interpolation should be done by client code.
+
+ html_prolog
+
+ parts['html_prolog] contains the XML declaration and the doctype
+ declaration. The XML declaration's "encoding" attribute's value is left
+ unresolved, as "%s":
+
+ <?xml version="1.0" encoding="%s" ?>
+
+ The interpolation should be done by client code.
+
+ html_subtitle
+ parts['html_subtitle'] contains the document subtitle, including the
+ enclosing <h2 class="subtitle"> & </h2> tags.
+
+ html_title
+ parts['html_title'] contains the document title, including the enclosing
+ <h1 class="title"> & </h1> tags.
+
+ meta
+ parts['meta'] contains all <meta ... /> tags.
+
+ stylesheet
+ parts['stylesheet'] contains the embedded stylesheet or stylesheet link.
+
+ subtitle
+ parts['subtitle'] contains the document subtitle text and any inline
+ markup. It does not include the enclosing <h2> & </h2> tags.
+
+ title
+ parts['title'] contains the document title text and any inline
+ markup. It does not include the enclosing <h1> & </h1> tags.
+ """
+
+ # settings for publish_parts
+ # input_encoding: The encoding of `input_string`. If it is an encoded
+ # 8-bit string, provide the correct encoding. If it is a Unicode string,
+ # use "unicode", the default.
+
+ overrides = {'input_encoding': 'utf-8',
+ 'doctitle_xform': doctitle,
+ 'initial_header_level': initial_header_level,
+ 'stylesheet_path' : stylesheet,
+ 'embed_stylesheet' : embed_stylesheet,
+ 'cloak_email_addresses' : True,
+ }
+ parts = core.publish_parts(source=input_string, source_path=source_path,
+ destination_path=destination_path,
+ writer_name='html5_polyglot', settings_overrides=overrides)
+ return parts
+
+
+def make_html(src_fo, dest_fo, embed_stylesheet=False, stylesheet=CSS, url_prefix=''):
+ """Make an HTML file from a reStructuredText source file."""
+ # Fix the url_prefix path in the banner HTML.
+ # This Python tricky business is necessary because the custom docutils
+ # writer, which inserts the HTML blobs, can't do it, because docutils
+ # doesn't provide any way to pass an argument such as image_dir to the
+ # writer.
+ # There must be a better way, but I haven't figured it out yet.
+ if url_prefix:
+ html_fragments.url_prefix = url_prefix.rstrip('/') + '/'
+
+ html_fragments.nav = html_fragments.make_nav()
+ html_fragments.banner = html_fragments.make_banner()
+ html_fragments.footer = html_fragments.make_footer()
+
+ rst_string = src_fo.read()
+
+ src_filepath = src_fo.name
+ # change to document's original directory, so docutils can find any
+ # things it might include via "include::"
+ cwdsave = os.getcwd()
+ if src_filepath != '<stdin>':
+ os.chdir(os.path.dirname(os.path.abspath(src_filepath)))
+ doc_parts = make_html_parts(rst_string, stylesheet=stylesheet, embed_stylesheet=embed_stylesheet)
+ os.chdir(cwdsave)
+
+ webpage = assemble_html(doc_parts, stylesheet_screen=stylesheet)
+ try:
+ dest_fo.write(webpage)
+ except Exception as e:
+ logerror("Failed to create output file: %s" % e)
+ return 1
+
+ return 0
+
+
+def main(argv=None):
+ import getopt
+
+ sys.stdin.reconfigure(encoding=ENCODING) # iso-8859-1 is also possible
+ sys.stdout.reconfigure(encoding=ENCODING)
+
+ if argv is None:
+ argv = sys.argv
+ try:
+ # parse command line options
+ try:
+ opts, args = getopt.getopt(argv[1:], 'hs:eu:',
+ ['help',
+ 'stylesheet=',
+ 'embed-stylesheet',
+ 'url-prefix=',
+ ])
+ except getopt.GetoptError as msg:
+ raise Usage(msg)
+
+ # process options
+ embed_stylesheet = False
+ stylesheet = None
+ url_prefix = ''
+
+ for opt, val in opts:
+ if opt in ("-h", "--help"):
+ loginfo(__doc__)
+ return 0
+
+ elif opt in ("-s", "--stylesheet"):
+ stylesheet = val
+
+ elif opt in ("-e", "--embed-stylesheet"):
+ embed_stylesheet = True
+
+ elif opt in ("-u", "--url-prefix"):
+ url_prefix = val
+
+ else:
+ logerror("Unrecognized option: %s\nfor help use --help" % opt)
+ return 1
+
+ # process arguments
+ src_fo = sys.stdin
+ dest_fo = sys.stdout
+
+ if len(args) >= 1:
+ src_filename = args[0]
+ try:
+ src_fo = open(src_filename, encoding=ENCODING)
+ except Exception as e:
+ logerror("Failed to open %s for reading: %s" % (src_filename, e))
+ return 2
+
+ if len(args) >= 2:
+ dest_filename = args[1]
+ try:
+ dest_fo = open(dest_filename, 'w', encoding=ENCODING)
+ except Exception as e:
+ logerror("Failed to open %s for writing: %s" % (dest_filename, e))
+ return 3
+
+ return make_html(src_fo, dest_fo, embed_stylesheet=embed_stylesheet,
+ stylesheet=stylesheet, url_prefix=url_prefix)
+
+
+
+ except Usage as err:
+ logerror(err.msg)
+ logerror("for help use --help")
+ return 11
+
+
+
+if __name__ == "__main__":
+ sys.exit(main())
+
+# vim:ts=4:sw=4:expandtab
diff --git a/scripts/rst2htmldeco.py b/scripts/rst2htmldeco.py
deleted file mode 100755
index 699d6f2..0000000
--- a/scripts/rst2htmldeco.py
+++ /dev/null
@@ -1,231 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# vim:ts=4:sw=4:expandtab
-
-#* Author: Mark Mitchell
-#* Copyright 2005-2008 Mark Mitchell, All Rights Reserved
-#* License: see __license__ below.
-
-# Use Python 3 print function in Python >= 2.6
-from __future__ import print_function
-
-__doc__ = """
-Renders reStructuredText files to HTML using the custom docutils writer
-docutils_htmldeco_writer, which inserts a common header and navigation menu at
-the top of all HTML pages. The header and navigation HTML blobs are
-kept in a separate python file, html_fragments.py.
-
-Usage:
- rst2htmldeco.py [options] SRCFILE OUTFILE
-
- SRCFILE is the path to a restructured text file.
- For example: ./AUTHORS.txt
-
- OUTFILE is the path where the HTML file is written.
- For example: ./www/authors.html
-
- Options:
-
- -h --help Print this help message
- -e --embed-stylesheet=<FILE>
- The stylesheet will be embedded in the HTML.
- -l --link-stylesheet=<URL>
- The HTML file will Link to the stylesheet,
- using the URL verbatim.
- -r --url-prefix=<PATH>
- The value of url-prefix is prefixed to all the URLs in the
- path to get to the top directory from the OUTFILE
- directory. Used to create working relative URLs in the custom
- header and navigation menu. Defaults to empty.
- Example: --url-prefix=../../
-
-
- -e and -l are mutually excusive. If neither is specified, nothing
- will work.
-
- Note that images referenced from the stylesheet may require different
- image-dir paths depending on whether the stylesheet is embedded or linked.
- If linked, image URLs in the stylesheet are relative to the stylesheet's
- location. If embedded, image URLs in the stylesheet are relative to the
- HTML file's path.
-
-Embedding vs. linking stylesheet
-=================================
-
-Embedding stylesheet
-----------------------
-* The HTML file needs no additional files in particular locations in order
- to render nicely.
-* The size of every HTML file is inflated. Download time is increased.
-
-Linking stylesheet
--------------------
-* Best performance for files served via HTTP, as browsers will download the
- stylesheet once and cache it, and individual HTML files will be more compact.
-
-* No need to regenerate every HTML file if the stylesheet is changed.
-
-* If the HTML file is detached from stylesheet, it will look very plain
- when rendered by a browser.
-
-Images are always referenced (there's two, the logo and banner background),
-so will not be rendered if the HTML file is detached from the image files.
-"""
-
-__copyright__ = "2005, 2008, Mark Mitchell"
-
-__license__ = """
-Copyright 2005, 2008, Mark Mitchell
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this oftware and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-The Software is provided "as is", without warranty of any kind,
-express or implied, including but not limited to the warranties of
-merchantability, fitness for a particular purpose and noninfringement.
-In no event shall the authors or copyright holders be liable for any
-claim, damages or other liability, whether in an action of contract,
-tort or otherwise, arising from, out of or in connection with Software
-or the use or other dealings in the Software.
-"""
-
-import sys
-import os, os.path
-import locale
-import getopt
-
-import html_fragments
-
-
-try:
- locale.setlocale(locale.LC_ALL, '')
-except:
- pass
-
-from docutils.core import publish_cmdline, default_description
-
-
-# Python module name of the custom HTML writer, must be in sys.path
-rst_writer = 'docutils_htmldeco_writer'
-
-docutils_opts = [
- '--cloak-email-addresses', # Obfusticate email addresses
- '--no-generator', # no "Generated by Docutils" credit and link at the end of the document.
- # '--date', # Include the date at the end of the document (UTC)
- # '--time', # Include the time & date (UTC)
- '--no-datestamp', # Do not include a datestamp of any kind
- '--traceback', # Enable Python tracebacks when Docutils is halted.
- '--rfc-references', # Recognize and link to standalone RFC references (like "RFC 822")
- '--rfc-base-url=http://tools.ietf.org/html/', # Base URL for RFC references
-]
-
-
-def make_html(src, dest, embed_stylesheet=False,
- stylesheet=None, url_prefix=''):
-
- # Fix the url_prefix path in the banner HTML.
- # This Python tricky business is necessary because the custom docutils
- # writer, which inserts the HTML blobs, can't do it, because docutils
- # doesn't provide any way to pass an argument such as image_dir to the
- # writer.
- # There must be a better way, but I haven't figured it out yet.
- if url_prefix:
- html_fragments.url_prefix = url_prefix.rstrip('/') + '/'
- html_fragments.nav = html_fragments.make_nav()
- html_fragments.banner = html_fragments.make_banner()
- html_fragments.footer = html_fragments.make_footer()
-
- args = list(docutils_opts)
- if embed_stylesheet:
- # for embedded stylesheet
- args.append('--stylesheet-path=%s' % stylesheet)
- args.append('--embed-stylesheet')
- else:
- # for linked stylesheet
- args.append('--stylesheet=%s' % stylesheet)
- args.append('--link-stylesheet')
- if src is not None:
- args.append(src)
- if dest is not None:
- args.append(dest)
-
- # Invoke docutils processing of the reST document. This call
- # to a docutils method ends up executing the custom HTML writer
- # in docutils_htmldeco_writer.py
- description = ('Generates (X)HTML documents from standalone reStructuredText '
- 'sources, with custom banner and footer. ' + default_description)
- publish_cmdline(writer_name=rst_writer,
- description=description,
- argv=args)
-
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv[1:]
-
- # parse command line options
- try:
- opts, posn_args = getopt.getopt(argv, 'he:l:u:',
- ['help',
- 'embed-stylesheet=',
- 'link-stylesheet=',
- 'url-prefix=',
- ])
- except getopt.GetoptError as msg:
- print(msg)
- print(__doc__)
- return 1
-
- # process options
- embed_stylesheet = False
- link_stylesheet = True
- stylesheet = None
- url_prefix = ''
-
- for opt, val in opts:
- if opt in ("-h", "--help"):
- print(__doc__)
- return 0
-
- if opt in ("-e", "--embed-stylesheet"):
- link_stylesheet = False
- embed_stylesheet = True
- stylesheet = val
-
- if opt in ("-l", "--link-stylesheet"):
- embed_stylesheet = False
- link_stylesheet = True
- stylesheet = val
-
- if opt in ("-u", "--url-prefix"):
- url_prefix = val
-
- #if len(posn_args) != 2:
- # print >> sys.stderr, 'Missing arguments'
- # print >> sys.stderr, __doc__
- # return 1
-
- try:
- srcfile_path = posn_args[0]
- except IndexError:
- srcfile_path = None
- try:
- outfile_path = posn_args[1]
- except IndexError:
- outfile_path = None
-
- make_html(srcfile_path, outfile_path, embed_stylesheet=embed_stylesheet,
- stylesheet=stylesheet, url_prefix=url_prefix)
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main())