Skip to content

Commit

Permalink
Merge pull request #1409 from fastai/card-export
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 authored Apr 30, 2024
2 parents f523593 + 7af5102 commit ea20cb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions nbdev/processors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/10_processors.ipynb.

# %% auto 0
__all__ = ['populate_language', 'insert_warning', 'cell_lang', 'add_show_docs', 'mv_exports', 'add_links', 'add_fold',
'strip_ansi', 'strip_hidden_metadata', 'hide_', 'hide_line', 'filter_stream_', 'clean_magics',
'rm_header_dash', 'rm_export', 'clean_show_doc', 'exec_show_docs', 'FilterDefaults']
__all__ = ['CARD_DIV', 'CLOSE_DIV', 'populate_language', 'insert_warning', 'cell_lang', 'add_show_docs', 'mv_exports',
'add_links', 'add_fold', 'strip_ansi', 'strip_hidden_metadata', 'hide_', 'hide_line', 'filter_stream_',
'clean_magics', 'rm_header_dash', 'rm_export', 'clean_show_doc', 'exec_show_docs', 'FilterDefaults']

# %% ../nbs/api/10_processors.ipynb 2
import ast
Expand Down Expand Up @@ -83,13 +83,19 @@ def begin(self):
nb.has_docs_ = shown_docs or exports

# %% ../nbs/api/10_processors.ipynb 17
CARD_DIV = mk_cell('::: {.py-2 .px-3 .mb-4 fig-align="center" .border .rounded .shadow-sm}', cell_type='markdown')
CLOSE_DIV = mk_cell(':::', cell_type='markdown')

class mv_exports(Processor):
"Move `exports` cells to after the `show_doc`"
def begin(self):
cells = self.nb.cells
exports = L(c for c in cells if c.cell_type=='code' and 'exports' in c.directives_)
for cell in reversed(exports):
if getattr(cells[cell.idx_+1], 'has_sd', 0): cells.insert(cell.idx_+1, cells.pop(cell.idx_))
if getattr(cells[cell.idx_+1], 'has_sd', 0):
cells.insert(cell.idx_+1, cells.pop(cell.idx_))
cells.insert(cell.idx_, CARD_DIV)
cells.insert(cell.idx_+3, CLOSE_DIV)

# %% ../nbs/api/10_processors.ipynb 18
_re_defaultexp = re.compile(r'^\s*#\|\s*default_exp\s+(\S+)', flags=re.MULTILINE)
Expand Down
10 changes: 8 additions & 2 deletions nbs/api/10_processors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,19 @@
"outputs": [],
"source": [
"#| export\n",
"CARD_DIV = mk_cell('::: {.py-2 .px-3 .mb-4 fig-align=\"center\" .border .rounded .shadow-sm}', cell_type='markdown')\n",
"CLOSE_DIV = mk_cell(':::', cell_type='markdown')\n",
"\n",
"class mv_exports(Processor):\n",
" \"Move `exports` cells to after the `show_doc`\"\n",
" def begin(self):\n",
" cells = self.nb.cells\n",
" exports = L(c for c in cells if c.cell_type=='code' and 'exports' in c.directives_)\n",
" for cell in reversed(exports):\n",
" if getattr(cells[cell.idx_+1], 'has_sd', 0): cells.insert(cell.idx_+1, cells.pop(cell.idx_))"
" if getattr(cells[cell.idx_+1], 'has_sd', 0): \n",
" cells.insert(cell.idx_+1, cells.pop(cell.idx_))\n",
" cells.insert(cell.idx_, CARD_DIV)\n",
" cells.insert(cell.idx_+3, CLOSE_DIV)"
]
},
{
Expand Down Expand Up @@ -744,7 +750,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
}
Expand Down

0 comments on commit ea20cb7

Please sign in to comment.