by strongpigeon · 2y ago · 0 comments
> This means you can extend Sphinx with new text objects! Say you that instead of an <image>, you want a <figure> with a <figcaption>. In basic markdown you have to manually insert the html
I can’t help but wonder what’s wrong with just writing HTML if you want those features? Why the extra layer?
# 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`.1. HTML is designed for representing webpages, not books. Your intermediate representation will become HTML's DOM, which is likely not well suited to the book use case. You'll either need to use an existing HTML-to-DOM parser or build your own. One big limitation of the DOM, as I see it, is that it doesn't have the concept of a page number.
2. HTML is not extensible in the way the author talks about. This is the "semantic linking" thing I meant. In rST, you can define entirely new top-level constructs: he defines an exercise which has a solution and will be a part of a solution list. The semantic linking part is that other parts of the document will refer back to these solutions. Some output formats will have all solutions inline, with the exercises, while other output formats will collect all solutions in one place at the end. HTML is not flexible in that manner.
What is extensible is XML. It's entirely feasible for XML to be the input, but for better-or-worse, most people are even more turned off by XML than they are by something like rST.
Yep!
> 1. HTML is designed for representing webpages, not books. Your intermediate representation will become HTML's DOM, which is likely not well suited to the book use case. You'll either need to use an existing HTML-to-DOM parser or build your own. One big limitation of the DOM, as I see it, is that it doesn't have the concept of a page number.
I guess my point is that while the main use of HTML indeed to render webpage, it seems pretty well suited at rendering most if not all types of documents. The page number issue you mention is typically only part of the presentation and is handled by the CSS paged media module (though admittedly, support of this isn't universal in my experience).
> 2. HTML is not extensible in the way the author talks about. [...]
Except it is! This is what HTML Custom Elements are all about. Combined with CSS, it can handled to different rendering formats you mention pretty well.
> What is extensible is XML. It's entirely feasible for XML to be the input [...]
I'd actually argue that raw XML is the wrong approach for most things, as the goal of XML is to be extended (e.g.: SVG, MathML, SAML, etc.). But I feel like that's a whole other discussion.
Anyways, I think this is a good conversation and wouldn't mind continuing over email (see my profile). It's fine if some people like rST, but HTML seems better suited for these use case than people make it out to be.
The point is that it's objectively better when you want to separate the concerns of writing content and rendering it. It makes writing much easier and keeping the layout consistent as well.