base_xenforoforum: Add details_spoiler option for #1165

This commit is contained in:
Jim Miller 2025-02-28 20:00:54 -06:00
parent de7d8079d9
commit a0463fc85b
4 changed files with 44 additions and 2 deletions

View file

@ -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 <details> tag with <summary> 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

View file

@ -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'):

View file

@ -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',

View file

@ -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 <details> tag with <summary> 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