Skip to content

Commit 0381741

Browse files
committed
add the make file
1 parent 8c18770 commit 0381741

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# note2mark
2-
A simple makefile used to convert files/directories of iPython notebooks to markdown format and viseversa
2+
3+
A simple makefile used to convert files/directories of iPython
4+
notebooks to markdown format and vise versa

0 commit comments

Comments
 (0)