Closed black-desk closed 6 months ago
That would be a good idea.
By the way, you might be interested in my https://github.com/jgm/djoths
It has a djot renderer that passes round-trip tests for all the test cases, and it omits the autogenerated ids.
I will make a PR later.
To be used as a formatter, I think djot.js should both keep these three documents unchanged.
# a
{#a}
# a
# a
[a]: #a
So, we cannot just simply compare the attributes and reference to check if it should be omitted or not.
I think we might add an autoAttributes
member to HasAttributes
interface and an autoReference
member to Doc
, to omit auto generated attributes and references.
But we have to break API in this way. Do you have a better idea?
I think it is probably okay for the interface to change this way. @matklad do you have any worries about this?
Alternatively, you could do what I did in my Haskell parser/renderer: the parser adds a special attribute _autogen=1
to track these. I adjusted the HTML and Djot renderers so they'd be sensitive to this attribute (and wouldn't print it as a regular attribute). This is more conservative, in that it doesn't alter the interface, but maybe a bit uglier.
I think it is probably okay for the interface to change this way. @matklad do you have any worries about this?
Alternatively, you could do what I did in my Haskell parser/renderer: the parser adds a special attribute
_autogen=1
to track these. I adjusted the HTML and Djot renderers so they'd be sensitive to this attribute (and wouldn't print it as a regular attribute). This is more conservative, in that it doesn't alter the interface, but maybe a bit uglier.
Consider this:
{.b}
# a
add _autogen=1
seems not working here.
add _autogen=1 seems not working here.
If you're trying my Haskell djot renderer, then note that I've changed to using a different approach. Now I just try to figure out if the id is the one that would have been autogenerated.
I am working on a lsp server for djot, and I want to use renderDjot as a formator. Keep these anchors is werid.