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


Python html4css1.Writer类代码示例

本文整理汇总了Python中docutils.writers.html4css1.Writer的典型用法代码示例。如果您正苦于以下问题:Python Writer类的具体用法?Python Writer怎么用?Python Writer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: main

def main():

    # Create a writer to deal with the generic element we may have created.
    writer = Writer()
    writer.translator_class = MyTranslator

    description = (
        'Generates (X)HTML documents from standalone reStructuredText '
       'sources.  Be forgiving against unknown elements.  '
       + default_description)

    # the parser processes the settings too late: we want to decide earlier if
    # we are running or testing.
    if ('--test-patch' in sys.argv
            and not ('-h' in sys.argv or '--help' in sys.argv)):
        return test_patch(writer)

    else:
        # Make docutils lenient.
        patch_docutils()

        overrides = {
            # If Pygments is missing, code-block directives are swallowed
            # with Docutils >= 0.9.
            'syntax_highlight': 'none',

            # not available on Docutils < 0.8 so can't pass as an option
            'math_output': 'HTML',
        }

        publish_cmdline(writer=writer, description=description,
             settings_spec=LenientSettingsSpecs, settings_overrides=overrides)
        return 0
开发者ID:dsteinbrunner,项目名称:text-markup,代码行数:33,代码来源:rst2html_lenient.py

示例2: __init__

    def __init__(self):

        core.Publisher.__init__(self)
        self.set_reader('standalone', None, 'restructuredtext')
        writer = Writer()

        # we don't want HTML headers in our writer
        writer.translator_class = NoHeaderHTMLTranslator
        self.writer = writer

        # go with the defaults
        self.get_settings()

        self.settings.xml_declaration = ""

        # this is needed, but doesn't seem to do anything
        self.settings._destination = ''

        # use no stylesheet
        self.settings.stylesheet = ''
        self.settings.stylesheet_path = ''
        self.settings.embed_stylesheet = False

        # don't break if we get errors
        self.settings.halt_level = 6

        # remember warnings
        self.warnings = ''
开发者ID:philn,项目名称:alinea,代码行数:28,代码来源:ReST.py

示例3: rst2html

def rst2html(rst):
  from docutils.core import publish_string
  from docutils.writers.html4css1 import Writer,HTMLTranslator

  class xia2HTMLTranslator(HTMLTranslator):
    def __init__(self, document):
      HTMLTranslator.__init__(self, document)

    def visit_table(self, node):
      self.context.append(self.compact_p)
      self.compact_p = True
      classes = ' '.join(['docutils', self.settings.table_style]).strip()
      self.body.append(
        self.starttag(node, 'table', CLASS=classes, border="0"))

    def write_colspecs(self):
      self.colspecs = []

  xia2_root_dir = libtbx.env.find_in_repositories("xia2", optional=False)

  args = {
    'stylesheet_path': os.path.join(xia2_root_dir, 'css', 'voidspace.css')
  }

  w = Writer()
  w.translator_class = xia2HTMLTranslator

  return publish_string(rst, writer=w, settings=None, settings_overrides=args)
开发者ID:xia2,项目名称:xia2,代码行数:28,代码来源:html.py

示例4: assemble_parts

 def assemble_parts(self):
     # we will add 2 new parts to the writer: 'first_paragraph_as_text' and
     # 'images'
     Writer.assemble_parts(self)
     self.parts['first_paragraph_as_text'] = \
         self.visitor.first_paragraph_as_text
     self.parts['images'] = self.visitor.images
开发者ID:GoGoBunny,项目名称:blohg,代码行数:7,代码来源:writer.py

示例5: main

