jgm / djot

A light markup language
https://djot.net
MIT License
1.63k stars 43 forks source link

Multi-line block-level attributes require future line parsing #163

Open hellux opened 1 year ago

hellux commented 1 year ago

The syntax reference states:

The contribution a line makes to block-level structure never depends on a future line.

and

Block attributes have the same syntax as inline attributes, but they must fit on one line.

However, the implementation intentionally allows multi-line attributes if indentation is used:

{
 %
 %
 attr=val
 %
 %
 %
 %
 }
> a
<blockquote attr="val">
<p>a</p>
</blockquote>

This seems to contradict that a line's impact on a block level structure never depends on a future line. When looking at the first line we can't tell whether it is a block-level attribute or a paragraph without parsing future lines until the closing }.

I can see that it would be useful to be able to hard-wrap e.g. long values, though it does not seem to work currently: #162.

jgm commented 1 year ago

That's true, the docs need updating in this regard (or maybe we should change this feature). The current implementation handles this as follows: we feed content line by line into an attribute parsing state machine, while also saving the raw lines, and when it fails, we convert the block from attributes to paragraph and feed the raw lines to the inline parser.

It feels slightly unprincipled compared to the rest, so maybe this should be reconsidered. My original vision was to require it to fit on one line.