当前位置: 首页>>代码示例>>Python>>正文


Python core.publish_parts方法代码示例

本文整理汇总了Python中docutils.core.publish_parts方法的典型用法代码示例。如果您正苦于以下问题:Python core.publish_parts方法的具体用法?Python core.publish_parts怎么用?Python core.publish_parts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.core的用法示例。


在下文中一共展示了core.publish_parts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def render(raw, stream=None, **kwargs):
    if stream is None:
        # Use a io.StringIO as the warning stream to prevent warnings from
        # being printed to sys.stderr.
        stream = io.StringIO()

    settings = SETTINGS.copy()
    settings["warning_stream"] = stream

    writer = Writer()
    writer.translator_class = ReadMeHTMLTranslator

    try:
        parts = publish_parts(raw, writer=writer, settings_overrides=settings)
    except SystemMessage:
        rendered = None
    else:
        rendered = parts.get("docinfo", "") + parts.get("fragment", "")

    if rendered:
        return clean(rendered)
    else:
        return None 
开发者ID:pypa,项目名称:readme_renderer,代码行数:25,代码来源:rst.py

示例2: rst

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def rst(cls, string, show_everything=False, translation=gettext.NullTranslations(), initial_header_level=3,
            debug=False):
        """Parses reStructuredText"""
        overrides = {
            'initial_header_level': initial_header_level,
            'doctitle_xform': False,
            'syntax_highlight': 'none',
            'force_show_hidden_until': show_everything,
            'translation': translation,
            'raw_enabled': True,
            'file_insertion_enabled': False,
            'math_output': 'MathJax /this/does/not/need/to/exist.js'
        }
        if debug:
            overrides['halt_level'] = 2
            overrides['traceback'] = True
        parts = core.publish_parts(source=string, writer=_CustomHTMLWriter(),
                                   settings_overrides=overrides)
        return parts['body_pre_docinfo'] + parts['fragment']

# override base directives 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:23,代码来源:parsable_text.py

示例3: gcode_formatted_description_node_visit

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def gcode_formatted_description_node_visit(self, node):
  self.body.append("<div class='col-xs-8'>")

  # doesn't seem the directive which instantiates this node gets the full set of settings
  # add the necessary ones that the rst admonition parser relies on
  settings = copy.copy(node.document.settings)

  settings.traceback = True
  settings.tab_width = 4
  settings.pep_references = False
  settings.rfc_references = False
  settings.smartquotes_locales = None
  settings.env.temp_data['docname'] = 'gcodes'
  settings.language_code = 'en'

  # since we're using docutils directly, it doesn't support '.. versionadded::' directive
  # patch the language file so it displays correctly
  import docutils
  docutils.languages.en.labels['versionmodified'] = 'New in Version'

  published = publish_parts(node['raw'], writer_name='html', settings=settings)['html_body']
  self.body.append(published)

  self.body.append("</div>") 
开发者ID:intelligent-agent,项目名称:redeem,代码行数:26,代码来源:nodes.py

示例4: html_doc

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def html_doc(self):
        """Methods docstring, as HTML"""
        if not self.raw_docstring:
            result = ''

        elif settings.MODERNRPC_DOC_FORMAT.lower() in ('rst', 'restructred', 'restructuredtext'):
            from docutils.core import publish_parts
            result = publish_parts(self.raw_docstring, writer_name='html')['body']

        elif settings.MODERNRPC_DOC_FORMAT.lower() in ('md', 'markdown'):
            import markdown
            result = markdown.markdown(self.raw_docstring)

        else:
            result = "<p>{}</p>".format(self.raw_docstring.replace('\n\n', '</p><p>').replace('\n', ' '))

        return result 
开发者ID:alorence,项目名称:django-modern-rpc,代码行数:19,代码来源:core.py

示例5: render

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def render(raw, stream=None):
    if stream is None:
        # Use a io.StringIO as the warning stream to prevent warnings from
        # being printed to sys.stderr.
        stream = io.StringIO()

    settings = SETTINGS.copy()
    settings["warning_stream"] = stream

    writer = Writer()
    writer.translator_class = ReadMeHTMLTranslator

    try:
        parts = publish_parts(raw, writer=writer, settings_overrides=settings)
    except SystemMessage:
        rendered = None
    else:
        rendered = parts.get("fragment")

    if rendered:
        return clean(rendered)
    else:
        return None 
开发者ID:holzschu,项目名称:Carnets,代码行数:25,代码来源:rst.py

示例6: features_doc

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
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)) 
开发者ID:quatrope,项目名称:feets,代码行数:29,代码来源:tutorial.py

