Repository: jupyterlab/pytest-check-links (language: python)

Issue:
AssertionError: missing attachment in notebook
<!-- Thank you for contributing. These HTML comments will not render in the issue, but you can delete them once you've read them if you prefer! -->

<!-- Before creating a new issue:
* Search for relevant issues
* Follow the issue reporting guidelines:
https://jupyterlab.readthedocs.io/en/latest/getting_started/issue.html
-->

## Description

It looks like `pytest-check-links` errors on notebook files with attachments.

## Reproduce

Using this test notebook:

```json
{
 "cells": [
  {
   "attachments": {
    "image.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAbmAAAG5gFFAfPZAAAAB3RJTUUH3gwMFiIaKb3l3gAACBFJREFUeNrtW31sVWcZ/z23pSKtCYqXjW3R4DqEdpNVgzaKAXUE3ew2xRLHRKMuk3WajbQ6DW65M4jgGIiLZP5lxGmyofhBl8lWsMBWKBPWdC4zHRAj8lFoN6al68c9z88/7rnnnnPvOee+5/Z2O8a+bdP3vufet+f5Pc/v+TpvgakxNabG//OQydz85p90XDY+xuUk5wNIUpkkOZtkEqqzSU4nOUhiQKEDCYuDCgworAFR7R2aNv3Jo6mm4f8pAJpTL1UN1/S3KbEC1AaQQhLZHzhzLVzT3DV7bVjJXemE1da9YVV/7AG4aev+BbD0NySvR56QXuELBPV5n+uzyguk9bVDD32pPbYAND/xRMXwP5N/B1nLPC0bCVnwvoLPjhPaePih1cfKCUCiXBsNn0re5hZeiQNQ3CLUW0gccAsJHzAM1qZB8aulqV9MLycAleXaiMpPwhGeF6tGRj6z23ZgTandHW9UJE6DnOlvCcZrdcP/TtwAoD12FgBgDkEABIhdu13ee3eqaRjkrkINI0Tr8LcExYdjSQFSk9kbBazFIMV1UUguDtJwNFpYC2NJASEqNae9ecs3PPVg5Y/atwLAyA/a1xKcB9tC3F9AJAoAirfFEgDNi+tK3D+altaMRXBGqIZdYHgA8rMEEPF0gv5mO6O4k0Ow1vPsxfYv8QQgnMOYaAj0WEtMLUB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OTpTUNhlRAELOBEx9g8e2fLFPlBvBfFOI62jSP5uWuQUpYTrtaY7jSygSiteGUeaAMUTAgMooGS3Ldsic5PP12oE7Yc6ukBKDKOm8rCRBexJffpVwudxNgILnJecHp1xt0Z9tGYFa7/A0Rns4/mb/L3M7Rwx7gfQ4mPGBY4y23mtit6t8RGGJYASBm5GWTsiNUQqx8Z2guw3a26qYbcmhMOBaWxEUPKtIzP6cG1XRyQAOjatfJ3AnSb5QGGSw4AbNIjZxUzZNPa7b0oSLSLQyF3hA+tX/EmATUXzAc/eNNRaEKcNQQkD1xPT5adSf3Bvyc8FDmxo/q5SP0vwdGA+oDbcWmJ4oiEoRSnhMcX/gPJ1qX/2ngk/GeradNuTAK5afN+O94xbFQ1UzrFzxsy38IWSw5xaf0CCezL3rs6enrrASZzUaVhk5pbrtWOBQ6hAD/525cuycqf1ph6T45lv9oBcaFiaZo+7fE+u3rkRb+EoHwCn78oA4CtoIChDIC8FJjlgTuPZfUT3Sd3BVTE8IBGlNHXmNaDWRCpxFe+K6QkRg8ZEaWms6zpR7uPN5QXAvDQt5icswPojyFkAl3jDW3mPiJQPAFg5jU6syBkDWS/1+48DAF/82DIInnYH93ICUL6ToqoDZYn90N9JfedxR9zrnnsGwAsuCxiMJwBId0V6UhMISnrUp6YadTGgO6YWgA7zfD4s88NKHvt40pG3d/GHIGjM3TEPxjIPAACebP45qHdG6+W53+eMIYA7IDIrc+YH0+x+3Tap77o3pk4QwDTci1F9P6hLojU4Cxx7DSAtect/xvmqtthmgjmKphLoO7YWYq0HdXqRXr3JlpcAuQ/1z24XKfdB2Un8rzGevPkyjI6sBvhVwD5wka/98NEL4S+RxmOysOt87GuBUDBe/tQsaLoOYB2gCzK/UQciCeAiBK9B0Q/weQgOoVIOyfznzmBqTI2pMTUmefwX5Mz8p5zVbn8AAAAASUVORK5CYII="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Attachment:\n",
    "![image.png](attachment:image.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
```

That renders like this in JupyterLab:

![image](https://user-images.githubusercontent.com/591645/124437986-ed7a6400-dd77-11eb-99d6-abd9a3c558aa.png)

Running `pytest-check-links example.ipynb` gives the following error:

```
===================================================================================================== short test summary info =====================================================================================================
ERROR example.ipynb - AssertionError: missing attachment: image.png
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================================== 2 warnings, 1 error in 0.31s ===================================================================================================
```

## Expected behavior

The check should pass.

## Context

Haven't looked more in details, but maybe this is more of a `nbconvert` issue since the assert is raised here? https://github.com/jupyter/nbconvert/blob/90b3911ed9b155e8ca3680ca4581d9344aa10be0/nbconvert/filters/markdown_mistune.py#L163


Discussion / hints:
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
<br>If you haven't done so already, check out [Jupyter's Code of Conduct](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md). Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
![welcome](https://raw.githubusercontent.com/jupyterlab/.github/master/images/welcome.jpg)
You can meet the other [Jovyans](https://jupyter.readthedocs.io/en/latest/community/content-community.html?highlight=jovyan#what-is-a-jovyan) by joining our [Discourse forum](http://discourse.jupyter.org/). There is also an intro thread there where you can stop by and say Hi! :wave:
<br>Welcome to the Jupyter community! :tada:


Fix patch:
diff --git a/setup.cfg b/setup.cfg
index 7cecff3..31ff041 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -42,7 +42,7 @@ console_scripts =
 
 [options.extras_require]
 cache =
-    requests-cache
+    requests-cache~=0.5.2
 
 [pep8]
 ignore=E128


Test patch:
diff --git a/pytest_check_links/plugin.py b/pytest_check_links/plugin.py
index d9c71a5..af27aad 100644
--- a/pytest_check_links/plugin.py
+++ b/pytest_check_links/plugin.py
@@ -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
diff --git a/test/test_cli.py b/test/test_cli.py
index 099c6e6..bc06b71 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -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):