From a0463fc85bcc7b54b74f0d5dea70a8bef20da6a4 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 28 Feb 2025 20:00:54 -0600 Subject: [PATCH] base_xenforoforum: Add details_spoiler option for #1165 --- calibre-plugin/plugin-defaults.ini | 17 ++++++++++++++++- .../adapters/base_xenforoforum_adapter.py | 10 ++++++++++ fanficfare/configurable.py | 2 ++ fanficfare/defaults.ini | 17 ++++++++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index 49f68cc6..19fc9abe 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -907,8 +907,17 @@ always_use_forumtags:false ## spoiler blocks with the original spoiler button text as a label ## using fieldset and legend HTML tags. For a simple box, see the ## add_to_output_css example for [base_xenforoforum:epub] below. +## remove_spoilers overrides legend_spoilers #legend_spoilers:false +## This option if uncommented and set true, will change the tags +## around spoiler blocks to a
tag with tag +## containing the original spoiler button text. For a simple line +## box, see the add_to_output_css example for [base_xenforoforum:epub] +## below. +## remove_spoilers and legend_spoilers override details +#details_spoilers:false + ## True by built-in default, but only applied if using threadmarks for ## chapters and a 'reader' URL is found in the thread, 'reader mode' ## will reduce the number of pages fetched by roughly 10 to 1 for a @@ -1039,13 +1048,19 @@ use_threadmark_wordcounts:true [base_xenforoforum:epub] -## See remove_spoilers above for more about 'spoilers'. This example +## See remove_spoilers/etc above for more about 'spoilers'. This example ## shows how to put a simple line around spoiler blocks. Uncomment ## all three lines, keep the leading space before .bbCodeSpoilerContainer. #add_to_keep_html_attrs:,style #add_to_output_css: # .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; } +## This example shows how to put a simple line around +## 'details_spoilers' blocks. Uncomment both lines, keep the leading +## space before .bbCodeSpoilerContainer. +#add_to_output_css: +# .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; } + ## When reveal_invisible_text:true, you can style the class ## invisible_text as you like for forum "invisible text". See ## reveal_invisible_text above. This is just one example. Note that diff --git a/fanficfare/adapters/base_xenforoforum_adapter.py b/fanficfare/adapters/base_xenforoforum_adapter.py index 629b9046..9467e542 100644 --- a/fanficfare/adapters/base_xenforoforum_adapter.py +++ b/fanficfare/adapters/base_xenforoforum_adapter.py @@ -850,6 +850,16 @@ class BaseXenForoForumAdapter(BaseSiteAdapter): legend.string = stripHTML(div.button.span) div.insert(0,legend) div.button.extract() + elif self.getConfig('details_spoilers'): + for div in self.get_spoiler_tags(topsoup): + div.name='details' + # add copy of XF1 class name for convenience of + # existing output_css when XF2. + div['class'].append('bbCodeSpoilerContainer') + legend = topsoup.new_tag('summary') + legend.string = stripHTML(div.button.span) + div.insert(0,legend) + div.button.extract() def _do_utf8FromSoup(self,url,soup,fetch=None,allow_replace_br_with_p=True): if self.getConfig('reveal_invisible_text'): diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index 19ad5247..cb68e718 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -296,6 +296,7 @@ def get_valid_set_options(): 'author_avatar_cover':(base_xenforo_list,None,boollist), 'remove_spoilers':(base_xenforo_list+['royalroad.com'],None,boollist), 'legend_spoilers':(base_xenforo_list+['royalroad.com', 'fiction.live'],None,boollist), + 'details_spoilers':(base_xenforo_list,None,boollist), 'apocrypha_to_omake':(base_xenforo_list,None,boollist), 'replace_failed_smilies_with_alt_text':(base_xenforo_list,None,boollist), 'use_threadmark_wordcounts':(base_xenforo_list,None,boollist), @@ -556,6 +557,7 @@ def get_valid_keywords(): 'reader_posts_per_page', 'remove_spoilers', 'legend_spoilers', + 'details_spoilers', 'apocrypha_to_omake', 'skip_threadmarks_categories', 'fix_relative_text_links', diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 427d96d2..4e9b4010 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -899,8 +899,17 @@ always_use_forumtags:false ## spoiler blocks with the original spoiler button text as a label ## using fieldset and legend HTML tags. For a simple box, see the ## add_to_output_css example for [base_xenforoforum:epub] below. +## remove_spoilers overrides legend_spoilers #legend_spoilers:false +## This option if uncommented and set true, will change the tags +## around spoiler blocks to a
tag with tag +## containing the original spoiler button text. For a simple line +## box, see the add_to_output_css example for [base_xenforoforum:epub] +## below. +## remove_spoilers and legend_spoilers override details +#details_spoilers:false + ## True by built-in default, but only applied if using threadmarks for ## chapters and a 'reader' URL is found in the thread, 'reader mode' ## will reduce the number of pages fetched by roughly 10 to 1 for a @@ -1031,13 +1040,19 @@ use_threadmark_wordcounts:true [base_xenforoforum:epub] -## See remove_spoilers above for more about 'spoilers'. This example +## See remove_spoilers/etc above for more about 'spoilers'. This example ## shows how to put a simple line around spoiler blocks. Uncomment ## all three lines, keep the leading space before .bbCodeSpoilerContainer. #add_to_keep_html_attrs:,style #add_to_output_css: # .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; } +## This example shows how to put a simple line around +## 'details_spoilers' blocks. Uncomment both lines, keep the leading +## space before .bbCodeSpoilerContainer. +#add_to_output_css: +# .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; } + ## When reveal_invisible_text:true, you can style the class ## invisible_text as you like for forum "invisible text". See ## reveal_invisible_text above. This is just one example. Note that