Beispiel #1
0
 def translate(self, *args, **kwargs):
     self.document.settings.newlines = \
       self.document.settings.indents = \
       self.builder.env.config.xml_pretty
     self.document.settings.xml_declaration = True
     self.document.settings.doctype_declaration = True
     return BaseXMLWriter.translate(self)
Beispiel #2
0
 def translate(self, *args, **kwargs):
     self.document.settings.newlines = \
         self.document.settings.indents = \
         self.builder.env.config.xml_pretty
     self.document.settings.xml_declaration = True
     self.document.settings.doctype_declaration = True
     return BaseXMLWriter.translate(self)
Beispiel #3
0
def rst2xml(rststring, source_path=None):
    reader = HovercraftReader()
    writer = Writer()
    result = publish_string(rststring,
                            source_path=source_path,
                            reader=reader,
                            writer=writer,
                            settings_overrides={'syntax_highlight': 'short'})
    dependencies = reader.settings.record_dependencies.list
    return result, dependencies
Beispiel #4
0
 def __init__(self, builder):
     BaseXMLWriter.__init__(self)
     self.builder = builder
Beispiel #5
0
 def __init__(self, builder):
     # type: (Builder) -> None
     BaseXMLWriter.__init__(self)
     self.builder = builder
     self.translator_class = self.builder.get_translator_class()
Beispiel #6
0
 def __init__(self, builder):
     # type: (Builder) -> None
     BaseXMLWriter.__init__(self)
     self.builder = builder
     self.translator_class = self.builder.get_translator_class()
Beispiel #7
0
 def __init__(self, builder):
     BaseXMLWriter.__init__(self)
     self.builder = builder
     if self.builder.translator_class:
         self.translator_class = self.builder.translator_class
Beispiel #8
0
 def __init__(self, builder):
     BaseXMLWriter.__init__(self)
     self.builder = builder
Beispiel #9
0
 def __init__(self, builder):
     BaseXMLWriter.__init__(self)
     self.builder = builder
     if self.builder.translator_class:
         self.translator_class = self.builder.translator_class
Beispiel #10
0
def rst2xml(rststring):
    return publish_string(rststring,
                          reader=HovercraftReader(),
                          writer=Writer(),
                          settings_overrides={'syntax_highlight': 'short'})
