Skip to content

Commit f958972

Browse files
committed
md
1 parent 98a68f8 commit f958972

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

tools/ProcessEbook.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
fonts = ebookResources.glob("ubuntumono-*")
2424
cover = ebookResources / "cover" / "cover.jpg"
2525
example_path = Path(r"C:\Users\Bruce\Dropbox\___OnJava\ExtractedExamples")
26+
tablepath = ebookBuildPath / "tables"
2627

2728
def start_marker(tag):
2829
return '[${}$]'.format(tag)
@@ -149,11 +150,10 @@ def cleanup_stripped_html():
149150
Clean up stripped HTML -- final housekeeping
150151
"""
151152
fixes = [
152-
(start_marker("code"), "<code>"),
153-
(end_marker("code"), "</code>"),
153+
(start_marker("code"), "<code>\n"),
154+
(end_marker("code"), "\n</code>"),
154155
(start_marker("blockquote"), "<blockquote>"),
155156
(end_marker("blockquote"), "</blockquote>"),
156-
# (start_marker("br"), "<br/>"),
157157
("</head>", style),
158158
('<table cellspacing="0" cellpadding="0">', '<table align="center">'),
159159
(blank_table_row, fixed_table_row),
@@ -173,7 +173,6 @@ def extract_and_check_tables():
173173
"""
174174
# Extract tables:
175175
print("extracting tables ...")
176-
tablepath = ebookBuildPath / "tables"
177176
if tablepath.exists():
178177
shutil.rmtree(str(tablepath))
179178
time.sleep(1)
@@ -182,23 +181,32 @@ def extract_and_check_tables():
182181
os.chdir(str(tablepath))
183182
with html.with_name(html.stem + "-3.html").open(encoding="utf8") as ht:
184183
doc = ht.read()
185-
doc = doc.replace("<thead>", "")
186-
doc = doc.replace("</thead>", "")
187-
doc = doc.replace("<tbody>", "")
188-
doc = doc.replace("</tbody>", "")
184+
# doc = doc.replace("<thead>", "")
185+
# doc = doc.replace("</thead>", "")
186+
# doc = doc.replace("<tbody>", "")
187+
# doc = doc.replace("</tbody>", "")
189188
tables = re.compile("(<table.*?>)(.*?</table>)", re.DOTALL)
190189
for n, table in enumerate(tables.findall(doc)):
191190
fname = "%02d_table.html" % n
192191
# print(fname)
193192
with (tablepath / fname).open('w', encoding="utf8") as tablefile:
194193
tablefile.write(table[0])
195194
tablefile.write(table[1])
196-
# webbrowser.open(str(tablepath / fname))
197195
pandoc = "pandoc {} -t markdown -o {}.md".format(fname, fname.split('.')[0])
198196
print(pandoc)
199197
os.system(pandoc)
200-
# os.system("ed {}.md".format(fname.split('.')[0]))
201-
# os.system("ed {}".format(tablepath / fname))
198+
199+
@CmdLine('v')
200+
def view_tables():
201+
"""
202+
View tables for checking
203+
"""
204+
os.chdir(str(tablepath))
205+
# for html in Path(".").glob("*.html"):
206+
# webbrowser.open("ed {}".format(html))
207+
for md in Path(".").glob("*.md"):
208+
os.system("ed {}".format(md))
209+
202210

203211

204212
@CmdLine('c')
@@ -265,6 +273,12 @@ def restore_example(matchobj):
265273
restored = restored.replace(standalone_start_old, standalone_start_new)
266274
restored = restored.replace(standalone_end_old, standalone_end_new)
267275

276+
######### This is the new section:
277+
codeblocks = re.compile("```java\n(.*?)\n```")
278+
def dedent(matchobj):
279+
return "```java\n" + textwrap.dedent(matchobj.group(1)) + "\n```"
280+
restored = codeblocks.sub(dedent, restored)
281+
268282
with Path("onjava-2.md").open('w', encoding="utf8") as ojmd2:
269283
ojmd2.write(restored)
270284

@@ -297,6 +311,14 @@ def mdfilename(h1, n):
297311
chp.write("=" * len(p) + "\n")
298312
chp.write(chaps[p])
299313

314+
@CmdLine('w')
315+
def view_in_texts():
316+
"Show all separate .md files in wysiwyg markdown editor"
317+
os.chdir(str(ebookBuildPath))
318+
for md in Path(".").glob("*.md"):
319+
os.system("texts {}".format(md))
320+
321+
300322
@CmdLine('e')
301323
def everything():
302324
# fresh_start()

0 commit comments

Comments
 (0)