diff --git a/frontend/ui/wikipedia.lua b/frontend/ui/wikipedia.lua
index ec3a19abb..b33e27d4f 100644
--- a/frontend/ui/wikipedia.lua
+++ b/frontend/ui/wikipedia.lua
@@ -945,6 +945,24 @@ hr.koreaderwikifrontpage {
margin-right: 20%;
margin-bottom: 1.2em;
}
+/* Have these HR get the same margins and position as our H2 */
+hr.koreaderwikitocstart {
+ page-break-before: always;
+ font-size: 140%;
+ margin: 0.7em 30% 1.5em;
+ height: 0.22em;
+ border: none;
+ background-color: black;
+}
+hr.koreaderwikitocend {
+ page-break-before: avoid;
+ page-break-after: always;
+ font-size: 140%;
+ margin: 1.2em 30% 0;
+ height: 0.22em;
+ border: none;
+ background-color: black;
+}
/* So many links, make them look like normal text except for underline */
a {
@@ -1246,6 +1264,58 @@ table {
]])
epub:add("OEBPS/toc.ncx", table.concat(toc_ncx_parts))
+ -- ----------------------------------------------------------------
+ -- HTML table of content
+ -- We used to have it in the HTML we got from Wikipedia, but we no longer do.
+ -- So, build it from the 'sections' we got from the API.
+ local toc_html_parts = {}
+ -- Unfortunately, we don't and can't get any localized "Contents" or "Sommaire" to use
+ -- as a heading. So, use some
at start and at end to make this HTML ToC stand out.
+ table.insert(toc_html_parts, '
\n')
+ cur_level = 0
+ for isec, s in ipairs(sections) do
+ -- Some chars in headings are converted to html entities in the
+ -- wikipedia-generated HTML. We need to do the same in TOC links
+ -- for the links to be valid.
+ local s_anchor = s.anchor:gsub("&", "&"):gsub('"', """):gsub(">", ">"):gsub("<", "<")
+ local s_title = string.format("%s %s", s.number, s.line)
+ local s_level = s.toclevel
+ if s_level == cur_level then
+ table.insert(toc_html_parts, "")
+ elseif s_level < cur_level then
+ table.insert(toc_html_parts, "")
+ while cur_level > s_level do
+ cur_level = cur_level - 1
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, "")
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, "")
+ end
+ else -- s_level > cur_level
+ while cur_level < s_level do
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, "")
+ cur_level = cur_level + 1
+ end
+ end
+ cur_level = s_level
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, string.format([[- ]], s_anchor, s_title))
+ end
+ -- close nested
+ table.insert(toc_html_parts, "
")
+ while cur_level > 0 do
+ cur_level = cur_level - 1
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, "
")
+ if cur_level > 0 then
+ table.insert(toc_html_parts, "\n"..(" "):rep(cur_level))
+ table.insert(toc_html_parts, "")
+ end
+ end
+ table.insert(toc_html_parts, '
\n')
+ html = html:gsub([[]], table.concat(toc_html_parts))
+
-- ----------------------------------------------------------------
-- OEBPS/content.html
-- Some small fixes to Wikipedia HTML to make crengine and the user happier