def main():
    """
    Parses the given ReST file or the redirected string input and returns the
    HTML body.

    Usage: rest2html < README.rst
           rest2html README.rst
    """
    try:
        text = codecs.open(sys.argv[1], 'r', 'utf-8').read()
    except IOError: # given filename could not be found
        return ''
    except IndexError: # no filename given
        text = sys.stdin.read()

    writer = Writer()
    writer.translator_class = GitHubHTMLTranslator

    parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
    if 'html_body' in parts:
        html = parts['html_body']

        # publish_parts() in python 2.x return dict values as Unicode type
        # in py3k Unicode is unavailable and values are of str type
        if isinstance(html, str):
            return html
        else:
            return html.encode('utf-8')
    return ''
开发者ID:nrgaway,项目名称:qubes-tools,代码行数:29,代码来源:rest2html.py

示例6: publishPage

    def publishPage(self,key):
        src = self.pages[key].rst
        pubpath = os.path.join(rootpath,"public",key)
        try:
            os.makedirs(os.path.split(pubpath)[0])
        except:
            pass
        # Soft reset
        traveler.features.reset()
        writer = Writer()
        writer.translator_class = HTMLTranslatorForLegalResourceRegistry
        keylst = key.split("/")
        upset = [".."] * (len(keylst)-1)
        css = os.path.sep.join(upset + ["screen.css"])
        octicons = os.path.sep.join(upset + ["bower_components/octicons/octicons/octicons.css"]) 
       
        options = {
            "stylesheet": octicons + "," + css,
            "stylesheet_path": None,
            "embed_stylesheet": False,
            "footnote_backlinks": True,
            "input_encoding": "utf-8"
            }
        src = src + '\n.. raw:: html\n\n   </div>\n'

        html = publish_string(src, reader=None, reader_name='standalone', writer=writer, settings_overrides=options)
        if self.writePages:
            codecs.open(pubpath, "w+", "utf-8").write(html)
开发者ID:fbennett,项目名称:legal-resource-registry,代码行数:28,代码来源:pages.py

示例7: rst_to_html

def rst_to_html(rst_string, settings=None):
    """Convert a string written in reStructuredText to an HTML string.

    :param rst_string:
        A string that holds the contents of a reStructuredText document.

    :param settings:
        Optional. A dictionary which overrides the default settings.

        For a list of the possible keys and values, see
        http://docutils.sourceforge.net/docs/user/config.html.

        To log the values used, pass in ``'dump_settings': 'yes'``.
    """
    writer = Writer()
    writer.translator_class = HTMLTranslator
    if settings is None:
        settings = {
            # Include a time/datestamp in the document footer.
            'datestamp': '%Y-%m-%d %H:%M UTC',
            # Recognize and link to standalone PEP references (like "PEP 258").
            'pep_references': 1,
            # Do not report any system messages.
            'report_level': 'none',
            # Recognize and link to standalone RFC references (like "RFC 822").
            'rfc_references': 1,
        }
    return core.publish_string(rst_string, writer=writer,
                               settings_overrides=settings)
开发者ID:kidaa,项目名称:Encyclopedia,代码行数:29,代码来源:rst.py

示例8: index

def index():
    flask.url_for('static', filename='github.css')
    flask.url_for('static', filename='semantic-1.2.0/semantic.css')
    flask.url_for('static', filename='semantic-1.2.0/semantic.js')
    flask.url_for('static', filename='qubes.css')

    input_filename = '/home/user/w/qubes-tools/NOTES.rst'
    # sys.argv.append('NOTES.rst')

    try:
        #text = codecs.open(sys.argv[1], 'r', 'utf-8').read()
        #with open(input_filename, "r", 'utf-8') as source:
        with open(input_filename, "r") as source:
            text = source.read().encode('utf-8')
    except IOError:  # given filename could not be found
        return ''
    except IndexError:  # no filename given
        text = sys.stdin.read()

    writer = Writer()
    writer.translator_class = rest2html.GitHubHTMLTranslator

    parts = docutils.core.publish_parts(text, writer=writer,
                                        settings_overrides=rest2html.SETTINGS)
    if 'html_body' in parts:
        print parts['html_body']
        html = flask.Markup(parts['html_body'])

        # publish_parts() in python 2.x return dict values as Unicode type
        # in py3k Unicode is unavailable and values are of str type
        if isinstance(html, str):
            return flask.render_template('index.html', html=html)
        else:
            return flask.render_template('index.html', html=html.encode('utf-8'))
    return flask.render_template('index.html', html='')
