Example #1
0
def rst_to_html(text):
    if not isinstance(text, text_type):
        text = text_type(text)

    if not has_sphinx:  # pragma: no cover
        return '<pre>%s</pre>' % text if text else ''

    sphinx, pub = get_sphinx()

    pub.set_source(text, None)

    try:
        pub.publish()
    except:
        log.warning('ReST to HTML error\n %s', text)
        return '<pre>%s</pre>' % text

    doctree = pub.document
    sphinx.env.filter_messages(doctree)
    for domain in sphinx.env.domains.values():
        domain.process_doc(sphinx.env, 'text', doctree)

    pub.writer.write(doctree, io.StringOutput(encoding='unicode'))
    pub.writer.assemble_parts()

    parts = pub.writer.parts
    return ''.join(
        (parts['body_pre_docinfo'], parts['docinfo'], parts['body']))
Example #2
0
 def build_doc(docname):
     doctree = self.env.get_doctree(docname)
     doctree.settings = self.docsettings
     destination = io.StringOutput(encoding='utf-8')
     self.docwriter.write(doctree, destination)
     self.docwriter.assemble_parts()
     return self.docwriter.parts['fragment']
Example #3
0
def debugTree(doc):
    """Returns the pseudoxml for the given document tree
    """
    so = io.StringOutput(encoding="utf8")
    WriterClass = writers.get_writer_class("pseudoxml")
    pxw = WriterClass()
    out = pxw.write(doc, so)
    return out.decode('utf8')
import sys
import zipfile
from cStringIO import StringIO

from docutils import core, io

import OOdirectives
import OOtext
import OOwriter

pub = core.Publisher(writer=OOwriter.Writer())
pub.set_reader('standalone', None, 'restructuredtext')
settings = pub.get_settings()
pub.source = io.FileInput(settings, source_path=sys.argv[1])
pub.destination = io.StringOutput(settings)
content = pub.publish()

manifest_list = [
    ('content.xml', content),
    ('styles.xml', OOtext.styles)
    ]

manifest_entries = []
for docname, _ in manifest_list:
    manifest_entries.append(OOtext.manifest_format % docname)
manifest = OOtext.manifest % '\n '.join(manifest_entries)
manifest_list.append( ('META-INF/manifest.xml', manifest) )

zip = zipfile.ZipFile(sys.argv[2], "w")
for docname, contents in manifest_list:
    zinfo = zipfile.ZipInfo(docname)
    import OOtext
    import OOwriter as EffWriter
elif writer is MIF:
    import MIFwriter as EffWriter
else:
    raise "Bad writer"

pub = core.Publisher(writer=EffWriter.Writer(EffMap.StyleMap))
inliner = EffParser.Inliner()
pub.set_reader('standalone', EffParser.Parser(inliner=inliner), 
    'restructuredtext')
settings = pub.get_settings()
#settings.doctitle_xform = 0
settings.traceback = 1
pub.source = io.FileInput(source_path=sys.argv[1])
pub.destination = io.StringOutput(encoding='utf-8')
content = pub.publish()

if writer is OO:
    manifest_list = [
        ('content.xml', content),
        ('styles.xml', OOtext.styles)
        ]

    manifest_entries = []
    for docname, _ in manifest_list:
        manifest_entries.append(OOtext.manifest_format % docname)
    manifest = OOtext.manifest % '\n '.join(manifest_entries)
    manifest_list.append( ('META-INF/manifest.xml', manifest) )

    zip = zipfile.ZipFile(outfile, "w")