Make allowances for plots and dataframes in MDX

class HTMLdf[source]

HTMLdf(convert_charrefs=True) :: HTMLParser

HTML Parser that finds a dataframe.

_test_html = """<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>"""

assert HTMLdf.search(_test_html)
assert not HTMLdf.search('<div></div>')

class HTMLEscape[source]

HTMLEscape(*args:Any, **kwargs:Any) :: Preprocessor

Place HTML in a codeblock and surround it with a component.

By default, HTML is incompatible with MDX. We place HTML in a code block and wrap it with the a custom component so that the static site generator can render it.

c, _ = run_preprocessor([HTMLEscape], 'test_files/pandas.ipynb', display_results=True)
assert '<HTMLOutputBlock' in c and '</HTMLOutputBlock>' in c and 'center' not in c
assert '```html\n<div>' in c and '</div>\n```' in c
```python
import pandas as pd
pd.read_csv('https://github.com/outerbounds/.data/raw/main/hospital_readmission.csv').head().iloc[:, :15]
```
    
<HTMLOutputBlock >




```html
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>time_in_hospital</th>
      <th>num_lab_procedures</th>
      <th>num_procedures</th>
      <th>num_medications</th>
      <th>number_outpatient</th>
      <th>number_emergency</th>
      <th>number_inpatient</th>
      <th>number_diagnoses</th>
      <th>race_Caucasian</th>
      <th>race_AfricanAmerican</th>
      <th>gender_Female</th>
      <th>age_[70-80)</th>
      <th>age_[60-70)</th>
      <th>age_[50-60)</th>
      <th>age_[80-90)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>14</td>
      <td>41</td>
      <td>0</td>
      <td>11</td>
      <td>0</td>
      <td>0</td>
      <td>0</td>
      <td>6</td>
      <td>True</td>
      <td>False</td>
      <td>False</td>
      <td>False</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>30</td>
      <td>0</td>
      <td>12</td>
      <td>0</td>
      <td>0</td>
      <td>1</td>
      <td>9</td>
      <td>True</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
    </tr>
    <tr>
      <th>2</th>
      <td>5</td>
      <td>66</td>
      <td>0</td>
      <td>22</td>
      <td>1</td>
      <td>0</td>
      <td>2</td>
      <td>9</td>
      <td>True</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
      <td>False</td>
      <td>False</td>
      <td>True</td>
    </tr>
    <tr>
      <th>3</th>
      <td>3</td>
      <td>63</td>
      <td>0</td>
      <td>8</td>
      <td>0</td>
      <td>0</td>
      <td>0</td>
      <td>8</td>
      <td>True</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>40</td>
      <td>0</td>
      <td>6</td>
      <td>0</td>
      <td>0</td>
      <td>1</td>
      <td>9</td>
      <td>True</td>
      <td>False</td>
      <td>True</td>
      <td>False</td>
      <td>False</td>
      <td>False</td>
      <td>True</td>
    </tr>
  </tbody>
</table>
</div>
```



</HTMLOutputBlock>

class ImageSave[source]

ImageSave(*args:Any, **kwargs:Any) :: Preprocessor

Saves images stored as bytes in notebooks to disk.

class ImagePath[source]

ImagePath(*args:Any, **kwargs:Any) :: Preprocessor

Changes the image path to the location where ImageSave saved the files.

ImageSave and ImagePath must be used together to extract and save images from notebooks and change the path. This is necessary to enable compatiblity with certain types of plotting libraries like matplotlib.

c, _ = run_preprocessor([ImageSave, ImagePath], 'test_files/matplotlib.ipynb', display_results=True)
assert '![png](_matplotlib_files/output_0_1.png)' in c
```python
from matplotlib import pyplot as plt
plt.plot(range(20), range(20))
plt.plot(range(10), range(10))
```

<CodeOutputBlock lang="python">




    [<matplotlib.lines.Line2D at 0x7f9d6922faf0>]




    
![png](_matplotlib_files/output_0_1.png)
    


</CodeOutputBlock>

c, _ = run_preprocessor([ImageSave, ImagePath], 'test_files/altair_jpeg.ipynb')
assert '![svg](_altair_jpeg_files/output_0_0.svg' in c