forked from TEALSK12/introduction-to-computer-science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-book.cmd
50 lines (39 loc) · 1.76 KB
/
create-book.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@echo off
setlocal
REM -- Create output directory and set up target output file name
mkdir 2>nul build
set targetBook=intro-book-complete.md
@REM set chrome="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
set edge="C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
REM -- We need the `sed.exe` tool; grab it from the user's Git install.
if not exist "%ProgramFiles%\Git\usr\bin" (
echo ERROR: Unable to find Git install for `sed.exe` tool.
exit /b 1
)
path %ProgramFiles%\Git\usr\bin;%path%
type >%targetBook% SUMMARY.md
REM -- For each file referenced in SUMMARY.md, add it to the target output Markdown file.
REM -- The following sed command extracts the file name from inside parentheses, and reverses path
REM -- slashes.
for /f "delims=" %%t in ('findstr -c:"(" SUMMARY.md ^| sed -e "s/^ *\* *\[.*\](\(.*\))$/\1/"
-e "s/\//\\\/g"') do (
echo %%t
echo.>>%targetBook%
type >>%targetBook% %%t
)
REM -- Normalize line endings to newlines.
move /y >nul %targetBook% %targetBook%.tmp
eol "\n" <%targetBook%.tmp >%targetBook%
del %targetBook%.tmp
@REM -- Create .pdf version of markdown files with no toc
type >"%targetBook%.html" .\markdeep-header.txt
type >>"%targetBook%.html" .\"%targetBook%
type >>"%targetBook%".html .\markdeep-footer-tocstyle-none.txt
@REM --no-margins does not work, had to edit the javascript
@REM %chrome% --headless --print-to-pdf="%%~pf%%~nf.pdf" --no-margins "%%f-pdf.html"
echo %edge% --headless --print-to-pdf="%targetBook%.pdf" --no-margins "%targetBook%.html"
%edge% --headless --print-to-pdf="%CD%\intro-book-complete.pdf" --no-margins "%CD%\%targetBook%.html"
del "%targetBook%.html"
del "%targetBook%"
echo.
echo Finished. You can find the resulting unified book in `intro-book-complete.pdf`.