-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trailing whitespace in labels is elided #22
Comments
I spent some time digging into this and trying to produce a fix. As far as I can tell, what's going on is:
Assuming you consider this behavior to be a bug, I'm not sure whether you'd consider the defect to be in the PS: Thank you for all your hard work! |
Thanks for the investigation and your kind words!
|
I’m not 100% this is a bug. Given Why do you want trailing whitespace? |
Thank you for digging in! It’s a fair question, and I don’t think it’s totally obvious that trailing whitespace should be preserved. I’m hoping to use the inline text directive to produce behavior somewhat like other inline text directives—links, inline code, emphasis. Of those, the first two preserve trailing whitespace; the last does not, AFAICT to avoid spurious parse situations. In my mind, these directive labels are very congruent to link labels. Perhaps leaf and container directive labels are less obviously analogous to link labels than the text directive labels. More concretely, I’m experimenting with text directives to create a “redact” markup for a flashcard system, and I imagined an interface where one can drag the handles of the redaction left to right across the text, character by character. It’s freeing to be able to drop the handle wherever, and feels weird if it “jumps” when I release it because the underlying representation can’t place the right edge in certain positions. I can make this work without actual syntactic support for the trailing space scenario, but it felt unintentional (given the line suffix token when it’s not actually at the end of a line) so I thought I’d write a bug. Thanks for considering! |
Links and emphasis are the same. *b
c*
[b
c](#) https://spec.commonmark.org/dingus/?text=%20*b%20%0Ac*%20%0A%0A%20%5Bb%20%0Ac%5D(%23)%20%0A The thing with them though, is that they are parsed as separate things: With content in the But there are two things here: a) initial/trailing when looking at the whole, b) initial/trailing when looking at a line ending. I assume you don’t see a reason for “keeping” the initial/trailing whitespace for So if this would be implemented, it should be a) only for text directives, b) not affect whitespace around line endings. Note: you can use a character reference btw: |
Ah, great point. No, in a document like this, you're right that I would expect the leading/trailing line whitespace to be stripped:
Right. I agree with your argument that stripping whitespace here matches the behavior of other flow-level nodes.
Right. I guess I'd expect the
Thanks! |
Without a final end-of-file end-of-line, it’s still the end of the line ( I remain unsure whichever is better. Current state or proposed state. I can see arguments for both. |
Fair enough! :) Thanks for your consideration. One more thing I wanted to mention. You mention "Links and emphasis are the same."—and in your example, they are. I'm sure you know this, but I wanted to clarify that I was referring to the behavior of links when their label doesn't involve a line ending; i.e. |
Initial checklist
Affected packages and versions
[email protected] [email protected] [email protected]
Link to runnable example
https://astexplorer.net/#/gist/b3ff9dc85d8e49ef94791c73e645646f/21c9658bf3272b1922fb07d889351d8482c1c552
Steps to reproduce
In this AST Explorer demo, observe the parse tree for
:redact[secret ]word
.(The same issue reproduces on my local machine using node@20, bun, macOS 14.1.2, and no build tools).
Expected behavior
I expect the
textDirective
node's childtext
node to have valuesecret
(with the trailing space).Actual behavior
The
textDirective
node's childtext
node has valuesecret
(without the trailing space). The trailing space isn't represented anywhere else in the parse tree.Runtime
Other (please specify in steps to reproduce)
Package manager
Other (please specify in steps to reproduce)
OS
Other (please specify in steps to reproduce)
Build and bundle tools
Other (please specify in steps to reproduce)
The text was updated successfully, but these errors were encountered: