Skip to content

Commit

Permalink
Handle attachments in notebook cells (#36)
Browse files Browse the repository at this point in the history
* Handle attachments in notebook cells

* Pin requests-cache

* Do not check for warnings in tests
  • Loading branch information
jtpio authored Jul 6, 2021
1 parent af5db12 commit 717c99e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
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

0 comments on commit 717c99e

Please sign in to comment.