Skip to content

Commit 17088e6

Browse files
committed
Working
1 parent 708b7f7 commit 17088e6

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

tools/ProcessEbook.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def cleanup_stripped_html():
151151
(end_marker("code"), "</code>"),
152152
(start_marker("blockquote"), "<blockquote>"),
153153
(end_marker("blockquote"), "</blockquote>"),
154-
(start_marker("br"), "<br/>")
154+
# (start_marker("br"), "<br/>"),
155155
("</head>", style),
156156
('<table cellspacing="0" cellpadding="0">', '<table align="center">'),
157157
(blank_table_row, fixed_table_row),
@@ -182,7 +182,8 @@ def convert_to_html():
182182
def convert_to_markdown():
183183
"Convert to markdown"
184184
os.chdir(str(ebookBuildPath))
185-
cmd = "pandoc {} -f html -t markdown -o {}.md --toc --toc-depth=2".format("onjava-3.html", "onjava")
185+
# cmd = "pandoc {} -f html -t markdown -o {}.md --toc --toc-depth=2".format("onjava-3.html", "onjava")
186+
cmd = "pandoc {} -f html -t markdown -o {}.md".format("onjava-3.html", "onjava")
186187
print(cmd)
187188
os.system(cmd)
188189

@@ -191,11 +192,23 @@ def convert_to_markdown():
191192
\
192193
<div>"""
193194

195+
standalone_start_old = r"""
196+
` """
197+
standalone_start_new = r"""
198+
```java
199+
"""
200+
standalone_end_old = r"""
201+
`
202+
"""
203+
standalone_end_new = r"""
204+
```
205+
"""
206+
194207
@CmdLine('s')
195208
def reconstruct_source_code_files():
196209
"Reconstruct source code from examples, make sure you attach output first"
197210
os.chdir(str(ebookBuildPath))
198-
example = re.compile(r"\` //: (.*?\.(java|txt|cpp|py|prop))(.*?)///:~\`", re.DOTALL)
211+
example = re.compile(r"` //: (.*?\.(java|txt|cpp|py|prop))(.*?)///:~.*?`", re.DOTALL)
199212

200213
def restore_example(matchobj):
201214
ename = matchobj.group(1)
@@ -210,8 +223,11 @@ def restore_example(matchobj):
210223

211224
with Path("onjava.md").open(encoding="utf8", errors="ignore") as md:
212225
restored = example.sub(restore_example, md.read())
226+
restored = restored.replace(start_marker("br"), "\n")
213227

214228
restored = restored.replace(silly, "")
229+
restored = restored.replace(standalone_start_old, standalone_start_new)
230+
restored = restored.replace(standalone_end_old, standalone_end_new)
215231

216232
with Path("onjava-2.md").open('w', encoding="utf8") as ojmd2:
217233
ojmd2.write(restored)
@@ -245,5 +261,12 @@ def mdfilename(h1, n):
245261
chp.write("=" * len(p) + "\n")
246262
chp.write(chaps[p])
247263

264+
@CmdLine('e')
265+
def everything():
266+
fresh_start()
267+
convert_to_html()
268+
convert_to_markdown()
269+
reconstruct_source_code_files()
270+
break_up_markdown_file()
248271

249272
if __name__ == '__main__': CmdLine.run()

0 commit comments

Comments
 (0)