1+ .PHONY : markdown notebook
2+
3+ .DEFAULT : help
4+
5+ # extensions
6+ nb_ext := .ipynb
7+ md_ext := .md
8+
9+ # custom function for converting markdown/notebook files from one format to another
10+ define to_markdown
11+ notedown $(1 ) --to markdown --strip > $(patsubst % .ipynb, % .md, $(1 ) )
12+ endef
13+
14+ define to_notebook
15+ notedown $(1 ) --to notebook --strip > $(patsubst * .md, * .ipynb, $(1 ) )
16+ endef
17+
18+
19+ help :
20+ @echo " make markdown"
21+ @echo " Convert .ipynb file/directory to markdown format."
22+ @echo " e.g. make markdown path=<path to file/dir>"
23+ @echo " run tests using pytest in verbose mode."
24+ @echo " make notebook"
25+ @echo " Convert .md file/directory to notebook format."
26+ @echo " e.g. make notebook path=<path to file/dir>"
27+
28+ # commands for converting a ipynb to markdown
29+ markdown : $(path )
30+ # if there is not suffix in path treat it as a directory
31+ ifeq ($(suffix $(path ) ) ,)
32+ $(foreach f, $(wildcard $(path)**.ipynb), $(call to_markdown, $(f));)
33+ # else treat it as a file and convert only if extension is .ipynb
34+ else ifeq ($(suffix $(path)), $(nb_ext))
35+ $(call to_markdown, $(path))
36+ endif
37+
38+ notebook : $(path )
39+ # if there is not suffix in path treat it as a directory
40+ ifeq ($(suffix $(path ) ) ,)
41+ $(foreach f, $(wildcard $(path)**.ipynb), $(call to_notebook, $(f));)
42+ # else treat it as a file and convert only if extension is .md
43+ else ifeq ($(suffix $(path)), $(md_ext))
44+ $(call to_notebook, $(path))
45+ endif
0 commit comments