示例7: html_parts

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def html_parts(input_string, source_path=None, destination_path=None,
               input_encoding='unicode', doctitle=True,
               initial_header_level=1):
    """
    Given an input string, returns a dictionary of HTML document 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.).
    - `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.
    - `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>").
    """
    overrides = {'input_encoding': input_encoding,
                 'doctitle_xform': doctitle,
                 'initial_header_level': initial_header_level}
    parts = core.publish_parts(
        source=input_string, source_path=source_path,
        destination_path=destination_path,
        writer_name='html', settings_overrides=overrides)
    return parts 
开发者ID:skarlekar,项目名称:faces,代码行数:36,代码来源:examples.py

示例8: _parse_comment_text

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def _parse_comment_text(self, text):
        settings = {'file_insertion_enabled': False,
                    'raw_enabled': False,
                    'output_encoding': 'unicode'}
        try:
            ret = publish_parts(text, writer_name='html',
                                settings_overrides=settings)['fragment']
        except Exception:
            ret = htmlescape(text)
        return ret 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:12,代码来源:core.py

示例9: restructuredtext

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def restructuredtext(value, short=False):
    try:
        from docutils.core import publish_parts
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError(
                "Error in 'restructuredtext' filter: "
                "The Python docutils library isn't installed."
            )
        return force_text(value)
    else:
        docutils_settings = {
            'raw_enabled': False,
            'file_insertion_enabled': False,
        }
        docutils_settings.update(getattr(settings, 'RESTRUCTUREDTEXT_FILTER_SETTINGS', {}))
        parts = publish_parts(source=force_bytes(value), writer_name="html4css1",
                              settings_overrides=docutils_settings)
        out = force_text(parts["html_body"])
        try:
            if short:
                out = out.split("\n")[0]
        except IndexError:
            pass
        finally:
            return mark_safe(out) 
开发者ID:readthedocs,项目名称:pydoc.io,代码行数:28,代码来源:core_tags.py

示例10: _render_html

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def _render_html(source):
        return core.publish_parts(
            source=source,
            writer=Writer(),
            writer_name='html',
            settings_overrides={'no_system_messages': True}
        ) 
开发者ID:openstack,项目名称:tripleo-validations,代码行数:9,代码来源:ansible-autodoc.py

示例11: _on_results_available

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def _on_results_available(self, results):
        self.setVisible(True)
        if len(results) and results[0] != '':
            string = '\n\n'.join(results)
            string = publish_parts(
                string, writer_name='html',
                settings_overrides={'output_encoding': 'unicode'})[
                    'html_body']
            string = string.replace('colspan="2"', 'colspan="0"')
            string = string.replace('<th ', '<th align="left" ')
            string = string.replace(
                '</tr>\n<tr class="field"><td>&nbsp;</td>', '')
            if string:
                skip_error_msg = False
                lines = []
                for l in string.splitlines():
                    if (l.startswith('<div class="system-message"') or
                            l.startswith(
                                '<div class="last system-message"')):
                        skip_error_msg = True
                        continue
                    if skip_error_msg:
                        if l.endswith('</div>'):
                            skip_error_msg = False
                    else:
                        lines.append(l)
                self.text_edit.setText('\n'.join(lines))
                return
        else:
            self.text_edit.setText(_('Documentation not found')) 
开发者ID:TuringApp,项目名称:Turing,代码行数:32,代码来源:quick_doc.py

示例12: _make_rst

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def _make_rst(self, file):
        return rst_gen(self._read(file), writer_name='html')['html_body'] 
开发者ID:vstconsulting,项目名称:polemarch,代码行数:4,代码来源:projects.py

示例13: help

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def help(self):
        if self.doc is None:
            self.doc = 'Sorry, no help available'
        try:
            from docutils.core import publish_parts
            doc = publish_parts(self.doc, writer_name='html')['html_body']
        except ImportError:
            doc = self.doc
        foo = QtWidgets.QMessageBox.information(self, "Routine documentation", doc, QtWidgets.QMessageBox.Ok) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:11,代码来源:Dialogs.py

示例14: rst2html

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def rst2html(rst):
    return publish_parts(rst, writer_name="html")["fragment"] 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:4,代码来源:BuildWebsite.py

示例15: DecodeReST

# 需要导入模块: from docutils import core [as 别名]
# 或者: from docutils.core import publish_parts [as 别名]
def DecodeReST(source):
    #print repr(source)
    res = ReSTPublishParts(
        source=PrepareDocstring(source),
        writer=HTML_DOC_WRITER,
        settings_overrides={"stylesheet_path": ""}
    )
    #print repr(res)
    return res['body'] 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:11,代码来源:Utils.py


注:本文中的docutils.core.publish_parts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。