def main(): from docutils.core import publish_cmdline, default_description description = ("Generates CodePlex's wiki source from standalone " "reStructuredText sources. " + default_description) publish_cmdline(writer_name='codeplex', description=description, writer=Writer(translator=CodePlexTranslator))
def publish_cmdline_pseudoxml(): """ Main function for pylatest ``rst2pseudoxml`` like command line client. See: ``bin/pylatest2pseudoxml`` script for usage. """ publish_cmdline(writer_name='pseudoxml')
def print_help_message(): sys.stdout.write( '\n\n' 'Use For rst_convert_with_inline:\n' '=================================' '\n\n' 'python rst_convert_with_inline.py [docuitls options] --output <output> file.txt\n' '(--output *must* be provided!)\n' '\n\n' 'An invalid docutils options will cause an error.\n' 'Hold on while the docutils help message prints out...' '\n\n' ) import locale try: locale.setlocale(locale.LC_ALL, '') except: pass argv = ['--help'] from docutils.core import publish_cmdline, default_description # I think this is just for the description at the beginning of the # resulting file description = ('Generates Docutils-native XML from standalone ' 'reStructuredText sources. \n' 'From script resruct_to_tei.py ' + default_description) # invoke the method for coversion publish_cmdline(writer_name='xml', description=description, argv = argv)
def publish_cmdline_man(): """ Main function for pylatest ``rst2html`` like command line client. See: ``bin/pylatest2man`` script for usage. """ publish_cmdline(writer_name='manpage')
def traditional_main(): copy_assets() script_name = os.path.basename(sys.argv[0]) source_dirname = os.path.abspath(os.path.dirname(__file__)) if script_name == 'rst2bootstrap3': template = os.path.join(source_dirname, 'page.tmpl') stylesheet_path = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' # stylesheet_path = 'bootstrap/css/bootstrap.min.css' elif script_name == 'rst2bootstrap-carousel': template = os.path.join(source_dirname, 'page-carousel.tmpl') stylesheet_path = 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css, bootstrap/css/carousel.css' else: template = os.path.join(source_dirname, 'page.tmpl') stylesheet_path = 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css' description = ('Generates (X)HTML bootstrap-ready documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer=HTMLWriter(), writer_name='rst2bootstrap', settings_overrides = { 'strip_comments' : True, 'report_level' : 3, 'doctitle_xform' : False, 'traceback' : True, 'compact_lists' : True, 'toc_backlinks' : False, 'syntax_highlight' : 'short', 'template' : template, 'cloak_email_addresses' : True, 'stylesheet_path' : stylesheet_path, 'embed_stylesheet' : False, 'xml_declaration' : False}, description=description)
def generate_html_report(report_dir, css_file=None): """ Generate an html report from the index.rst file in report_dir """ # Copy the css if css_file is not None: css_dest_path = os.path.join(report_dir, css_file) copyfile(css_file, css_dest_path) else: # use the one in our package_data from pkg_resources import resource_string css_content = resource_string('funkload', 'data/funkload.css') css_dest_path = os.path.join(report_dir, 'funkload.css') with open(css_dest_path, 'w') as css: css.write(css_content) # Build the html html_path = os.path.join(report_dir, 'index.html') rst_path = os.path.join(report_dir, 'index.rst') publish_cmdline(writer_name='html', argv=[ '-t', '--stylesheet-path=' + css_dest_path, rst_path, html_path ]) return html_path
def main(): source = sys.argv[-2] src.plugins.rst_directives.info['source_base_dir'] = os.path.dirname( os.path.normpath(os.path.join(os.getcwd(), source))) destination = sys.argv[-1] writer = CrunchySlideWriter() publish_cmdline(writer=writer, description=description)
def create_userguide(): from docutils.core import publish_cmdline print 'Creating user guide ...' ugdir = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(ugdir, '..', '..', 'src', 'robot')) from version import get_version print 'Version:', get_version() vfile = open(os.path.join(ugdir, 'src', 'version.txt'), 'w') vfile.write('.. |version| replace:: %s\n' % get_version()) vfile.close() description = 'HTML generator for Robot Framework User Guide.' arguments = ''' --time --stylesheet-path=src/userguide.css src/RobotFrameworkUserGuide.txt RobotFrameworkUserGuide.html '''.split('\n')[1:-1] os.chdir(ugdir) publish_cmdline(writer_name='html', description=description, argv=arguments) os.unlink(vfile.name) ugpath = os.path.abspath(arguments[-1]) print ugpath return ugpath, get_version(sep='-')
def run_publisher(reader_name='mpe', writer_name='pseudoxml'): """ Simple wrapper for docutils.core.publish_cmdline """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline from docutils.parsers.rst import Parser import dotmpe.du.ext from dotmpe.du.ext.parser import Inliner description = ('') parser = Parser(inliner=Inliner()) publish_cmdline( parser=parser, reader_name=reader_name, writer_name=writer_name, description=description)
def release_check(version): """Various checks to be done prior a release.""" # --- check README -------------------------------------------------------- from docutils.core import publish_cmdline readme = os.path.join(ROOT, "README.rst") publish_cmdline(argv=["--halt", "2", readme, os.devnull]) # --- version numbers ----------------------------------------------------- rx = r'\n--+\nChanges\n--+\n\nVersion %s\n~~+\n\n' % version if not _contains(readme, rx): abort("bad version in README.rst") setup = os.path.join(ROOT, "setup.py") rx = r'''\nversion *= *['"]%s['"]\n''' % version if not _contains(setup, rx): abort("bad version in setup.py") # --- run tests ----------------------------------------------------------- local("python tests.py") # --- check working copy -------------------------------------------- _needcleanworkingcopy() out = local("hg bookmarks", capture=True) if not re.match(r'\s*\* master\s', out): abort("working copy is not at master bookmark")
def cli_du_publisher(reader_name='mpe', parser=None, parser_name='rst', writer=None, writer_name='pseudoxml', description=''): """ Simple wrapper for ``docutils.core.publish_cmdline``. During development, this should still be working. Shortcomings are it cannot load settings-specs from transforms, or perform processing only (without rendering). It does not handle stores for transforms directly as Nabu does. But, given that transforms could handle storage initialization themselves, and that the Reader/Parser/Writer 'parent' component can hold the settings-specs, should make it fairly easy to port Builder code back to work with docutils. """ # XXX: how far does inline customization go? parser = Parser(inliner=Inliner()) reader_class = comp.get_reader_class(reader_name) parser_class = None if not parser: parser_class = comp.get_parser_class(parser_name) parser = parser_class() if not writer: writer_class = comp.get_writer_class(writer_name) writer = writer_class() publish_cmdline( parser=parser, parser_name=parser_name, reader=reader_class(parser), reader_name=reader_name, writer=writer, writer_name=writer_name, description=description)
def test_output_error_handling(self): # pass IOErrors to calling application if `traceback` is True try: core.publish_cmdline(argv=['data/include.txt', 'nonexisting/path'], settings_overrides={'traceback': True}) except IOError as e: self.assertTrue(isinstance(e, io.OutputError))
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
def main(): from docutils.core import publish_cmdline, default_description description = ('Generates HTML documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer=htmlwriter.Writer(), writer_name='html', description=description)
def create_tooldoc(tool_name): description = "HTML generator for Robot Framework Tool Documentation." stylesheet_path = os.path.join(BASEDIR, "..", "doc", "userguide", "src", "userguide.css") base_path = os.path.join(BASEDIR, tool_name, "doc", tool_name) arguments = ["--time", "--stylesheet-path", [stylesheet_path], base_path + ".txt", base_path + ".html"] publish_cmdline(writer_name="html", description=description, argv=arguments) print os.path.abspath(arguments[-1])
def publish_cmdline_html(): """ Main function for pylatest ``rst2html`` like command line client. See: ``bin/pylatest2html`` script for usage. """ # see: http://docutils.sourceforge.net/docs/api/cmdline-tool.html publish_cmdline(writer_name='html', settings_overrides=HTML_OVERRIDES)
def main(): description = ('Generates (X)HTML bootstrap-ready documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer=HTMLWriter(), writer_name='bootstrap', settings_overrides = { 'stylesheet_path' : 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css'}, description=description)
def run(): from docutils.core import publish_cmdline from docutils.parsers.rst import directives directives.register_directive("code", CodeDirective) writer = RevealJSWriter() publish_cmdline( writer_name="revealjs", writer=writer, settings_overrides={"template": writer.default_template_path} )
def test_input_error_handling(self): # core.publish_cmdline(argv=['nonexisting/path']) # exits with a short message, if `traceback` is False, # pass IOErrors to calling application if `traceback` is True try: core.publish_cmdline(argv=["nonexisting/path"], settings_overrides={"traceback": True}) except IOError, e: self.assertTrue(isinstance(e, io.InputError))
def generateHtml(self): """Ask docutils to convert our rst file into html.""" from docutils.core import publish_cmdline html_path = os.path.join(self.report_dir, "index.html") cmdline = "-t --stylesheet-path=%s %s %s" % (self.css_path, self.rst_path, html_path) cmd_argv = cmdline.split(" ") publish_cmdline(writer_name="html", argv=cmd_argv) self.html_path = html_path
def main(): description = ( 'Generates Beamer-flavoured LaTeX for PDF-based presentations. ' + default_description) publish_cmdline( writer=BeamerWriter(), description=description, settings_overrides={'halt_level': utils.Reporter.ERROR_LEVEL})
def project_docs(ctx): """Generate project documentation. These docs are visible at http://robotframework.org/SeleniumLibrary/. """ args = ['--stylesheet=style.css,extra.css', '--link-stylesheet', 'README.rst', 'docs/index.html'] publish_cmdline(writer_name='html5', argv=args) print(Path(args[-1]).absolute())
def generateHtml(self): """Ask docutils to convert our rst file into html.""" from docutils.core import publish_cmdline html_path = os.path.join(self.report_dir, 'index.html') cmdline = [] if self.quiet: cmdline.append('-q') cmdline.extend(['-t', '--stylesheet-path', self.css_path, self.rst_path, html_path]) publish_cmdline(writer_name='html', argv=cmdline) self.html_path = html_path
def main (): """Generates Beamer-flavoured LaTeX for PDF-based presentations.""" sys.argv.extend([ '--documentclass=beamer', '--documentoptions=t', '--output-encoding=UTF-8', '--output-encoding-error-handler=backslashreplace', '--template=beamer-tmpl.tex', '--no-section-numbering', '--use-latex-docinfo', ]) description = (main.__doc__ + default_description) publish_cmdline(writer=BeamerWriter(), description=description)
def create_html_doc_from_rest(): if not os.path.exists("htmldoc"): os.makedirs("htmldoc") from docutils.core import publish_cmdline, default_description description = ('Generates (X)HTML documents from standalone reStructuredText ' 'sources. ' + default_description) for source in document_source_list: source_path = "doc/%s.txt" % source output_path = "htmldoc/%s.html" % source print "generating... ", output_path publish_cmdline(writer_name='html', description=description, argv=[source_path, output_path])
def run(self): from docutils.core import publish_cmdline from docutils.nodes import raw from docutils.parsers import rst docutils_conf = os.path.join('doc', 'conf', 'docutils.ini') epydoc_conf = os.path.join('doc', 'conf', 'epydoc.ini') try: from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter def code_block(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): lexer = get_lexer_by_name(arguments[0]) html = highlight('\n'.join(content), lexer, HtmlFormatter()) return [raw('', html, format='html')] code_block.arguments = (1, 0, 0) code_block.options = {'language' : rst.directives.unchanged} code_block.content = 1 rst.directives.register_directive('code-block', code_block) except ImportError: print('Pygments not installed, syntax highlighting disabled') for source in glob('doc/*.txt'): dest = os.path.splitext(source)[0] + '.html' if self.force or not os.path.exists(dest) or \ os.path.getmtime(dest) < os.path.getmtime(source): print('building documentation file %s' % dest) publish_cmdline(writer_name='html', argv=['--config=%s' % docutils_conf, source, dest]) if not self.without_apidocs: try: from epydoc import cli old_argv = sys.argv[1:] sys.argv[1:] = [ '--config=%s' % epydoc_conf, '--no-private', # epydoc bug, not read from config '--simple-term', '--verbose' ] cli.cli() sys.argv[1:] = old_argv except ImportError: print('epydoc not installed, skipping API documentation.')
def generate_html(rst_file, html_file, report_dir): """Ask docutils to convert our rst file into html.""" css_content = pkg_resources.resource_string('benchbase', '/templates/benchbase.css') css_dest_path = os.path.join(report_dir, 'benchbase.css') f = open(css_dest_path, 'w') f.write(css_content) f.close() cmdline = "-t --stylesheet-path=%s %s %s" % ('benchbase.css', os.path.basename(rst_file), os.path.basename(html_file)) cmd_argv = cmdline.split(' ') pwd = os.getcwd() os.chdir(report_dir) publish_cmdline(writer_name='html', argv=cmd_argv) os.chdir(pwd)
def main(): try: import locale locale.setlocale(locale.LC_ALL, '') except ImportError: pass desc = default_description + ( ' ' 'For chunked HTML output, <destination> is the filename of the ' 'root chunk. The other chunks are written to the same directory ' 'as the root chunk, but their names are generated from the value ' 'given to the --chunk-basename option. It is an error to use ' 'stdout as <destination> if there is more than one chunk to write.' ) publish_cmdline(writer=ChunkedHTMLWriter(), description=desc)
def create_tutorial(): from docutils.core import publish_cmdline print 'Creating Python Tutorial ...' os.chdir(os.path.dirname(os.path.abspath(__file__))) description = 'Python Tutorial for Robot Framework Library Developers' arguments = ''' --time --stylesheet-path=../userguide/src/userguide.css PythonTutorial.rst PythonTutorial.html '''.split('\n')[1:-1] publish_cmdline(writer_name='html', description=description, argv=arguments) path = arguments[-1] print os.path.abspath(path) return path
def run(self): from docutils.core import publish_cmdline from docutils.nodes import raw from docutils.parsers import rst docutils_conf = os.path.join("doc", "conf", "docutils.ini") epydoc_conf = os.path.join("doc", "conf", "epydoc.ini") try: from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter def code_block(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): lexer = get_lexer_by_name(arguments[0]) html = highlight("\n".join(content), lexer, HtmlFormatter()) return [raw("", html, format="html")] code_block.arguments = (1, 0, 0) code_block.options = {"language": rst.directives.unchanged} code_block.content = 1 rst.directives.register_directive("code-block", code_block) except ImportError: print "Pygments not installed, syntax highlighting disabled" for source in glob("doc/*.txt"): dest = os.path.splitext(source)[0] + ".html" if self.force or not os.path.exists(dest) or os.path.getmtime(dest) < os.path.getmtime(source): print "building documentation file %s" % dest publish_cmdline(writer_name="html", argv=["--config=%s" % docutils_conf, source, dest]) if not self.without_apidocs: try: from epydoc import cli old_argv = sys.argv[1:] sys.argv[1:] = [ "--config=%s" % epydoc_conf, "--no-private", # epydoc bug, not read from config "--simple-term", "--verbose", ] cli.cli() sys.argv[1:] = old_argv except ImportError: print "epydoc not installed, skipping API documentation."
#!C:\Users\cccob\PycharmProjects\NseStocks\venv\Scripts\python.exe # $Id: rst2pseudoxml.py 4564 2006-05-21 20:44:42Z wiemann $ # Author: David Goodger <*****@*****.**> # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing pseudo-XML. """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description description = ('Generates pseudo-XML from standalone reStructuredText ' 'sources (for testing purposes). ' + default_description) publish_cmdline(description=description)
#!/Users/leandro998/PycharmProjects/ibm1/venv/bin/python # Author: # Contact: [email protected] # Copyright: This module has been placed in the public domain. """ man.py ====== This module provides a simple command line interface that uses the man page writer to output from ReStructuredText source. """ import locale try: locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description from docutils.writers import manpage description = ("Generates plain unix manual documents. " + default_description) publish_cmdline(writer=manpage.Writer(), description=description)
#!C:\Users\Ailon\PycharmProjects\Nofi\venv\Scripts\python.exe # $Id: rstpep2html.py 4564 2006-05-21 20:44:42Z wiemann $ # Author: David Goodger <*****@*****.**> # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing HTML from PEP (Python Enhancement Proposal) documents. """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description description = ('Generates (X)HTML from reStructuredText-format PEP files. ' + default_description) publish_cmdline(reader_name='pep', writer_name='pep_html', description=description)
#!c:\users\pranj\docume~1\python\online~1\venv\scripts\python.exe # $Id: rst2xetex.py 7847 2015-03-17 17:30:47Z milde $ # Author: Guenter Milde # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing Lua/XeLaTeX code. """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline description = ('Generates LaTeX documents from standalone reStructuredText ' 'sources for compilation with the Unicode-aware TeX variants ' 'XeLaTeX or LuaLaTeX. ' 'Reads from <source> (default is stdin) and writes to ' '<destination> (default is stdout). See ' '<http://docutils.sourceforge.net/docs/user/latex.html> for ' 'the full reference.') publish_cmdline(writer_name='xetex', description=description)
#!/Users/xuqihang/PycharmProjects/untitled2/venv/bin/python # $Id: rst2html4.py 7994 2016-12-10 17:41:45Z milde $ # Author: David Goodger <*****@*****.**> # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing (X)HTML. The output conforms to XHTML 1.0 transitional and almost to HTML 4.01 transitional (except for closing empty tags). """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description description = ('Generates (X)HTML documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer_name='html4', description=description)