Beispiel #11
0
def env_updated(app, env):
    config = app.builder.config

    doctree = env.get_doctree(config.master_doc)
    from sphinx import addnodes

    toctrees = []
    for toctreenode in doctree.traverse(addnodes.toctree):
        toctree = env.resolve_toctree(config.master_doc, app.builder, 
            toctreenode, prune = False, includehidden = True, maxdepth = 0,
            collapse = False)
        toctrees.append(toctree)

    if not toctrees:
        toc = None
    else:
        toc = toctrees[0]
        for toctree in toctrees[1:]:
            toc.extend(toctree.children)

    # toc = env.get_toctree_for(config.master_doc, app.builder, False)

    node = toc

    doc = new_document(b('<partial node>'))
    doc.append(node)

    pub = Publisher(
            source_class = DocTreeInput,
            destination_class=StringOutput)

    pub.set_components('standalone', 'restructuredtext', 'pseudoxml')

    pub.reader = DoctreeReader()
    pub.writer = Writer()
    pub.writer.format = 'pseudoxml'
    pub.process_programmatic_settings(
        None, {'output_encoding': 'unicode'}, None)
    pub.set_source(doc, None)
    pub.set_destination(None, None)
    pub.publish()

    import xml.etree.cElementTree as ET
    from cStringIO import StringIO

    #out = re.sub(r'^<!DOCTYPE[^>]*>\s*', '<?xml version="1.0"?>', pub.writer.output)
    out = pub.writer.output.encode('utf-8').replace(' encoding="unicode"', ' encoding="utf-8"')

    #pprint.pprint(out)

    doctree = ET.fromstring(out)

    #pprint.pprint(doctree)
    #pprint.pprint(dir(doctree))
    if hasattr(doctree, 'getroot'):
        doctree = doctree.getroot()
    #root = doctree.getroot()

    fuzzy_find_entries = []
    docs = {}

    def indexentries(entry, links, cap = ''):
        if links:
            fuzzy_find_entries.append(dict(
                href = links[0][1],
                name = entry,
                path = "index/%s/%s" % (char,cap),
                info = "INDEX",
                detail = '',
            ))

            for i, (ismain, link) in enumerate(links[1:], start=1):
                doclink = link.split('#', 1)[0]
                docname = docs.get(doclink, i)
                fuzzy_find_entries.append(dict(
                    href = link,
                    name = "%s (%s)" % (entry, docname),
                    path = "index/%s/%s" % (char, cap),
                    info = "INDEX",
                    detail = '',
                ))
            return ''
        else:
            return entry

    if app.config.html_findanything_add_topics:
        if hasattr(doctree, 'iter'):
            references = doctree.iter('reference')
        else:
            references = doctree.getiterator('reference')

    #            fuzzy_find_entries.append(dict(
    #                    href = link,
    #                    name = entry,
    #                    path = "index/%s/" % char,
    #                    info = "INDEX",
    #                    detail = '',
    #                ))

        refset = set()

        for ref in references:
            refuri = ref.attrib['refuri']

            docs[refuri] = ref.text
            path = "/"
            if "/" in refuri:
                path = refuri.rsplit('/', 1)[0]+"/"

            if '#' in refuri:
                docname = docs.get(refuri.split('#', 1)[0])
                if docname:
                    path += docname + "/"
                info = 'SECTION'
            else:
                info = 'PAGE'

            e = dict(
                    href = ref.attrib['refuri'],
                    name = ref.text,
                    info = info,
                    path = path,
                    detail = '',
                )

            refid = "%(href)s^%(path)s^%(name)s^%(info)s" % e

            if refid in refset: continue

            refset.add(refid)

            fuzzy_find_entries.append(e)


    if app.config.html_findanything_add_indexentries:
        genindex = env.create_index(app.builder)

        for char,char_list in genindex:
            for entry, (links, subitems) in char_list:
                cap = indexentries(entry, links)
                if subitems:
                    if cap: cap += '/'
                    for subname, sublinks in subitems:
                        indexentries(subname, sublinks, cap=cap)
    
    s = json.dumps(fuzzy_find_entries)

    static_dir = os.path.join(app.builder.outdir, '_static')

    if not os.path.exists(static_dir):
        os.makedirs(static_dir)

    with open(os.path.join(static_dir, 'fuzzyindex.js'), 'wb') as f:
        f.write("DOCUMENTATION_OPTIONS.FIND_ANYTHING_ENTRIES = %s;" % s);


        if app.config.html_findanything_use_cached_hits:
            f.write("DOCUMENTATION_OPTIONS.FIND_ANYTHING_USE_CACHED_HITS = true;")

        f.write("DOCUMENTATION_OPTIONS.FIND_ANYTHING_WIDTH = '%s';" 
            % app.config.html_findanything_width);
Beispiel #12
0
    #     --input-encoding-error-handler

    settingsSpec = SettingsSpec()
    for arg in sys.argv:
        if arg in settingsSpec.xsltOptions:
            usePython = False
    if usePython:
        from odf2docutilslib.python import Parser
        from docutils.writers.docutils_xml import Writer
    else:
        from odf2docutilslib.xslt import Parser, Writer

    pub = docutils.core.Publisher(
        docutils.readers.Reader(),
        Parser(),
        Writer(),
        source_class=OdfFileInput,
        destination_class=docutils.io.BinaryFileOutput)
    pub.process_command_line(
        settings_spec=settingsSpec,
        description=
        "Reads ODF file <source> (default is stdin) and writes Docutils XML to <destination> (default is stdout)."
    )
    if pub.settings.python != usePython:
        raise AssertionError(
            "Internal error: Assumed setting of --xslt/--python not confirmed by explicit parsing"
        )
    pub.publish()

# TODO Use XSLT variant as export filter for LibreOffice - which works from
#      scratch using https://help.libreoffice.org/Common/Creating_XML_Filters