コード例 #1
0
ファイル: __init__.py プロジェクト: minrk/ipython-svn-archive
def write():
    """A simple command to get the notebook document. Now defaults to HTML."""

    import docutils, docutils.io
    from docutils.writers.html4css1 import Writer

    out = docutils.io.FileOutput()
    out.encoding = 'unicode'
    w = Writer()
    w.write(document, out)
コード例 #2
0
ファイル: html.py プロジェクト: stpierre/dmr
    def output(self):
        writer = Writer()
        output = StringOutput(encoding="utf8")
        mydoc = copy.deepcopy(self.document.source)
        mydoc.reporter = self.document.source.reporter
        mydoc.settings = \
            OptionParser(components=(Writer,)).get_default_values()
        if config.footer:
            mydoc.append(
                docutils.nodes.footer(config.footer,
                                      docutils.nodes.Text(config.footer)))

        return writer.write(mydoc, output)
コード例 #3
0
import transform
from docutils.writers.html4css1 import Writer
from docutils.frontend import OptionParser

usage = '%prog [options] [<package-directory> | <python-file> [html-file]]'
description = ('Generates .html documentation for the given Python package'
               ' or module.')

writer = Writer()

option_parser = OptionParser(components=[writer],
                             usage=usage,
                             description=description)

settings = option_parser.parse_args(sys.argv[1:])

source_path = settings._source
target_path = settings._destination

nodes = parse_package_or_module(source_path)

# That then needs converting to a docutils tree
document = transform.make_document(nodes, settings)

# And *that* wants converting to the appropriate output format
try:
    target = open(target_path, "w")
    writer.write(document, target)
finally:
    target.close()
コード例 #4
0
        elif output_format == "ast":
            thing.show_ast(outstream)
            print
        elif output_format == "pretty":
            outstream.write(document.pformat(indent="  "))
        elif output_format == "xml":
            if not quiet: print >> sys.stderr, "*** Producing a DOM tree"
            domtree = document.asdom()
            if not quiet: print >> sys.stderr, "    Writing XML"
            domtree.writexml(outstream, indent="", addindent="  ", newl="\n")
        elif output_format == "html":
            if not quiet: print >> sys.stderr, "*** Writing HTML"
            if new_writer:
                from docutils.writers.html4css1 import Writer
                writer = Writer()
                writer.write(document, outstream)
            elif input_format == "text":
                writer = html.Writer()
                writer(document, outstream)
            else:
                writer = html.PythonWriter()
                writer(document, outstream)
    finally:
        if outstream != sys.stdout:
            outstream.close()


# ----------------------------------------------------------------------
if __name__ == "__main__":
    main()
コード例 #5
0
ファイル: pysrc2html.py プロジェクト: Distrotech/docutils
from package import parse_package_or_module
import transform
from docutils.writers.html4css1 import Writer
from docutils.frontend import OptionParser

usage = '%prog [options] [<package-directory> | <python-file> [html-file]]'
description = ('Generates .html documentation for the given Python package'
               ' or module.')

writer = Writer()

option_parser = OptionParser(components=[writer],
                             usage=usage,description=description)

settings = option_parser.parse_args(sys.argv[1:])

source_path = settings._source
target_path = settings._destination

nodes = parse_package_or_module(source_path)

# That then needs converting to a docutils tree
document = transform.make_document(nodes,settings)

# And *that* wants converting to the appropriate output format
try:
    target = open(target_path,"w")
    writer.write(document,target)
finally:
    target.close()
コード例 #6
0
settings.stylesheet = None
settings.initial_header_level = "1"
reporter = Reporter(source,
                    settings.report_level,
                    settings.halt_level,
                    stream=settings.warning_stream,
                    debug=settings.debug,
                    encoding=settings.error_encoding,
                    error_handler=settings.error_encoding_error_handler)
document = nodes.document(settings, reporter)

title = nodes.title(text="This is the title")
subtitle = nodes.subtitle(text=".. with a subtitle")

introduction = nodes.section()
start = nodes.paragraph(text="The introduction starts with this.")
introduction += start

background = nodes.section()
background += nodes.paragraph(
    text="This paragraph starts the second section, background.")

document += [title, subtitle, introduction, background]

#print str(document)

out = docutils.io.FileOutput()
out.encoding = 'unicode'
w = Writer()
w.write(document, out)
コード例 #7
0
ファイル: pysource.py プロジェクト: Distrotech/docutils
        elif output_format == "ast":
            thing.show_ast(outstream)
            print
        elif output_format == "pretty":
            outstream.write(document.pformat(indent="  "))
        elif output_format == "xml":
            if not quiet: print >>sys.stderr, "*** Producing a DOM tree"
            domtree = document.asdom()
            if not quiet: print >>sys.stderr, "    Writing XML"
            domtree.writexml(outstream,indent="", addindent="  ",newl="\n")
        elif output_format == "html":
            if not quiet: print >>sys.stderr, "*** Writing HTML"
            if new_writer:
                from docutils.writers.html4css1 import Writer
                writer = Writer()
                writer.write(document,outstream)
            elif input_format == "text":
                writer = html.Writer()
                writer(document,outstream)
            else:
                writer = html.PythonWriter()
                writer(document,outstream)
    finally:
        if outstream != sys.stdout:
            outstream.close()


# ----------------------------------------------------------------------
if __name__ == "__main__":
    main()