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


Python nbconvert.RSTExporter方法代码示例

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


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

示例1: convert

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def convert(nbfile):
    basename, _ = os.path.splitext(nbfile)

    meta = {'metadata': {'path': '.'}}
    with open(nbfile, 'r', encoding='utf-8') as nbf:
        nbdata = nbformat.read(nbf, as_version=4, encoding='utf-8')

    runner = ExecutePreprocessor(timeout=600, kernel_name='probscale')
    runner.preprocess(nbdata, meta)

    img_folder = basename + '_files'
    body_raw, images = RSTExporter().from_notebook_node(nbdata)
    body_final = body_raw.replace('.. image:: ', '.. image:: {}/'.format(img_folder))

    with open(basename + '.rst', 'w', encoding='utf-8') as rst_out:
        rst_out.write(body_final)

    for img_name, img_data in images['outputs'].items():
        img_path = os.path.join(img_folder, img_name)
        with open(img_path, 'wb') as img:
            img.write(img_data) 
开发者ID:matplotlib,项目名称:mpl-probscale,代码行数:23,代码来源:make.py

示例2: run

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def run(self):
        import nbconvert
        from os.path import join

        exporter = nbconvert.RSTExporter()
        writer = nbconvert.writers.FilesWriter()

        files = [
            join("examples", "01_simple_usage.ipynb"),
            join("examples", "02_advanced_usage.ipynb"),
            join("examples", "03_preserving_global_structure.ipynb"),
            join("examples", "04_large_data_sets.ipynb"),
        ]
        target_dir = join("docs", "source", "examples")

        for fname in files:
            self.announce(f"Converting {fname}...")
            directory, nb_name = fname.split("/")
            nb_name, _ = nb_name.split(".")
            body, resources = exporter.from_file(fname)
            writer.build_directory = join(target_dir, nb_name)
            writer.write(body, resources, nb_name) 
开发者ID:pavlin-policar,项目名称:openTSNE,代码行数:24,代码来源:setup.py

示例3: parse_notebook_index

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def parse_notebook_index(ntbkpth):
    """
    Parse the top-level notebook index file at `ntbkpth`. Returns a list of
    subdirectories in order of appearance in the index file, and a dict
    mapping subdirectory name to a description.
    """

    # Convert notebook to RST text in string
    rex = RSTExporter()
    rsttxt = rex.from_filename(ntbkpth)[0]
    # Clean up trailing whitespace
    rsttxt = re.sub(r'\n  ', r'', rsttxt, re.M | re.S)
    pthidx = {}
    pthlst = []
    lines = rsttxt.split('\n')
    for l in lines:
        m = re.match(r'^-\s+`([^<]+)\s+<([^>]+).ipynb>`__', l)
        if m:
            # List of subdirectories in order of appearance in index.rst
            pthlst.append(m.group(2))
            # Dict mapping subdirectory name to description
            pthidx[m.group(2)] = m.group(1)
    return pthlst, pthidx 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:25,代码来源:docntbk.py

示例4: notebook_object_to_rst

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def notebook_object_to_rst(ntbk, rpth, rdir, cr=None):
    """
    Convert notebook object `ntbk` to rst document at `rpth`, in directory
    `rdir`. Parameter `cr` is a CrossReferenceLookup object.
    """

    # Pre-process notebook prior to conversion to rst
    if cr is not None:
        preprocess_notebook(ntbk, cr)
    # Convert notebook to rst
    rex = RSTExporter()
    rsttxt, rstres = rex.from_notebook_node(ntbk)
    # Replace `` with ` in sphinx cross-references
    rsttxt = re.sub(r':([^:]+):``(.*?)``', r':\1:`\2`', rsttxt)
    # Insert a cross-reference target at top of file
    reflbl = '.. _example_' + os.path.basename(rdir) + '_' + \
            rpth.replace('-', '_') + ':\n'
    rsttxt = reflbl + rsttxt
    # Write the converted rst to disk
    write_notebook_rst(rsttxt, rstres, rpth, rdir) 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:22,代码来源:docntbk.py

示例5: parse_notebook_index

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def parse_notebook_index(ntbkpth):
    """
    Parse the top-level notebook index file at `ntbkpth`.  Returns a
    list of subdirectories in order of appearance in the index file,
    and a dict mapping subdirectory name to a description.
    """

    # Convert notebook to RST text in string
    rex = RSTExporter()
    rsttxt = rex.from_filename(ntbkpth)[0]
    # Clean up trailing whitespace
    rsttxt = re.sub(r'\n  ', r'', rsttxt, re.M | re.S)
    pthidx = {}
    pthlst = []
    lines = rsttxt.split('\n')
    for l in lines:
        m = re.match(r'^-\s+`([^<]+)\s+<([^>]+).ipynb>`__', l)
        if m:
            # List of subdirectories in order of appearance in index.rst
            pthlst.append(m.group(2))
            # Dict mapping subdirectory name to description
            pthidx[m.group(2)] = m.group(1)
    return pthlst, pthidx 
开发者ID:bwohlberg,项目名称:sporco,代码行数:25,代码来源:docntbk.py

示例6: notebook_object_to_rst

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def notebook_object_to_rst(ntbk, rpth, cr=None):
    """
    Convert notebook object `ntbk` to rst document at `rpth`, in
    directory `rdir`.  Parameter `cr` is a CrossReferenceLookup
    object.
    """

    # Parent directory of file rpth
    rdir = os.path.dirname(rpth)
    # File basename
    rb = os.path.basename(os.path.splitext(rpth)[0])

    # Pre-process notebook prior to conversion to rst
    if cr is not None:
        preprocess_notebook(ntbk, cr)
    # Convert notebook to rst
    rex = RSTExporter()
    rsttxt, rstres = rex.from_notebook_node(ntbk)
    # Replace `` with ` in sphinx cross-references
    rsttxt = re.sub(r':([^:]+):``(.*?)``', r':\1:`\2`', rsttxt)
    # Insert a cross-reference target at top of file
    reflbl = '.. _examples_' + os.path.basename(rdir) + '_' + \
             rb.replace('-', '_') + ':\n\n'
    rsttxt = reflbl + rsttxt
    # Write the converted rst to disk
    write_notebook_rst(rsttxt, rstres, rb, rdir) 
开发者ID:bwohlberg,项目名称:sporco,代码行数:28,代码来源:docntbk.py

示例7: convert_notebook

# 需要导入模块: import nbconvert [as 别名]
# 或者: from nbconvert import RSTExporter [as 别名]
def convert_notebook(nb: notebooknode.NotebookNode, resources: Dict[str, str]):
    nb = _process_nb(nb)
    writer = nbconvert.RSTExporter()
    body, resources = writer.from_notebook_node(nb, resources)
    body = _process_rst(body)
    return body, resources 
开发者ID:d2l-ai,项目名称:d2l-book,代码行数:8,代码来源:rst.py


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