jgm/djot

Standalone attributes

panglesd opened this issue · 6 comments

Hello !

I have another question about attributes. Why isn't it possible to have a floating/standalone attribute: an attribute that is not attached to anything?

For instance (assuming flag attributes),

In my presentation, you will see {pause} nothing.

{pause}

Just kidding!

would render in html as:

<p>In my presentation, you will see <span pause></span> nothing.</p>
<div pause></div>
<p>Just kidding!</p>

For reference:

  • Spaces before an inline attribute make the whole attribute disappear
  • Spaces after a block attribute does not change anything

So, currently the example above would render:

<p>In my presentation, you will see  nothing.</p>
<p pause>Just kidding!</p>

Interesting point.

As a workaround you could use a thematic break with class attributes and hide it with CSS

{.pause}
---

(This may have the advantage to make the intent explicit, vs. mistakenly having inserted a standalone attribute in the source?)

Thanks! It's also possible with the current syntax for inline attributes using []{pause}.

However, I think this harms the readability, so the workaround might work in some context, but in a context where you need to add standalone attributes quite often, it is not ideal.

This may have the advantage to make the intent explicit,

In my opinion, in:

paragraph 1

{attributes}

paragraph 2

the intent that attributes are standalone looks already explicit, rather than being attached to paragraph 2! That said, there is a problem of backward compatibility, and anyone used to the current syntax might not see the intent the same as me...

(In my specific case, I am implementing those features on top of another markdown parser (cmarkit) to have a syntax tailored to my (quite specific) needs. So, while I'm sad creating yet another markup variant, I am not tied to djot, and if no-one else needs this syntax, I understand if djot stays as it is!)

Practically, I’d use a symbol here, :pause:.

By definition, attributes attach to a node in a document tree. A node which is empty and is used only for its attributes is a reasonable construct, but it seems that it should have some non-empty syntax for readability. And using a symbol for an empty block/inline element makes sense syntactically.

Good idea, I did no think of using a symbol for my specific use-case.

About standalone attributes, if I understand correctly your suggestion is to have "empty nodes", represented by some non-empty syntax (more precisely, a symbol), and then attach this empty node with an inline attribute.

So for standalone block attributes:

{attributes}
:empty:

and for standalone inline attributes

paragraph words :empty:{attributes} other words

Is that right?

jgm commented

I don't see the use of this. You can attach attributes to an empty span or empty fenced div if you want. But attributes are semantically attributes of something.

About the use-case: I'd like to use a markup language for a presentation framework where there are a lot of <div attrs...></div> or ` and I wanted to have a lighter syntax for this.

But I agree with all the points here! Maybe I'm taking the wrong approach.

In any case, I think the fact that

word {.foo} word2

drops the {.foo} part (it is not rendered as text, nor added as an attribute: <p>word word2</p>) is not ideal! But maybe that's an implementation bug, not something related with the djot language.