4 ms·
Convenience? I have a "spoiler" role for rST, for example, which works like this: # state class to contain the counter class _spoiler: count =
by ryan-c 2y ago
Convenience? I have a "spoiler" role for rST, for example, which works like this:
# state class to contain the counter
class _spoiler:
count = defaultdict(lambda: 0)
def id(src):
_spoiler.count[src] += 1
src_hash = sha256(src.encode()).hexdigest()[:7]
return f'spoil-{src_hash}{_spoiler.count[src]:03}'
def spoiler_role(name, rawtext, text, lineno, inliner,
options={}, content=[]):
src = inliner.document.attributes['source']
html = (
'<input id="{id}" type="checkbox" class="spoiler" checked />'+\
'<label for="{id}" class="spoiler">{text}</label>'
).format(text=text, id=_spoiler.id(src))
return [nodes.raw('', html, format='html')], []
I don't want to do that manually, and this lets me write :spoiler:`Rosebud was the name of his sled`.
- mmcdermott 2y agoJust out of curiosity, why not use HTML5's built-in details/summary tags (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details https://developer.mozilla.org/en-US/docs/Web/HTML/Element/de...)?
- ryan-c 2y agoThese get styled such that they're black-on-black until you click on them. detail/summary doesn't work like that. Maybe with wild css hacks?