Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
d2l-zh
提交
11d92bb6
D
d2l-zh
项目概览
OpenDocCN
/
d2l-zh
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
d2l-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
11d92bb6
编写于
5月 31, 2018
作者:
A
Aston Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
concat book
上级
c854a2a5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
0 deletion
+77
-0
build/ipynb2mdd.sh
build/ipynb2mdd.sh
+36
-0
build/mdd_utils.py
build/mdd_utils.py
+41
-0
未找到文件。
build/ipynb2mdd.sh
浏览文件 @
11d92bb6
MD
=
"mdd"
CH
=
"ch.md"
[
-e
$MD
]
&&
rm
-rf
$MD
mkdir
$MD
# Collect files.
cp
index.md
$MD
/
cp
-R
img
$MD
/
for
f
in
chapter
*
/
*
;
do
...
...
@@ -13,6 +15,7 @@ for f in chapter*/*; do
fi
done
# ipynb to md.
for
f
in
$MD
/chapter
*
/
*
ipynb
;
do
base
=
$(
basename
$f
)
jupyter nbconvert
--to
markdown
$f
--output
"
${
base
%%.*
}
.md"
...
...
@@ -20,14 +23,47 @@ for f in $MD/chapter*/*ipynb; do
done
for
f
in
$MD
/chapter
*
/
*
md
;
do
dir
=
$(
dirname
"
$f
"
)
# Remove inner link.
sed
-i
's/\[\([^]]*\)\]([^\)]*.md)/\1/'
$f
# Refer pdf instead of svg.
sed
-i
s/
\.
svg/
\.
pdf/
$f
# Refer img in the same level.
sed
-i
's/\](..\/img/\](img/'
$f
if
[
"
$f
"
!=
"
$dir
/index.md"
]
;
then
sed
-i
s/#
\
/##
\
/
$f
fi
done
# Convert svg to pdf.
for
f
in
$MD
/img/
*
svg
;
do
rsvg-convert
-f
pdf
-o
"
${
f
%%.*
}
.pdf"
$f
rm
$f
done
# Concat sections in each chapter.
for
f
in
$MD
/chapter
*
/index.md
;
do
sections
=
$(
python
-c
'import mdd_utils; print(mdd_utils.get_sections())'
$f
)
dir
=
$(
dirname
"
$f
"
)
chapter
=
$dir
/
$CH
cat
$f
$sections
>
$chapter
perl
-i
-0777
-pe
's/```eval_rst[^`]+```//ge'
$chapter
done
chapters
=
$(
python
-c
'import mdd_utils; print(mdd_utils.get_chapters())'
$MD
/index.md
)
i
=
1
for
chapter
in
$chapters
;
do
# Move matplotlib plots outside.
mv
$MD
/
$chapter
/
*
_files
$MD
/
# Move ch.md to ../ch0x.md
mv
$MD
/
$chapter
/
$CH
$MD
/ch
$(
printf
%02d
$i
)
.md
rm
-rf
$MD
/
$chapter
i
=
$((
i
+
1
))
done
rm
$MD
/index.md
# zip files.
[
-e
"
$MD
.zip"
]
&&
rm
"
$MD
.zip"
zip
-r
"
$MD
.zip"
$MD
[
-e
$MD
]
&&
rm
-rf
$MD
build/mdd_utils.py
0 → 100644
浏览文件 @
11d92bb6
import
os
import
sys
def
get_sections
():
assert
len
(
sys
.
argv
)
==
2
index_md
=
sys
.
argv
[
1
]
dirname
=
os
.
path
.
dirname
(
index_md
)
start
=
False
sections
=
[]
with
open
(
index_md
)
as
f
:
for
line
in
f
:
line
=
line
.
rstrip
().
lstrip
()
if
':maxdepth:'
in
line
:
start
=
True
continue
elif
line
==
'```'
:
break
if
start
and
len
(
line
)
>
1
:
sections
.
append
(
os
.
path
.
join
(
dirname
,
line
+
'.md'
))
return
' '
.
join
(
sections
)
def
get_chapters
():
assert
len
(
sys
.
argv
)
==
2
index_md
=
sys
.
argv
[
1
]
start
=
False
chapters
=
[]
with
open
(
index_md
)
as
f
:
for
line
in
f
:
line
=
line
.
rstrip
().
lstrip
()
if
':maxdepth:'
in
line
:
start
=
True
continue
elif
line
==
'```'
:
break
if
start
and
len
(
line
)
>
1
:
chapters
.
append
(
line
.
split
(
'/'
)[
0
])
return
' '
.
join
(
chapters
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录