Пример #1
0
def features_doc():
    import feets

    import rst2html5_

    from docutils.core import publish_parts

    rows = []
    extractors = sorted({e for e in feets.registered_extractors().values()})
    for idx, ext in enumerate(extractors):
        name = ext.__name__

        doc = publish_parts(make_title(name) +
                            deindent_reference(ext.__doc__ or ""),
                            writer_name='html5',
                            writer=rst2html5_.HTML5Writer())["body"]

        features = ext.get_features()
        data = sorted(ext.get_data(), key=feets.extractors.DATAS.index)

        if len(features) > 4:
            features = list(features)[:4] + ["..."]
        rows.append((name, doc, ext, features, data))
    rows.sort()
    return HTML(DOC_TEMPLATE.render(rows=rows))
Пример #2
0
def test_readme_sanity(mocker):
    fake_stdout = io.StringIO()  # just to ignore the output
    fake_stderr = io.StringIO()  # will have content if there are problems
    with open('README.rst', 'rt', encoding='utf8') as fh:
        mocker.patch('sys.stdout', fake_stdout)
        mocker.patch('sys.stderr', fake_stderr)
        docutils.core.publish_file(source=fh, writer=rst2html5_.HTML5Writer())

    errors = fake_stderr.getvalue()
    assert not bool(errors), "There are issues!\n" + errors
Пример #3
0
def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
             destination_path=None, reader=None,
             parser=None, parser_name='restructuredtext', writer=None,
             writer_name='html5', settings=None, settings_spec=None,
             settings_overrides=None, config_section=None,
             enable_exit_status=None, logger=None, l_add_ln=0):
    """
    Set up & run a `Publisher`, and return a dictionary of document parts.
    Dictionary keys are the names of parts, and values are Unicode strings;
    encoding is up to the client.  For programmatic use with string I/O.

    For encoded string input, be sure to set the 'input_encoding' setting to
    the desired encoding.  Set it to 'unicode' for unencoded Unicode string
    input.  Here's how::

        publish_parts(..., settings_overrides={'input_encoding': 'unicode'})

    Parameters: see `publish_programmatically`.

    WARNING: `reader` should be None (or NikolaReader()) if you want Nikola to report
             reStructuredText syntax errors.
    """
    if reader is None:
        reader = NikolaReader()
        # For our custom logging, we have special needs and special settings we
        # specify here.
        # logger    a logger from Nikola
        # source   source filename (docutils gets a string)
        # add_ln   amount of metadata lines (see comment in compile_html above)
        reader.l_settings = {'logger': logger, 'source': source_path,
                             'add_ln': l_add_ln}

    if writer is None:
        writer = rst2html5_.HTML5Writer()

    pub = docutils.core.Publisher(reader, parser, writer, settings=settings,
                                  source_class=source_class,
                                  destination_class=docutils.io.StringOutput)
    pub.set_components(None, parser_name, writer_name)
    pub.process_programmatic_settings(
        settings_spec, settings_overrides, config_section)
    pub.set_source(source, None)
    pub.settings._nikola_source_path = source_path
    pub.set_destination(None, destination_path)
    pub.publish(enable_exit_status=enable_exit_status)

    return pub.writer.parts['body'], pub.document.reporter.max_level, pub.settings.record_dependencies