position info missing when use plain `[url]` syntax
Initial checklist
- [x] I read the support docs
- [x] I read the contributing guide
- [x] I agree to follow the code of conduct
- [x] I searched issues and discussions and couldn’t find anything (or linked relevant results below)
Affected package
Steps to reproduce
https://github.com/Project-HAMi/HAMi/pull/1271
[https://github.com/Project-HAMi/HAMi/pull/1271]
Actual behavior
The first link and text both have correct position info, while the second link and texts all have no position info unexpectedly.
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "https://github.com/Project-HAMi/HAMi/pull/1271",
"children": [
{
"type": "text",
"value": "https://github.com/Project-HAMi/HAMi/pull/1271",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 47,
"offset": 46
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 47,
"offset": 46
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 47,
"offset": 46
}
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "["
},
{
"type": "link",
"title": null,
"url": "https://github.com/Project-HAMi/HAMi/pull/1271",
"children": [
{
"type": "text",
"value": "https://github.com/Project-HAMi/HAMi/pull/1271"
}
]
},
{
"type": "text",
"value": "]"
}
],
"position": {
"start": {
"line": 3,
"column": 1,
"offset": 48
},
"end": {
"line": 3,
"column": 49,
"offset": 96
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 3,
"column": 49,
"offset": 96
}
}
}
Expected behavior
position should always be there
Runtime
Package manager
Operating system
macOS Sequoia 15.6.1
Build and bundle tools
No response
May I ask which package is actually doing the parsing? Too many dependencies... Not sure where to fix.
Is it micromark-extension-gfm-autolink-literal?
https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/blob/ba83f42e2d6e7bafbb213b2bf94ec533891a6d82/lib/index.js#L130.
It’s not really fixable, because it by definition works on the AST instead of on the markdown input.
See how GH renders the code by OP:
https://github.com/Project-HAMi/HAMi/pull/1271
[https://github.com/Project-HAMi/HAMi/pull/1271]
References: https://github.com/micromark/micromark-extension-gfm-autolink-literal/tree/main?tab=readme-ov-file#bugs, https://github.com/github/cmark-gfm/issues/278
It's blocking Prettier, what should we do?
Simply join them as a Node?
I am not entirely sure what your use case is; what joining means? what alternatives you have?
Given the GH bug, I’d think the ideal output would be [<https://github.com/Project-HAMi/HAMi/pull/1271>] as that renders correctly on GH as: [https://github.com/Project-HAMi/HAMi/pull/1271]. Generally I think prettier should never output raw URLs but always wrap them in <>, that’s what we do
what joining means?
Children in link don't have position information, I mean I should join the children as a normal text.
what alternatives you have?
I don't. Since Prettier requires position.
It’s not really fixable, because it by definition works on the AST instead of on the markdown input.
I'm not quite sure to understand, this issue is about parsing with position info missing, not about printing? position SHOULD always be there on Node. The linked references bugs are not about position, are they?
No, position should not always be there: when the tree is changed in a way that new nodes were not present in the original document, position should not be there.
The original source text could have . and such in there, changing positional info.
Prettier is a formatter, that’s why I suggest formatting in a particular way.
The referenced issues in cmark-gfm are to show that I think how GH works is not good.
Because GH works like that, on the AST, these projects work on the AST too
No,
positionshould not always be there: when the tree is changed in a way that new nodes were not present in the original document, position should not be there.
Hmm... But the content is parsed as text([]) + link nodes same as the source text.
My original issue is not specific for prettier, I found this issue because eslint-mdx is also using position info on Node which is assumed to always be there on parsing phase.
Should we reconsider allowing disable "autolink" then? https://github.com/remarkjs/remark-gfm/issues/16#issuecomment-899046315
I'm trying to make an own mdast-util-gfm by removing gfmAutolinkLiteralFromMarkdown and gfmAutolinkLiteralToMarkdown, somehow
>cat test.md
_http://www.example.com:80/_a*b_
>yarn debug test.md
test.md{
type: 'paragraph',
children: [ { type: 'emphasis', children: [], position: [Object] } ],
position: {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 33, offset: 32 }
}
}
__
Missing children in emphasis
https://github.com/prettier/prettier/pull/18365