|
@@ -10,8 +10,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
-import sys, os
|
|
|
-import shutil
|
|
|
+import sys, os, shutil
|
|
|
import markdown
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
@@ -19,7 +18,7 @@ import pypandoc
|
|
|
import json
|
|
|
import re
|
|
|
|
|
|
-_BOOKS_SRC = 'book-src'
|
|
|
+_BOOK_SRC = 'book-src'
|
|
|
_BUILD_d = "build"
|
|
|
|
|
|
|
|
@@ -30,7 +29,7 @@ def main():
|
|
|
shutil.rmtree(_BUILD_d, ignore_errors=True)
|
|
|
os.mkdir(_BUILD_d)
|
|
|
|
|
|
- parse_book(_BOOKS_SRC)
|
|
|
+ parse_book(_BOOK_SRC)
|
|
|
|
|
|
|
|
|
def parse_book(book):
|
|
@@ -40,7 +39,7 @@ def parse_book(book):
|
|
|
|
|
|
|
|
|
|
|
|
- sum_p = os.path.join(_BOOKS_SRC, "SUMMARY.md")
|
|
|
+ sum_p = os.path.join(_BOOK_SRC, "SUMMARY.md")
|
|
|
if not os.path.isfile(sum_p):
|
|
|
print("No summary file, can't generate html")
|
|
|
return
|
|
@@ -102,7 +101,7 @@ def generate_html(book, toc):
|
|
|
pagename = toc[p]['file'].replace('.md', '')
|
|
|
|
|
|
|
|
|
- in_f = os.path.join(_BOOKS_SRC, toc[p]['file'])
|
|
|
+ in_f = os.path.join(_BOOK_SRC, toc[p]['file'])
|
|
|
if not os.path.isfile(in_f):
|
|
|
print("Source path is not a file, can't generate html : "+in_f)
|
|
|
continue
|
|
@@ -114,18 +113,42 @@ def generate_html(book, toc):
|
|
|
pdoc_args = ['--mathjax',
|
|
|
'--smart']
|
|
|
|
|
|
+ pdoc_filters = []
|
|
|
+
|
|
|
output = pypandoc.convert_file(in_f,
|
|
|
to='html5',
|
|
|
- format='md',
|
|
|
- extra_args=pdoc_args)
|
|
|
-
|
|
|
+ format='markdown+header_attributes+link_attributes+bracketed_spans',
|
|
|
+ extra_args=pdoc_args,
|
|
|
+ filters=pdoc_filters)
|
|
|
|
|
|
+ output_dom = BeautifulSoup(output, 'html.parser')
|
|
|
+
|
|
|
|
|
|
|
|
|
- story_page = BeautifulSoup('<div class="story-page" id="'+pagename+'"></div>')
|
|
|
- story_page.div.append(BeautifulSoup(output))
|
|
|
+ story_page = BeautifulSoup('<div class="story-page" id="'+pagename+'"></div>', 'html.parser')
|
|
|
+ story_page.div.append(output_dom)
|
|
|
story_dom.append(story_page)
|
|
|
|
|
|
+
|
|
|
+ for img in output_dom.find_all('img'):
|
|
|
+ att_src = re.sub(r"^\/", "", img['src'])
|
|
|
+ src_img = os.path.join(_BOOK_SRC, att_src)
|
|
|
+
|
|
|
+
|
|
|
+ if not os.path.isfile(src_img):
|
|
|
+ print("Source path is not a file, can't copy img : "+src_img)
|
|
|
+ continue
|
|
|
+
|
|
|
+ dest_img = os.path.join(_BUILD_d, att_src)
|
|
|
+
|
|
|
+
|
|
|
+ dest_path, dest_file = os.path.split(dest_img)
|
|
|
+ if not os.path.isdir(dest_path):
|
|
|
+ os.makedirs(dest_path)
|
|
|
+
|
|
|
+ shutil.copyfile(src_img, dest_img)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
book_html_f = os.path.join(_BUILD_d,'stories.html')
|
|
|
with open(book_html_f, 'w') as fp:
|