Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle attachments in notebook cells #36

Merged
merged 3 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pytest_check_links/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ def _html_from_rst(self):
def _items_from_notebook(self):
"""Yield LinkItems from a notebook"""
import nbformat
from nbconvert.filters import markdown2html
from nbconvert.filters.markdown_mistune import IPythonRenderer, MarkdownWithMath

nb = nbformat.read(str(self.fspath), as_version=4)
for cell_num, cell in enumerate(nb.cells):
if cell.cell_type != 'markdown':
continue

html = markdown2html(cell.source)
attachments = cell.get('attachments', {})
renderer = IPythonRenderer(escape=False, attachments=attachments)
html = MarkdownWithMath(renderer=renderer).render(cell.source)
basename = 'Cell %i' % cell_num
for item in links_in_html(basename, self, html):
yield item
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ console_scripts =

[options.extras_require]
cache =
requests-cache
requests-cache~=0.5.2

[pep8]
ignore=E128
Expand Down
2 changes: 1 addition & 1 deletion test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_cli_meta():


@pytest.mark.parametrize("example,rc,expected,unexpected", [
["httpbin.md", 0, [" 6 passed"], [" failed", " warning"]],
["httpbin.md", 0, [" 6 passed"], [" failed"]],
["rst.rst", 1, [" 2 failed", " 7 passed"], [" warning"]]
])
def test_cli_pass(testdir, example, rc, expected, unexpected):
Expand Down