Skip to content
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

Parsing of link node doesn't return title attribute #28

Closed
nvanexan opened this issue May 14, 2022 · 0 comments · Fixed by #32 or #38
Closed

Parsing of link node doesn't return title attribute #28

nvanexan opened this issue May 14, 2022 · 0 comments · Fixed by #32 or #38
Assignees
Labels
bug Something isn't working

Comments

@nvanexan
Copy link
Contributor

nvanexan commented May 14, 2022

What happened?

I was trying to create a custom transform on "link" nodes to support adding additional custom attributes and in doing so, I noticed that the title attribute declared in markdown was never returned when calling Markdoc.parse.

In the Commonmark spec, link-titles can be declared with the following syntax:

[link](/uri "title")

When running the parse function on a link with this syntax, however, only the href attribute is returned. No title attribute is ever returned from the parser.

Based on the documentation for link node, I expected href and optionally the title attribute to be available in the node attributes when the markdown is parsed.

To reproduce

The issue can be reproduced by running the following file.

import Markdoc, { Node } from "@markdoc/markdoc";

function printNodeAttributes(ast: Node) {
  if (ast.type === "link") {
    console.log(`Node type: ${ast.type}`);
    console.log(`Node attributes: ${JSON.stringify(ast.attributes)}`);
  }
  if (ast.children) {
    ast.children.forEach((child) => printNodeAttributes(child));
  }
}

const testLink = `[Markdoc](https://markdoc.io "markdoc link title")`;
const ast = Markdoc.parse(testLink);
printNodeAttributes(ast);

The output is

Node type: link
Node attributes: {"href":"https://markdoc.io"}

I was expecting

Node type: link
Node attributes: {"href":"https://markdoc.io", title: "markdoc link title"}

Version

0.1.1

Additional context

It looks like the source of the issue may be here

It looks like the handleAttrs function is only returning href for link nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants