當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。