My basic method
Software:
Hardware:
Epub -> HTML
pandoc input.epub -t chunkedhtml --chunk-template="%n_%h.html" -o chapters
for f in *.html; do pandoc "$f" -t markdown -o "${f%.html}.md"; done
Prune files... remove unnecessary html files
HTML -> markdown
for file in *.html; do
pandoc "$file" -f html -t markdown --lua-filter=ignore-nav.lua -o "${file%.html}.md"
done
ignore-nav.lua
-- Helper function to check if a class list contains "sitenav"
local function has_sitenav_class(classes)
for _, class in ipairs(classes) do
if class == 'sitenav' then
return true
end
end
return false
end
-- Function to handle block containers (Div, Nav, Section, Header blocks)
function Div (el)
if el.identifier == 'sitenav' or has_sitenav_class(el.classes) then
return {} -- Strip the element completely
end
end
-- Fallback for older Pandoc parsers handling generic block wrappers
function Block (el)
if el.identifier == 'sitenav' or (el.classes and has_sitenav_class(el.classes)) then
return {}
end
end
Join all markdown files together as book.md . Minimal editing may be necessary after joining
markdown -> PDF (decide whether top-level-division is "part" or "chapter")
pandoc metadata.yaml book.md -H header.tex -o output.pdf --toc --pdf-engine=xelatex --top-level-division=part
metadata.yaml
---
title: "book's title"
author: "book's author"
documentclass: book
classoption:
- twoside
- openright
geometry:
- a5paper
- margin=20mm
mainfont: "Palatino Linotype"
---
header.tex
\usepackage{fancyhdr}
\usepackage{tocloft}
\usepackage{atbegshi}
% --- Blank page after title page ---
\AtBeginDocument{
\maketitle
\clearpage
\thispagestyle{empty}
\null
\newpage
}
% --- Page Style Setup ---
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
}
\fancypagestyle{empty}{
\fancyhf{}
}
% --- ToC Styling ---
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftpartleader}{\hfill}
% --- blank page after TOC ---
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
\oldtableofcontents
\cleardoublepage % Using your custom logic below
}
% --- Custom clearing logic ---
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}%
\thispagestyle{empty}%
\newpage
\if@twocolumn\hbox{}\thispagestyle{empty}\newpage\fi
\fi\fi}
\makeatother
% --- Corrected Part command ---
\let\oldpart\part
\renewcommand{\part}{%
\cleardoublepage % Ensures we are on an odd page
\oldpart
}