开发者ID:nrgaway,项目名称:qubes-tools,代码行数:35,代码来源:rest2html_flask_server.py

示例9: getPublicCmsReSTWriter

def getPublicCmsReSTWriter():

    global _PublicCmsReSTWriter, _PublicReSTTranslator

    if not _PublicCmsReSTWriter:
        _PublicCmsReSTWriter = Writer()
        _PublicCmsReSTWriter.translator_class = _PublicReSTTranslator

    return _PublicCmsReSTWriter
开发者ID:timparkin,项目名称:into-the-light,代码行数:9,代码来源:rest.py

示例10: translate

 def translate(self):
     # Build the document
     Writer.translate(self)
     # Build the contents
     contents = self.build_contents(self.document)
     contents_doc = self.document.copy()
     contents_doc.children = contents
     contents_visitor = self.translator_class(contents_doc)
     contents_doc.walkabout(contents_visitor)
     self.parts['toc'] = ''.join(contents_visitor.fragment)
开发者ID:cstroie,项目名称:tranpy,代码行数:10,代码来源:builder.py

示例11: form_example

 def form_example(self, ctx):
     form = formal.Form()
     form.addField('restString', formal.String(required=True),
             widgetFactory=formal.ReSTTextArea)
     if docutilsAvailable:
         w = Writer()
         w.translator_class = CustomisedHTMLTranslator
         form.addField('customRestString', formal.String(required=True),
                 formal.widgetFactory(formal.ReSTTextArea, restWriter=w))
     form.addAction(self.submitted)
     return form
开发者ID:bne,项目名称:squeal,代码行数:11,代码来源:restwidget.py

示例12: convert_string_fragment

def convert_string_fragment(string):
    """ Converts a string of reST text into an html fragment (ie no <header>,
        <body>, etc tags).
    """

    html_fragment_writer = Writer()
    html_fragment_writer.translator_class = HTMLFragmentTranslator
    return core.publish_string(_fix_indent(string),
                               writer = html_fragment_writer,
                               # Suppress output of warnings in html
                               settings_overrides={'report_level':'5'})
开发者ID:BabeNovelty,项目名称:blockcanvas,代码行数:11,代码来源:rest_html.py

示例13: output

    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)
开发者ID:stpierre,项目名称:dmr,代码行数:13,代码来源:html.py

示例14: about

def about(request, template="about.html"):
    """
    Convert the README file into HTML.
    """
    from docutils.core import publish_string
    from docutils.writers.html4css1 import Writer, HTMLTranslator
    writer = Writer()
    writer.translator_class = HTMLTranslator
    with open(join(settings.PROJECT_ROOT, "README.rst"), "r") as f:
        about = publish_string(f.read(), writer=writer)
    with open(join(settings.PROJECT_ROOT, "LICENSE"), "r") as f:
        license = publish_string(f.read(), writer=writer)
    context = {"about": about, "license": license}
    return render(request, template, context)
开发者ID:finid,项目名称:drawnby,代码行数:14,代码来源:views.py

示例15: restructured_to_html

def restructured_to_html(s):
    """ Convert RST string to HTML string.
    """

    if not s:
        return s

    html_fragment_writer = Writer()
    html_fragment_writer.translator_class = HTMLFragmentTranslator
    #html = docutils.core.publish_string(s, writer=html_fragment_writer)

    parts = docutils.core.publish_parts(source=s, writer_name='html')

    return parts['body_pre_docinfo']+parts['fragment']
开发者ID:saily,项目名称:plone.app.widgets,代码行数:14,代码来源:rst.py


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