-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Some text
node has not position
property
#16
Comments
Unfortunately we can’t add them. GH’s uses two algorithms to add autolinks (see this readme and some of the other issues there). One at parse time, another at “AST” time. The one at parse time nicely adds positional info. The one at AST-time can’t infer the original position of certain URLs from text nodes, because the AST only has the starting and ending point, but no knowledge in this case: - > a block quote in a list
with https://example.com a URL But, the fact that http://user:password@host:port/path?key=value#fragment
http://user:password@host:port/path?key=value#fragment http://user:password@host:port/path?key=value#fragment ^-- it shouldn’t link |
text
node has not position
propertytext
node has not position
property
However, It seems that gfm plugin can infer the import unified from "unified";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
const remark = unified().use(remarkParse).use(remarkGfm);
const ast = remark.parse(`This is https://example.com`);
console.log(JSON.stringify(ast, null, 4)); to {
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is ",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 9,
"offset": 8
}
}
},
{
"type": "link",
"title": null,
"url": "https://example.com",
"children": [
{
"type": "text",
"value": "https://example.com",
"position": {
"start": {
"line": 1,
"column": 9,
"offset": 8
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 9,
"offset": 8
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
} I think that it is a bug related to result of list + blockquote + autolinkimport unified from "unified";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
const remark = unified().use(remarkParse).use(remarkGfm);
const ast = remark.parse(`- > a block quote in a list
with https://example.com a URL`);
console.log(JSON.stringify(ast, null, 4)); to {
"type": "root",
"children": [
{
"type": "list",
"ordered": false,
"start": null,
"spread": false,
"children": [
{
"type": "listItem",
"spread": false,
"checked": null,
"children": [
{
"type": "blockquote",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "a block quote in a list",
"position": {
"start": {
"line": 1,
"column": 5,
"offset": 4
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 5,
"offset": 4
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 3,
"offset": 2
},
"end": {
"line": 1,
"column": 28,
"offset": 27
}
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "with ",
"position": {
"start": {
"line": 2,
"column": 5,
"offset": 32
},
"end": {
"line": 2,
"column": 10,
"offset": 37
}
}
},
{
"type": "link",
"title": null,
"url": "https://example.com",
"children": [
{
"type": "text",
"value": "https://example.com",
"position": {
"start": {
"line": 2,
"column": 10,
"offset": 37
},
"end": {
"line": 2,
"column": 29,
"offset": 56
}
}
}
],
"position": {
"start": {
"line": 2,
"column": 10,
"offset": 37
},
"end": {
"line": 2,
"column": 29,
"offset": 56
}
}
},
{
"type": "text",
"value": " a URL",
"position": {
"start": {
"line": 2,
"column": 29,
"offset": 56
},
"end": {
"line": 2,
"column": 35,
"offset": 62
}
}
}
],
"position": {
"start": {
"line": 2,
"column": 5,
"offset": 32
},
"end": {
"line": 2,
"column": 35,
"offset": 62
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 35,
"offset": 62
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 35,
"offset": 62
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 35,
"offset": 62
}
}
} |
text
node has not position
propertytext
node has not position
property
This is exactly what I described in my previous comment!
I think it’s acceptable, because it’s impossible to solve. The list + blockquote example was to illustrate, here is an actual working example: https://runkit.com/embed/tyohiws7jhem. There is no positional info on the link, because it has to use algorithm 2, and it would be hard to figure out from the AST information where that link was originally. There is a bug: |
Thanks for the details.
Does it mean that transforming AST to AST? I expected that all node has Actually, remark@12 has Is there a workaround for avoiding creating non- |
I have looked into this. We may need following changes to transformGfmAutolinkLiterals. diff --git a/from-markdown.js b/from-markdown.js
index 8a24bcc..cc02eab 100644
--- a/from-markdown.js
+++ b/from-markdown.js
@@ -82,7 +82,22 @@ function findUrl($0, protocol, domain, path, match) {
type: 'link',
title: null,
url: prefix + protocol + parts[0],
- children: [{type: 'text', value: protocol + parts[0]}]
+ children: [{
+ type: 'text',
+ value: protocol + parts[0],
+ position: {
+ start: {
+ line: calcLineFromOffset(node.position.start.offset + match.index),
+ column: calcColumnFromOffset(node.position.start.offset + match.index),
+ offset: node.position.start.offset + match.index
+ },
+ end: {
+ line: calcLineFromOffset(node.position.start.offset + match.index + $0.length),
+ column: calcColumnFromOffset(node.position.start.offset + match.index + $0.length),
+ offset: node.position.start.offset + match.index + $0.length
+ }
+ }
+ }]
}
if (parts[1]) { Lack of implementation:
|
📝 Workaround: disable import unified from "unified";
// @ts-ignore
import autolinkLiteral from "mdast-util-gfm-autolink-literal/from-markdown";
// disable autolink transforms
autolinkLiteral.transforms = [];
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
const remark = unified().use(remarkParse).use(remarkGfm);
const ast = remark.parse(`http://user:password@host:port/path?key=value#fragment`);
console.log(JSON.stringify(ast, null, 4)); |
* feat(markdown-to-ast): update remark-parse@9 * test: update snapshots * fix: support footnote [^1] again * fix: create range from offset * fix: treat BOM text * chore: rename footnoteReference to FootnoteReference * test: add broken example * test: add broken example * fix(markdown-to-ast): add a workaround to fix broken node workaround for remarkjs/remark-gfm#16
Given this markdown: - > a block quote in a list
with https://example.com a URL The text node has this value: It starts at 1:5, and ends at 2:35. The markdown could look like this: - > a block quote in a list
with https://example.com a URL This: - > a block quote in a list
with https://example.com a URL This: :::some custom markdown structure
a block quote in a list
with https://example.com a URL
::: How do you know where the link starts and ends?
The
Yes it did, but it also didn’t match GFM. To properly match GFM, the two algorithms need to be used: one at parse time, one at “AST time”. |
This comment has been minimized.
This comment has been minimized.
I fixed what seemed like the bug. |
Thanks
Would it be possible to provide a option that disable mdast-util-gfm-autolink-literal? |
I don’t see a reason for an option to turn all of I somewhat see an option to turn algorithm2 off, which is what you do in the workaround, in The reason is that algorithm2 does not work in comments, and thus that option would somewhat match some flavor of GFM. But not 100%, because email links do work in comments: https://gist.github.com/wooorm/076fd173c31ba6837f17591d5932476e. I’m not convinced yet of such an option. @ChristianMurphy? (and I think your workaround will work fine with ESM!) |
I don't really see the option as making much sense. 🤔 Taking a step back, |
Subject of the issue
When parsing some text, the
text
node has notposition
property.Your environment
Env:
Node: 14.16.1 - ~/.volta/tools/image/node/14.16.1/bin/node
Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
npm: 6.14.12 - ~/.volta/tools/image/node/14.16.1/bin/npm
Steps to reproduce
Reproducing repo: https://github.com/azu/remark-gfm-no-position-bug
output:
Expected behavior
The
text
node should haveposition
property.Actual behavior
The
text
node has notposition
property.Escaping +
http://
is something wrong:http://a
The text was updated successfully, but these errors were encountered: