From 3fe6eeff71cf960fdb5a760c8f12ef981d695d7c Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 1 Jan 2019 18:23:10 +0100 Subject: [PATCH] cre: adds in-page footnotes and alternative TOC hints tweaks Adds 2 tweaks to allow displaying footnotes at the bottom of pages, like it's done in some printed books. This will work only with books with correctly specified footnotes with the adequate EPUB attributes, and with Wikipedia EPUBs. But users may be able to activate them for other books with some user style tweaks. Adds a few tweaks to control the build of the alternative TOC. With some user style tweaks, one may be able to build a usable TOC for some badly formatted or converted books. Also fixes 2 paragraphs tweaks. --- base | 2 +- .../apps/reader/modules/readerstyletweak.lua | 20 +++ frontend/ui/data/css_tweaks.lua | 120 +++++++++++++++++- 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/base b/base index d6aa32064..feb4c1d94 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit d6aa3206468123dfa8da68b60a4dd5cbb930906a +Subproject commit feb4c1d943d34214e74670168f4b76b47e0efad0 diff --git a/frontend/apps/reader/modules/readerstyletweak.lua b/frontend/apps/reader/modules/readerstyletweak.lua index db91656cd..50af5919d 100644 --- a/frontend/apps/reader/modules/readerstyletweak.lua +++ b/frontend/apps/reader/modules/readerstyletweak.lua @@ -430,6 +430,26 @@ You can enable individual tweaks on this book with a tap, or view more details a end, separator = item.separator, }) + elseif item.info_text then -- informative menu item + table.insert(menu, { + text = item.title or "### undefined menu title ###", + -- No check box. + -- Show the info text when either tap or hold + keep_menu_open = true, + callback = function() + UIManager:show(InfoMessage:new{ + text = item.info_text, + face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"), + }) + end, + hold_callback = function() + UIManager:show(InfoMessage:new{ + text = item.info_text, + face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"), + }) + end, + separator = item.separator, + }) else table.insert(menu, { text = item.if_empty_menu_title or _("This section is empty"), diff --git a/frontend/ui/data/css_tweaks.lua b/frontend/ui/data/css_tweaks.lua index e8c9aa001..9ab98a9fb 100644 --- a/frontend/ui/data/css_tweaks.lua +++ b/frontend/ui/data/css_tweaks.lua @@ -134,7 +134,7 @@ h1, h2, h3, h4, h5, h6 { hyphens: none !important; } id = "paragraph_no_indent"; title = _("No indentation on first paragraph line"), description = _("Do not indent the first line of paragraphs."), - css = [[p + p { text-indent: 0 !important; }]], + css = [[p { text-indent: 0 !important; }]], }, { id = "paragraph_indent"; @@ -162,7 +162,7 @@ body, h1, h2, h3, h4, h5, h6, div, li, td, th { text-indent: 0 !important; } id = "paragraph_no_whitespace"; title = _("No spacing between paragraphs"), description = _("No whitespace between paragraphs is the default, but it may be overridden by publisher styles. This will re-enable it for paragraphs and list items."), - css = [[p, li { margin: 0 !important; }]], + css = [[p, li { margin-top: 0 !important; margin-bottom: 0 !important; }]], }, }, { @@ -259,6 +259,122 @@ width: 100% !important; }, { title = _("Miscellaneous"), + { + title = _("Alternative TOC hints"), + { + title = _("About alternative TOC"), + smaller_font = true, + info_text = _([[ +An alternative table of content can be built with a long-press on the "Table of content" menu item. + +It will be built from document headings

to

. Some of these can be ignored with the tweaks available here. +If the document contains no heading, or all are ignored, the alternative TOC will be built from the document fragments, to point to the start of each individual HTML file in the EPUB. + +Hints can be set to other non-heading elements, for them to be used as TOC items, in some user style tweaks (as they would be quite book-specific, see last tweak here for some examples). + +After applying these tweaks, it is needed to re-build the alternative TOC by long-pressing "Table of content" twice (once to restore the original TOC, once to build again the alternative TOC).]]), + separator = true, + }, + { + id = "alt_toc_ignore_h_all"; + title = _("Ignore all

to

"), + css = [[h1, h2, h3, h4, h5, h6 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h1"; + title = _("Ignore

"), + css = [[h1 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h2"; + title = _("Ignore

"), + css = [[h2 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h3"; + title = _("Ignore

"), + css = [[h3 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h4"; + title = _("Ignore

"), + css = [[h4 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h5"; + title = _("Ignore

"), + css = [[h5 { -cr-hint: toc-ignore; }]], + }, + { + id = "alt_toc_ignore_h6"; + title = _("Ignore
"), + css = [[h6 { -cr-hint: toc-ignore; }]], + separator = true, + }, + { + id = "alt_toc_level_example"; + title = _("Example of book specific TOC hints"), + description = _([[ +If headings or document fragments do not give a usable TOC, you may inspect the HTML and look for elements that contain chapter titles, and set hints to their class names. +This is just an example, that will need to be adapted in a user style tweak.]]), + css = [[ +.book_n { -cr-hint: toc-level1; } +.part_n { -cr-hint: toc-level2; } +.chap_tit { -cr-hint: toc-level3; } +.chap_tit1 { -cr-hint: toc-level3; } + ]], + }, + }, + { + id = "epub_footnote-inpage"; + title = _("Show EPUB footnotes in pages"), + description = _([[ +Show footnotes text at the bottom of pages that contain links to them. +This only works with footnotes that have specific attributes set by the publisher.]]), + css = [[ +/* EPUB attributes: */ +*[type~="note"], *[type~="footnote"], +*[type~="rearnote"], +*[role~="doc-note"], *[role~="doc-footnote"], +*[role~="doc-rearnote"], +/* Wikipedia EPUBs footnotes: */ +ol.references > li, +/* Classic footnotes class names: */ +.footnote, .note, .note1 +{ + -cr-hint: footnote-inpage; + margin-top: 0 !important; + margin-bottom: 0 !important; +} +/* Wikipedia EPUBs: hide backlinks */ +ol.references > li > .noprint { display: none; } + ]], + }, + { + id = "epub_footnote-inpage_smaller"; + title = _("Show smaller EPUB footnotes in pages"), + description = _([[Decrease font size of footnotes text displayed in pages.]]), + -- Include the whole content of previous style, so toggling this one is enough + css = [[ +/* EPUB attributes: */ +*[type~="note"], *[type~="footnote"], +*[type~="rearnote"], +*[role~="doc-note"], *[role~="doc-footnote"], +*[role~="doc-rearnote"], +/* Wikipedia EPUBs footnotes: */ +ol.references > li, +/* Classic footnotes class names: */ +.footnote, .note, .note1 +{ + -cr-hint: footnote-inpage; + font-size: 80% !important; + margin-top: 0 !important; + margin-bottom: 0 !important; +} +/* Wikipedia EPUBs: hide backlinks */ +ol.references > li > .noprint { display: none; } + ]], + }, { id = "epub_switch_show_case"; title = _("Toggle alternative EPUB content"),