Extend caption syntax to images and block quotes#373
Extend caption syntax to images and block quotes#373dereuromark wants to merge 2 commits intojgm:mainfrom
Conversation
Generalize the existing table caption syntax (^ caption text) to also support images and block quotes: - Image + caption: wraps in <figure> with <figcaption> - Block quote + caption: wraps in <figure> with <figcaption>, useful for attributions - Table caption behavior is unchanged (<caption> element) Extract the caption rules into a dedicated "Caption" section in the spec for clarity, replacing the table-specific caption paragraph. Addresses jgm#28 and jgm#31.
Extend the existing table caption syntax (^ caption text) to also work with images and block quotes, wrapping them in <figure> and <figcaption> HTML elements. - Add Figure and Figcaption AST node types - Modify the -caption handler in parse.ts to detect image paragraphs and block quotes, wrapping them in figure/figcaption nodes - Add figure/figcaption rendering in the HTML renderer - Add test cases for image captions, block quote captions, formatted captions, and non-captionable element handling Companion spec PR: jgm/djot#373
doc/syntax.md
Outdated
| and can extend over multiple lines, provided they are indented relative | ||
| to the `^`. | ||
|
|
||
| A table caption produces a `<caption>` element inside the table: |
There was a problem hiding this comment.
<figure>, <caption>, <figcaption> etc. = does the specification of a lightweight markup language has to be dependent on HTML-derived concepts?
- It's too technical for non tech-savvy readers (who do not bother what HTML is)
- The lightweight markup language may be used in other context that the Web...
There was a problem hiding this comment.
(In other terms, the proposal here is confounding the specification of a markup and the actual way it might be rendered in some context, which is by no mean authoritative.)
There was a problem hiding this comment.
True. Let me rephrase this more agnostically.
|
Omikhleia raises a fair point about HTML-dependency in the spec. A possible approach: lead with semantic description, then mention HTML as an example output. For instance, instead of:
Consider:
This keeps the spec useful for HTML users while being output-agnostic in principle. The semantic meaning ("provides a title/description", "is associated with") comes first; the HTML rendering is presented as one possible output, not the definition. Same pattern could apply to figures:
This way non-technical readers understand what it does, and technical readers know how it renders. |
Lead with semantic descriptions ('provides a title or description',
'is associated with', 'becomes a figure'), then mention HTML rendering
as an example output. This addresses the concern about HTML-dependency
in the spec.
|
This being said, I personally like the proposal. So it has two reference implementations
A third independent implementation would be nice -- typically, for instance, the djot-hs parser (unless mistaken) used by Pandoc, i.e. with respect to the intermediary AST used in that software. On that topic, regarding: It seems to me that the most logical way would to use a Extra question: why on images and block quotes only, and not generalized to code blocks and divs? |
95% use case I would say. You gotto stop somewhere. |
Summary
^ captionsyntax (currently tables only) to also support images and block quotes<figure>with<figcaption><figure>with<figcaption>, useful for attributions<caption>element)This is a natural extension of the table caption syntax that already exists in the spec, using the same
^marker consistently across elements.Examples:
Addresses #28 and #31.
A reference implementation already exists in djot-php, closing the gap between upstream spec and downstream implementations.