-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
css_tweaks.lua
1128 lines (1116 loc) · 47.9 KB
/
css_tweaks.lua
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[--
CSS tweaks must have the following attributes:
- id: unique ID identifying this tweak, to be stored in settings
- title: menu item title (must not be too long)
- css: stylesheet text to append to external stylesheet
They may have the following optional attributes:
- description: text displayed when holding on menu item
- priority: higher numbers are appended after lower numbers
(if not specified, default to 0)
- conflicts_with: a string with the id of another tweak that should be
disabled when this tweak is enabled, or an array/table of tweaks ids,
or a function(other_id) return true for ids conflicting.
It is also used with "hold / use on all books", unless the
next property is provided.
- global_conflicts_with: similar to 'conflicts_with', but used with
"hold / use on all books". If 'false', no conflict check is done.
]]
local util = require("util")
local _ = require("gettext")
local C_ = _.pgettext
local T = require("ffi/util").template
-- Default globally enabled style tweaks, for new installations
local DEFAULT_GLOBAL_STYLE_TWEAKS = {}
-- Display in-page per-specs footnotes for EPUB and FB2:
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_epub_smaller"] = true
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_fb2"] = true
local CssTweaks = {
DEFAULT_GLOBAL_STYLE_TWEAKS = DEFAULT_GLOBAL_STYLE_TWEAKS,
{
title = C_("Style tweaks category", "Pages and margins"),
{
id = "margin_body_0",
title = _("Ignore publisher page margins"),
description = _("Force page margins to be 0, and may allow KOReader's margin settings to work on books where they would not."),
css = [[body { margin: 0 !important; }]],
},
{
title = _("Horizontal margins"),
{
id = "margin_horizontal_all_0",
conflicts_with = "paragraph_no_horizontal_margin",
title = _("Ignore all horizontal margins"),
css = [[* { margin-left: 0 !important; margin-right: 0 !important; }]],
},
{
id = "padding_horizontal_all_0",
conflicts_with = "paragraph_no_horizontal_padding",
title = _("Ignore all horizontal padding"),
css = [[* { padding-left: 0 !important; padding-right: 0 !important; }]],
separator = true,
},
{
id = "paragraph_no_horizontal_margin",
conflicts_with = "margin_horizontal_all_0",
title = _("Ignore horizontal paragraph margins"),
css = [[p, li { margin-left: 0 !important; margin-right: 0 !important; }]],
},
{
id = "paragraph_no_horizontal_padding",
conflicts_with = "padding_horizontal_all_0",
title = _("Ignore horizontal paragraph padding"),
css = [[p, li { padding-left: 0 !important; padding-right: 0 !important; }]],
},
},
{
title = _("Vertical margins"),
{
id = "margin_vertical_all_0",
conflicts_with = "paragraph_no_vertical_margin",
title = _("Ignore all vertical margins"),
css = [[* { margin-top: 0 !important; margin-bottom: 0 !important; }]],
},
{
id = "padding_vertical_all_0",
conflicts_with = "paragraph_no_vertical_padding",
title = _("Ignore all vertical padding"),
css = [[* { padding-top: 0 !important; padding-bottom: 0 !important; }]],
separator = true,
},
{
id = "paragraph_no_vertical_margin",
conflicts_with = "margin_vertical_all_0",
title = _("Ignore vertical paragraph margins"),
css = [[p, li { margin-top: 0 !important; margin-bottom: 0 !important; }]],
},
{
id = "paragraph_no_vertical_padding",
conflicts_with = "padding_vertical_all_0",
title = _("Ignore vertical paragraph padding"),
css = [[p, li { padding-top: 0 !important; padding-bottom: 0 !important; }]],
},
separator = true,
},
{
title = _("Page breaks and blank pages"),
{
id = "titles_page-break-before_avoid ",
title = _("Avoid blank page on chapter start"),
priority = 2, -- so it can override the one put back by publisher_page-break-before_avoid
css = [[h1, h2, h3 { page-break-before: auto !important; }]],
},
{
id = "docfragment_page-break-before_avoid ",
title = _("Avoid blank page on chapter end"),
priority = 2, -- so it can override the one put back by publisher_page-break-before_avoid
css = [[DocFragment { page-break-before: auto !important; }]],
},
{
id = "publisher_page-breaks_avoid ",
title = _("Avoid publisher page breaks"),
description = _("Disable all publisher page breaks, keeping only KOReader's epub.css ones.\nWhen combined with the two previous tweaks, all page-breaks are disabled."),
css = [[
* { page-break-before: auto !important; page-break-after: auto !important; }
/* put back epub.css page-breaks */
DocFragment { page-break-before: always !important; }
h1 { -cr-only-if: -epub-document; page-break-before: always !important; }
h2, h3 { -cr-only-if: legacy -epub-document; page-break-before: always !important; }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid !important; }
]],
separator = true,
},
{
title = _("New page on headings"),
{
id = "h1_page-break-before_always",
title = _("New page on <H1>"),
css = [[h1 { page-break-before: always !important; }]],
},
{
id = "h2_page-break-before_always",
title = _("New page on <H2>"),
css = [[
h2 { page-break-before: always !important; }
h1 + h2 { page-break-before: avoid !important; }
]],
},
{
id = "h3_page-break-before_always",
title = _("New page on <H3>"),
css = [[
h3 { page-break-before: always !important; }
h1 + h3, h2 + h3 { page-break-before: avoid !important; }
]],
},
{
id = "h4_page-break-before_always",
title = _("New page on <H4>"),
css = [[
h4 { page-break-before: always !important; }
h1 + h4, h2 + h4, h3 + h4 { page-break-before: avoid !important; }
]],
},
{
id = "h5_page-break-before_always",
title = _("New page on <H5>"),
css = [[
h5 { page-break-before: always !important; }
h1 + h5, h2 + h5, h3 + h5, h4 + h5 { page-break-before: avoid !important; }
]],
},
{
id = "h6_page-break-before_always",
title = _("New page on <H6>"),
css = [[
h6 { page-break-before: always !important; }
h1 + h6, h2 + h6, h3 + h6, h4 + h6, h5 + h6 { page-break-before: avoid !important; }
]],
},
},
},
{
title = _("Widows and orphans"),
{
title = _("About widow and orphan lines"),
info_text = _([[
Widows and orphans are lines at the beginning or end of a paragraph, which are left dangling at the top or bottom of a page, separated from the rest of the paragraph.
The first line of a paragraph alone at the bottom of a page is called an orphan line.
The last line of a paragraph alone at the top of a page is called a widow line.
Some people (and publishers) don't like widows and orphans, and can avoid them with CSS rules.
To avoid widows and orphans, some lines have to be pushed to the next page to accompany what would otherwise be widows and orphans. This may leave some blank space at the bottom of the previous page, which might be more disturbing to others.
The default is to allow widows and orphans.
These tweaks allow you to change this behavior, and to override publisher rules.]]),
separator = true,
},
-- To avoid duplicating these 2 tweaks into 2 others for ignoring publisher rules,
-- we apply the rules to BODY without !important (so they can still be overriden
-- by publisher rules applied to BODY), and to DocFragment with !important (so
-- that with "* {widows/orphans: inherit !important}", all elements will inherit
-- from the DocFragment rules.
-- This trick will work with EPUB, but not with single file HTML.
{
id = "widows_orphans_avoid",
conflicts_with = "widows_avoid_orphans_allow",
title = _("Avoid widows and orphans"),
description = _("Avoid widow and orphan lines, allowing for some possible blank space at the bottom of pages."),
css = [[
body { orphans: 2; widows: 2; }
DocFragment {
orphans: 2 !important;
widows: 2 !important;
}
]],
priority = 2, -- so it overrides the * inherit below for DocFragment
},
{
id = "widows_avoid_orphans_allow",
conflicts_with = "widows_orphans_avoid",
title = _("Avoid widows but allow orphans"),
description = _([[
Avoid widow lines, but allow orphan lines, allowing for some possible blank space at the bottom of pages.
Allowing orphans avoids ambiguous blank space at the bottom of a page, which could otherwise be confused with real spacing between paragraphs.]]),
css = [[
body { orphans: 1; widows: 2; }
DocFragment {
orphans: 1 !important;
widows: 2 !important;
}
]],
priority = 2, -- so it overrides the * inherit below for DocFragment
separator = true,
},
{
id = "widows_orphans_all_inherit",
title = _("Ignore publisher orphan and widow rules"),
description = _("Disable orphan and widow rules specified in embedded styles."),
css = [[
* {
orphans: inherit !important;
widows: inherit !important;
}
]],
},
},
},
{
title = _("Text"),
{
title = _("Text alignment"),
{
id = "text_align_most_left",
conflicts_with = { "text_align_all_left", "text_align_most_justify" },
title = _("Left align most text"),
description = _("Enforce left alignment of text in common text elements."),
css = [[body, p, li { text-align: left !important; }]],
priority = 2, -- so it overrides the justify below
},
{
id = "text_align_all_left",
conflicts_with = { "text_align_most_left", "text_align_all_justify" },
title = _("Left align all elements"),
description = _("Enforce left alignment of text in all elements."),
css = [[* { text-align: left !important; }]],
priority = 2, -- so it overrides the justify below
separator = true,
},
{
id = "text_align_most_justify",
conflicts_with = { "text_align_most_left", "text_align_all_justify" },
title = _("Justify most text"),
description = _("Text justification is the default, but it may be overridden by publisher styles. This will re-enable it for most common text elements."),
css = [[
body, p, li { text-align: justify !important; }
pre {
-cr-only-if: txt-document;
text-align: justify !important;
white-space: normal;
}
]],
},
{
id = "text_align_all_justify",
conflicts_with = { "text_align_all_left", "text_align_most_justify" },
title = _("Justify all elements"),
description = _("Text justification is the default, but it may be overridden by publisher styles. This will force justification on all elements, some of which may not be centered as expected."),
css = [[
* { text-align: justify !important; }
pre {
-cr-only-if: txt-document;
white-space: normal;
}
]],
separator = true,
},
{
id = "headings_align_center",
title = _("Center headings"),
css = [[h1, h2, h3, h4, h5, h6 { text-align: center !important; }]],
priority = 4, -- so it overrides the ones above
},
},
{
title = _("Text direction"),
{
title = _("About text direction"),
info_text = _([[
Languages like Arabic or Hebrew use right-to-left writing systems (Right-To-Left or RTL). This doesn't only affect text layout, but also list item bullets and numbers, which have to be put on the right side of the page, as well as tables, where the cells are laid out from right to left.
Usually, the publisher will have set the appropriate tags to enable RTL rendering. But if these are missing, or if you're reading plain text documents, you may want to manually enable RTL with these tweaks.
Note that in the absence of such specifications, KOReader will try to detect the language of each paragraph to set the appropriate rendering per paragraph.
You may also want to enable, in the top menu → Gear → Taps and gestures → Page turns → Invert page turn taps and swipes.]]),
separator = true,
},
{
id = "body_direction_rtl",
conflicts_with = "body_direction_ltr",
title = _("Document direction RTL"),
css = [[body { direction: rtl !important; }]],
priority = 2, -- so it overrides the LTR one below
},
{
id = "text_align_most_right",
conflicts_with = "text_align_all_right",
title = _("Right align most text"),
description = _("Enforce right alignment of text in common text elements."),
-- Includes H1..H6 as this is probably most useful for RTL readers
css = [[body, p, li, h1, h2, h3, h4, h5, h6 { text-align: right !important; }]],
priority = 3, -- so it overrides the ones from Text alignment
},
{
id = "text_align_all_right",
conflicts_with = "text_align_most_right",
title = _("Right align all elements"),
description = _("Enforce right alignment of text in all elements."),
css = [[* { text-align: right !important; }]],
priority = 3, -- so it overrides the ones from Text alignment
separator = true,
},
{
id = "body_direction_ltr",
conflicts_with = "body_direction_rtl",
title = _("Document direction LTR"),
css = [[body { direction: ltr !important; }]],
},
separator = true,
},
{
title = _("Hyphenation, ligatures, ruby"),
{
id = "hyphenate_all_auto",
title = _("Allow hyphenation on all text"),
description = _("Allow hyphenation on all text (except headings), in case the publisher has disabled it."),
css = [[
* { hyphens: auto !important; }
h1, h2, h3, h4, h5, h6 { hyphens: none !important; }
]],
},
{
id = "line_break_cre_loose",
title = _("Ignore publisher line-break restrictions"),
description = _([[
A publisher might use non-breaking spaces and hyphens to avoid line breaking between some words, which is not always necessary and may have been added to make reading easier. This can cause large word spacing on some lines.
Ignoring them will only use KOReader's own typography rules for line breaking.]]),
css = [[* { line-break: -cr-loose; }]],
},
{
id = "ligature_all_no_common_ligature",
title = _("Disable common ligatures"),
description = _("Disable common ligatures, which are enabled by default in 'best' kerning mode."),
-- We don't use !important, as this would stop other font-variant properties
-- from being applied
css = [[
* { font-variant: no-common-ligatures; }
]],
separator = true,
},
{
title = _("Ruby"),
{
title = _("About ruby"),
info_text = _([[
Ruby characters are small glosses on writing in Asian languages (Hanzi, Kanji, Hanja, etc.) to show the pronunciation of the logographs.
These tweaks can help make ruby easier to read or ignore.]]),
separator = true,
},
{
id = "ruby_font_sans_serif",
title = _("Sans-serif font for ruby"),
description = _([[
Use a sans serif font to display all ruby text for a more 'book-like' feeling.
Also force the regular text weight when used with lighter or bolder fonts.]]),
css = [[
rt, rubyBox[T=rt] {
font-family: "Noto Sans CJK SC" !important;
font-weight: 400 !important;
}
]],
},
{
id = "ruby_font_size_larger",
title = _("Larger ruby text size"),
description = _("Increase ruby text size."),
css = [[rt, rubyBox[T=rt] { font-size: 50% !important; }]],
separator = true,
},
{
id = "ruby_most_line_height_larger",
title = _("Larger spacing between ruby lines"),
description = _([[
Increase line spacing of most text, so that lines keep an even spacing whether or not they include ruby.
Further small adjustments can be done with 'Line Spacing' in the bottom menu.]]),
css = [[p, li { line-height: 2 !important; }]],
-- no need for priority, this has higher specificity than lineheight_all_inherit below
},
{
id = "ruby_inline",
title = _("Render ruby content inline"),
description = _("Disable handling of <ruby> tags and render them inline."),
css = [[ruby { display: inline !important; }]],
},
},
separator = true,
},
{
title = _("Font size and families"),
{
id = "font_family_all_inherit",
title = _("Ignore publisher font families"),
description = _("Disable font-family specified in embedded styles."),
css = [[* { font-family: inherit !important; }]],
separator = true,
},
{
id = "font_size_all_inherit",
conflicts_with = "font_size_most_reset",
title = _("Ignore publisher font sizes"),
description = _("Disable font-size specified in embedded styles."),
priority = -1, -- so in-page footnotes smaller can override this
css = [[* { font-size: inherit !important; }]],
},
{
id = "font_size_most_reset",
conflicts_with = "font_size_all_inherit",
title = _("Reset main text font size"),
description = _("Disable font-size set on the main text (keeping possibly larger headings untouched), so that KOReader's font size is used."),
priority = -1, -- so in-page footnotes smaller can override this
css = [[body, p, li, div, blockquote { font-size: 1rem !important; }]],
},
},
{
title = _("Line heights"),
{
id = "lineheight_all_inherit",
title = _("Ignore publisher line heights"),
description = _("Disable line-height specified in embedded styles, and may allow KOReader's line spacing settings to work on books where they would not."),
css = [[* { line-height: inherit !important; }]],
},
{
id = "lineheight_all_normal_strut_confined",
title = _("Enforce steady line heights"),
description = _("Prevent inline content like sub- and superscript from changing their paragraph line height."),
-- strut-confined is among the few cr-hints that are inherited
css = [[body { -cr-hint: strut-confined; }]],
separator = true,
},
{
id = "sub_sup_smaller",
title = _("Smaller sub- and superscript"),
description = _("Prevent sub- and superscript from affecting line-height."),
priority = 5, -- so we can override "font_size_all_inherit"
-- https://friendsofepub.github.io/eBookTricks/
-- https://github.com/koreader/koreader/issues/3923#issuecomment-386510294
css = [[
sup { font-size: 50% !important; vertical-align: super !important; }
sub { font-size: 50% !important; vertical-align: sub !important; }
]],
},
},
},
{
title = _("Paragraphs"),
{
id = "paragraph_web_browser_style",
title = _("Generic web browser paragraph style"),
description = _([[
Display paragraphs as browsers do, in full-block style without indentation or justification, discarding KOReader's book paragraph style.
This might be needed with some documents that expect this style as the default, and only use CSS when it needs to diverge from this default.]]),
priority = -1,
css = [[
p {
text-align: start;
text-indent: 0;
margin-top: 1em;
margin-bottom: 1em;
}
]],
},
{
id = "cjk_tailored",
title = _("Tailor widths and text-indent for CJK"),
description = _([[
Adjust paragraph width and text-indent to be an integer multiple of the font size, so that lines of Chinese and Japanese characters don't need space added between glyphs for text justification.]]),
css = [[ body { -cr-hint: cjk-tailored; }]], -- This hint is inherited
separator = true,
},
{
title = _("Paragraph first-line indentation"),
{
id = "paragraph_no_indent",
title = _("No indentation on first paragraph line"),
description = _("Do not indent the first line of paragraphs."),
css = [[p { text-indent: 0 !important; }]],
separator = true,
},
{
id = "paragraph_indent",
title = _("Indentation on first paragraph line"),
description = _("Indentation on the first line of a paragraph is the default, but it may be overridden by publisher styles. This will force KOReader's defaults on common elements."),
css = [[
p { text-indent: 1.2em !important; }
body, h1, h2, h3, h4, h5, h6, div, li, td, th { text-indent: 0 !important; }
]],
},
{
id = "paragraph_first_no_indent",
title = _("No indentation on first paragraph"),
description = _("Do not indent the first line of the first paragraph of its container. This might be needed to correctly display drop caps, while still having indentation on following paragraphs."),
priority = 2, -- so it can override 'paragraph_indent'
css = [[p:first-child { text-indent: 0 !important; }]],
},
{
id = "paragraph_following_no_indent",
title = _("No indentation on following paragraphs"),
description = _("Do not indent the first line of following paragraphs, but leave the first paragraph of its container untouched."),
priority = 2, -- so it can override 'paragraph_indent'
css = [[p + p { text-indent: 0 !important; }]],
},
},
{
title = _("Spacing between paragraphs"),
{
id = "paragraph_whitespace",
conflicts_with = { "paragraph_whitespace_half", "paragraph_no_whitespace" },
title = _("Spacing between paragraphs"),
description = _("Add a line of whitespace between paragraphs."),
priority = 5, -- Override "Ignore margins and paddings" above
css = [[p + p { margin-top: 1em !important; }]],
},
{
id = "paragraph_whitespace_half",
conflicts_with = { "paragraph_whitespace", "paragraph_no_whitespace" },
title = _("Spacing between paragraphs (half)"),
description = _("Add half a line of whitespace between paragraphs."),
priority = 5,
css = [[p + p { margin-top: .5em !important; }]],
},
{
id = "paragraph_no_whitespace",
conflicts_with = { "paragraph_whitespace", "paragraph_whitespace_half" },
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."),
priority = 5,
css = [[p { margin-top: 0 !important; margin-bottom: 0 !important; }]],
},
},
},
{
title = _("Tables, links, images"),
{
title = _("Tables"),
{
id = "table_full_width",
title = _("Full-width tables"),
description = _("Make table expand to the full width of the page. (Tables with small content now use only the width needed to display that content. This restores the previous behavior.)"),
css = [[table { width: 100% !important; }]],
priority = 2, -- Override next one
},
{
id = "table_td_width_auto",
title = _("Ignore publisher table and cell widths"),
description = _("Ignore table and cells widths specified by the publisher, and let the engine decide the most appropriate widths."),
css = [[table, td, th { width: auto !important; }]],
},
{
id = "table_margin_left_right_auto",
title = _("Center small tables"),
description = _("Horizontally center tables that do not use the full page width."),
css = [[table { margin-left: auto !important; margin-right: auto !important; }]],
priority = 3, -- Override "Pages > Ignore margin and padding"
separator = true,
},
{
id = "td_vertical_align_none",
title = _("Ignore publisher vertical alignment in tables"),
-- Using "vertical-align: top" would vertical-align children text nodes to top.
-- "vertical-align: baseline" has no meaning in table rendering, and is as fine
css = [[td { vertical-align: baseline !important; }]],
},
{
id = "table_row_odd_even",
title = _("Alternate background color of table rows"),
css = [[
tr:nth-child(odd) { background-color: #EEE !important; }
tr:nth-child(even) { background-color: #CCC !important; }
]],
},
{
id = "table_force_border",
title = _("Show borders on all tables"),
css = [[
table, tcaption, tr, th, td { border: black solid 1px; border-collapse: collapse; }
]],
},
},
{
title = _("Links"),
{
id = "a_black",
conflicts_with = "a_blue",
title = _("Links always black"),
css = [[a, a * { color: black !important; }]],
},
{
id = "a_blue",
conflicts_with = "a_black",
title = _("Links always blue"),
css = [[a, a * { color: blue !important; }]],
separator = true,
},
{
id = "a_bold",
conflicts_with = "a_not_bold",
title = _("Links always bold"),
css = [[a, a * { font-weight: bold !important; }]],
},
{
id = "a_not_bold",
conflicts_with = "a_bold",
title = _("Links never bold"),
css = [[a, a * { font-weight: normal !important; }]],
separator = true,
},
{
id = "a_italic",
conflicts_with = "a_not_italic",
title = _("Links always italic"),
css = [[a, a * { font-style: italic !important; }]],
},
{
id = "a_not_italic",
conflicts_with = "a_italic",
title = _("Links never italic"),
css = [[a, a * { font-style: normal !important; }]],
separator = true,
},
{
id = "a_underline",
conflicts_with = "a_not_underline",
title = _("Links always underlined"),
css = [[a[href], a[href] * { text-decoration: underline !important; }]],
-- Have it apply only on real links with a href=, not on anchors
},
{
id = "a_not_underline",
conflicts_with = "a_underline",
title = _("Links never underlined"),
css = [[a, a * { text-decoration: none !important; }]],
},
},
{
title = _("Images"),
{
id = "image_full_width",
title = _("Full-width images"),
description = _("Useful for books containing only images, when they are smaller than your screen. May stretch images in some cases."),
-- This helped me once with a book. Will mess with aspect ratio
-- when images have a style="width: NNpx; heigh: NNpx"
css = [[
img {
text-align: center !important;
text-indent: 0px !important;
display: block !important;
width: 100% !important;
}
]],
},
{
id = "image_valign_middle",
title = _("Vertically center-align images relative to text"),
css = [[img { vertical-align: middle; }]],
},
},
},
{
title = _("Miscellaneous"),
{
title = _("Alternative ToC hints"),
{
title = _("About alternative ToC"),
info_text = _([[
An alternative table of contents can be built via a dedicated option in the "Settings" menu below the "Table of contents" menu entry.
The ToC will be built from document headings <H1> to <H6>. Some of these can be ignored with the tweaks available here.
If the document contains no headings, or all are ignored, the alternative ToC will be built from document fragments and will point to the start of each individual HTML file in the EPUB.
Hints can be set to other non-heading elements in a user style tweak, so they can be used as ToC items. Since this would be quite book-specific, please see the final tweak for some examples.
After applying these tweaks, the alternative ToC needs to be rebuilt by toggling it twice in its menu: once to restore the original ToC, and once to build the alternative ToC again.]]),
separator = true,
},
{
id = "alt_toc_ignore_h_all",
title = _("Ignore all <H1> to <H6>"),
css = [[h1, h2, h3, h4, h5, h6 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h1",
title = _("Ignore <H1>"),
css = [[h1 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h2",
title = _("Ignore <H2>"),
css = [[h2 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h3",
title = _("Ignore <H3>"),
css = [[h3 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h4",
title = _("Ignore <H4>"),
css = [[h4 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h5",
title = _("Ignore <H5>"),
css = [[h5 { -cr-hint: toc-ignore; }]],
},
{
id = "alt_toc_ignore_h6",
title = _("Ignore <H6>"),
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 result in a usable ToC, you can inspect the HTML and look for elements that contain chapter titles. Then you can set hints to their class names.
This is just an example, that will need to be adapted into 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; }
]],
},
separator = true,
},
{
title = _("List items"),
{
id = "ul_li_type_disc",
title = _("Force bullets with unordered lists"),
css = [[ul > li { list-style-type: disc !important; }]],
},
{
id = "ol_li_type_decimal",
title = _("Force decimal numbers with ordered lists"),
css = [[ol > li { list-style-type: decimal !important; }]],
},
},
{
id = "no_pseudo_element_before_after",
title = _("Disable before/after pseudo elements"),
description = _([[Disable generated text from ::before and ::after pseudo elements, usually used to add cosmetic text around some content.]]),
css = [[
*::before { display: none !important; }
*::after { display: none !important; }
]],
separator = true,
},
{
id = "pure_black_and_white",
title = _("Pure black and white"),
description = _([[Enforce black text and borders, and remove backgrounds.]]),
css = [[
* {
color: black !important;
border-color: black !important;
background-color: transparent !important;
background-image: !important;
}
]], -- (This last empty background-image: works for cancelling any previous one
},
},
{
title = _("In-page footnotes"),
{
title = _("In-page FB2 footnotes"),
{
id = "footnote-inpage_fb2",
title = _("In-page FB2 footnotes"),
description = _([[
Show FB2 footnote text at the bottom of pages that contain links to them.]]),
-- Restrict this to FB2 documents, even if we won't probably
-- match in any other kind of document
-- (Last selector avoids title bottom margin from collapsing
-- into the first footnote by substituting it with padding.)
css = [[
body[name="notes"] section {
-cr-only-if: fb2-document;
-cr-hint: footnote-inpage;
margin: 0 !important;
}
body[name="notes"] > section {
-cr-only-if: fb2-document;
font-size: 0.75rem;
}
body[name="notes"] > title {
-cr-only-if: fb2-document;
margin-bottom: 0;
padding-bottom: 0.5em;
}
]],
},
{
id = "footnote-inpage_fb2_comments",
title = _("In-page FB2 endnotes"),
description = _([[
Show FB2 endnote text at the bottom of pages that contain links to them.]]),
css = [[
body[name="comments"] section {
-cr-only-if: fb2-document;
-cr-hint: footnote-inpage;
margin: 0 !important;
}
body[name="comments"] > section {
-cr-only-if: fb2-document;
font-size: 0.85rem;
}
body[name="comments"] > title {
-cr-only-if: fb2-document;
margin-bottom: 0;
padding-bottom: 0.5em;
}
]],
separator = true,
},
{
id = "fb2_footnotes_regular_font_size",
title = _("Keep regular font size"),
description = _([[
FB2 footnotes and endnotes get a smaller font size when displayed in-page. This allows them to be shown with the normal font size.]]),
css = [[
body[name="notes"] > section,
body[name="comments"] > section
{
-cr-only-if: fb2-document;
font-size: 1rem !important;
}
]],
},
separator = true,
},
{
id = "footnote-inpage_epub",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_epub") end,
title = _("In-page EPUB footnotes"),
description = _([[
Show EPUB footnote text at the bottom of pages that contain links to them.
This only works with footnotes that have specific attributes set by the publisher.]]),
-- Restrict this to non-FB2 documents, as FB2 can have <a type="note">
css = [[
*[type~="note"],
*[type~="endnote"],
*[type~="footnote"],
*[type~="rearnote"],
*[role~="doc-note"],
*[role~="doc-endnote"],
*[role~="doc-footnote"],
*[role~="doc-rearnote"]
{
-cr-only-if: -fb2-document;
-cr-hint: footnote-inpage;
margin: 0 !important;
}
]],
},
{
id = "footnote-inpage_epub_smaller",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_epub") end,
title = _("In-page EPUB footnotes (smaller)"),
description = _([[
Show EPUB footnote text at the bottom of pages that contain links to them.
This only works with footnotes that have specific attributes set by the publisher.]]),
-- Restrict this to non-FB2 documents, as FB2 can have <a type="note">
-- and we don't want to have them smaller
css = [[
*[type~="note"],
*[type~="endnote"],
*[type~="footnote"],
*[type~="rearnote"],
*[role~="doc-note"],
*[role~="doc-endnote"],
*[role~="doc-footnote"],
*[role~="doc-rearnote"]
{
-cr-only-if: -fb2-document;
-cr-hint: footnote-inpage;
margin: 0 !important;
font-size: 0.8rem !important;
}
]],
separator = true,
},
{
id = "footnote-inpage_wikipedia",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_wikipedia") end,
title = _("In-page Wikipedia footnotes"),
description = _([[Show footnotes at the bottom of pages in Wikipedia EPUBs.]]),
css = [[
ol.references > li {
-cr-hint: footnote-inpage;
list-style-position: -cr-outside;
margin: 0 !important;
}
/* hide backlinks */
ol.references > li > .noprint { display: none; }
ol.references > li > .mw-cite-backlink { display: none; }
]],
},
{
id = "footnote-inpage_wikipedia_smaller",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_wikipedia") end,
title = _("In-page Wikipedia footnotes (smaller)"),
description = _([[Show footnotes at the bottom of pages in Wikipedia EPUBs.]]),
css = [[
ol.references > li {
-cr-hint: footnote-inpage;
list-style-position: -cr-outside;
margin: 0 !important;
font-size: 0.8rem !important;
}
/* hide backlinks */
ol.references > li > .noprint { display: none; }
ol.references > li > .mw-cite-backlink { display: none; }
]],
separator = true,
},
-- We can add other classic classnames to the 2 following
-- tweaks (except when named 'calibreN', as the N number is
-- usually random across books).
{
id = "footnote-inpage_classic_classnames",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_classic_classnames") end,
title = _("In-page classic classname footnotes"),
description = _([[
Show footnotes with classic classnames at the bottom of pages.
This tweak can be duplicated as a user style tweak when books contain footnotes wrapped with other class names.]]),
css = [[
.footnote, .footnotes, .fn,
.note, .note1, .note2, .note3,
.ntb, .ntb-txt, .ntb-txt-j,
.przypis, .przypis1, /* Polish footnotes */
.voetnoten /* Dutch footnotes */
{
-cr-hint: footnote-inpage;
margin: 0 !important;
}
]],
},
{
id = "footnote-inpage_classic_classnames_smaller",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_classic_classnames") end,
title = _("In-page classic classname footnotes (smaller)"),
description = _([[
Show footnotes with classic classnames at the bottom of pages.
This tweak can be duplicated as a user style tweak when books contain footnotes wrapped with other class names.]]),
css = [[
.footnote, .footnotes, .fn,
.note, .note1, .note2, .note3,
.ntb, .ntb-txt, .ntb-txt-j,
.przypis, .przypis1, /* Polish footnotes */
.voetnoten /* Dutch footnotes */
{
-cr-hint: footnote-inpage;
margin: 0 !important;
font-size: 0.8rem !important;
}
]],
separator = true,
},
-- Next tweaks, with the help of crengine, will apply only to elements that were
-- matched by previous tweaks that have set them the "footnote-inpage" cr-hint,
-- and their children (their content).