本文整理匯總了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)
示例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}'
示例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
示例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
示例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
示例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
示例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
示例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)
示例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()
示例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)
示例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
示例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