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


Python v4.new_markdown_cell方法代码示例

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


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

示例1: py2ipynb

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def py2ipynb(input, output, cellmark_style, other_ignores=[]):
    """Converts a .py file to a V.4 .ipynb notebook usiing `parsePy` function

    :param input: Input .py filename
    :param output: Output .ipynb filename
    :param cellmark_style: Determines cell marker based on IDE, see parsePy documentation for values
    :param other_ignores: Other lines to ignore
    """
    # Create the code cells by parsing the file in input
    cells = []
    for c in parsePy(input, cellmark_style, other_ignores):
        codecell, metadata, code = c
        cell = new_code_cell(source=code, metadata=metadata) if codecell else new_markdown_cell(source=code, metadata=metadata)
        cells.append(cell)

    # This creates a V4 Notebook with the code cells extracted above
    nb0 = new_notebook(cells=cells,
                       metadata={'language': 'python',})

    with codecs.open(output, encoding='utf-8', mode='w') as f:
        nbformat.write(nb0, f, 4) 
开发者ID:gatsoulis,项目名称:py2ipynb,代码行数:23,代码来源:py2ipynb.py

示例2: test_add_sec_label

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def test_add_sec_label():
    sample = ("# Foo\n"
              "\n"
              "Bar")
    res = latex.add_sec_label(new_markdown_cell(sample), '05-test')
    assert len(res) == 3
    assert res[0].cell_type == 'markdown'
    assert res[0].source.strip() == '# Foo'
    assert res[1].cell_type == 'raw'
    assert res[1].source.strip() == '\\label{sec:05-test}'
    assert res[2].cell_type == 'markdown'

    sample = ("Foo\n"
              "===\n")
    res = latex.add_sec_label(new_markdown_cell(sample), '05-test')
    assert len(res) == 2
    assert res[0].cell_type == 'markdown'
    assert res[0].source.strip() == 'Foo\n==='
    assert res[1].cell_type == 'raw'
    assert res[1].source.strip() == '\\label{sec:05-test}' 
开发者ID:takluyver,项目名称:bookbook,代码行数:22,代码来源:test_latex.py

示例3: create_regular_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_regular_cell(source, cell_type, schema_version=SCHEMA_VERSION):
    if cell_type == "markdown":
        cell = new_markdown_cell(source=source)
    elif cell_type == "code":
        cell = new_code_cell(source=source)
    else:
        raise ValueError("invalid cell type: {}".format(cell_type))

    cell.metadata.nbgrader = {}
    cell.metadata.nbgrader["grade"] = False
    cell.metadata.nbgrader["grade_id"] = ""
    cell.metadata.nbgrader["points"] = 0.0
    cell.metadata.nbgrader["solution"] = False
    cell.metadata.nbgrader["task"] = False
    cell.metadata.nbgrader["locked"] = False
    cell.metadata.nbgrader["schema_version"] = schema_version

    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:20,代码来源:__init__.py

示例4: create_grade_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_grade_cell(source, cell_type, grade_id, points, schema_version=SCHEMA_VERSION):
    if cell_type == "markdown":
        cell = new_markdown_cell(source=source)
    elif cell_type == "code":
        cell = new_code_cell(source=source)
    else:
        raise ValueError("invalid cell type: {}".format(cell_type))

    cell.metadata.nbgrader = {}
    cell.metadata.nbgrader["grade"] = True
    cell.metadata.nbgrader["grade_id"] = grade_id
    cell.metadata.nbgrader["points"] = points
    cell.metadata.nbgrader["solution"] = False
    cell.metadata.nbgrader["task"] = False
    cell.metadata.nbgrader["locked"] = False
    cell.metadata.nbgrader["schema_version"] = schema_version

    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:20,代码来源:__init__.py

示例5: create_solution_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_solution_cell(source, cell_type, grade_id, schema_version=SCHEMA_VERSION):
    if cell_type == "markdown":
        cell = new_markdown_cell(source=source)
    elif cell_type == "code":
        cell = new_code_cell(source=source)
    else:
        raise ValueError("invalid cell type: {}".format(cell_type))

    cell.metadata.nbgrader = {}
    cell.metadata.nbgrader["solution"] = True
    cell.metadata.nbgrader["grade_id"] = grade_id
    cell.metadata.nbgrader["grade"] = False
    cell.metadata.nbgrader["task"] = False
    cell.metadata.nbgrader["locked"] = False
    cell.metadata.nbgrader["schema_version"] = schema_version

    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:__init__.py

示例6: create_locked_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_locked_cell(source, cell_type, grade_id, schema_version=SCHEMA_VERSION):
    if cell_type == "markdown":
        cell = new_markdown_cell(source=source)
    elif cell_type == "code":
        cell = new_code_cell(source=source)
    else:
        raise ValueError("invalid cell type: {}".format(cell_type))

    cell.metadata.nbgrader = {}
    cell.metadata.nbgrader["locked"] = True
    cell.metadata.nbgrader["grade_id"] = grade_id
    cell.metadata.nbgrader["solution"] = False
    cell.metadata.nbgrader["task"] = False
    cell.metadata.nbgrader["grade"] = False
    cell.metadata.nbgrader["schema_version"] = schema_version

    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:__init__.py

示例7: create_task_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_task_cell(source, cell_type, grade_id, points, schema_version=SCHEMA_VERSION):
    if cell_type == "markdown":
        cell = new_markdown_cell(source=source)
    elif cell_type == "code":
        cell = new_code_cell(source=source)
    else:
        raise ValueError("invalid cell type: {}".format(cell_type))

    cell.metadata.nbgrader = {}
    cell.metadata.nbgrader["solution"] = False
    cell.metadata.nbgrader["grade"] = False
    cell.metadata.nbgrader["task"] = True
    cell.metadata.nbgrader["grade_id"] = grade_id
    cell.metadata.nbgrader["points"] = points
    cell.metadata.nbgrader["locked"] = True
    cell.metadata.nbgrader["schema_version"] = schema_version

    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:20,代码来源:__init__.py

示例8: markdown_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def markdown_cell(group):
    # Two spaces for markdown line break
    source = '  \n'.join(group).strip()
    return new_markdown_cell(source) 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:6,代码来源:to_ipynb.py

示例9: test_markdown

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def test_markdown():
    nb = Notebook(new_notebook(cells=[new_markdown_cell("this is a test.")]))
    assert nb.scraps == collections.OrderedDict() 
开发者ID:nteract,项目名称:scrapbook,代码行数:5,代码来源:test_notebooks.py

示例10: to_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def to_cell(self):
        return nbv.new_markdown_cell(self._text) 
开发者ID:andrewcooke,项目名称:choochoo,代码行数:4,代码来源:load.py

示例11: add_sec_label

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def add_sec_label(cell: NotebookNode, nbname) -> Sequence[NotebookNode]:
    """Adds a Latex \\label{} under the chapter heading.

    This takes the first cell of a notebook, and expects it to be a Markdown
    cell starting with a level 1 heading. It inserts a label with the notebook
    name just underneath this heading.
    """
    assert cell.cell_type == 'markdown', cell.cell_type
    lines = cell.source.splitlines()
    if lines[0].startswith('# '):
        header_lines = 1
    elif len(lines) > 1 and lines[1].startswith('==='):
        header_lines = 2
    else:
        raise NoHeader

    header = '\n'.join(lines[:header_lines])
    intro_remainder = '\n'.join(lines[header_lines:]).strip()
    res = [
        new_markdown_cell(header),
        new_latex_cell('\label{sec:%s}' % nbname)
    ]
    res[0].metadata = cell.metadata
    if intro_remainder:
        res.append(new_markdown_cell(intro_remainder))
    return res 
开发者ID:takluyver,项目名称:bookbook,代码行数:28,代码来源:latex.py

示例12: create_text_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_markdown_cell [as 别名]
def create_text_cell():
    source = "this is the answer!\n"
    cell = new_markdown_cell(source=source)
    return cell 
开发者ID:jupyter,项目名称:nbgrader,代码行数:6,代码来源:__init__.py


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