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

Add a autolink field #3439

Closed
wants to merge 1 commit into from

Conversation

wvanderp
Copy link

@wvanderp wvanderp commented Sep 1, 2024

I'm working on an extension that will render markdown to markdown.
Then you can use marked to lex the markdown, change things, and then write it back to markdown.

While I know that parsing is an inherently lossy process, some of the details can be preserved.

In this PR, I propose to indicate if a link was an autolink or a regular link.

In the future, I might have more of these PRs.

This PR also fixes an issue with the node test runner. I'm running node 20.x, which indicated no unit tests were found.
With the changed command, the unit test now runs again.

If you have any questions or need any changes, please let me know because I'm happy to help.

Marked version: any

Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting a new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

Copy link

vercel bot commented Sep 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 1, 2024 0:59am

@UziTech
Copy link
Member

UziTech commented Sep 1, 2024

It looks like that change to the unit tests breaks in the latest version of node.

I think adding these Boolean parameters to tokens would be fine. We should try to add them all at once to prevent a bunch of releases.

@UziTech
Copy link
Member

UziTech commented Sep 2, 2024

One other option is to use the raw property to determine these properties. The raw property should always be the actual markdown that was used to create that token.

import { marked } from 'marked';

marked.lexer(`
[http://example.com](http://example.com)

http://example.com

[http://example.com][example]

[example]: http://example.com
`);
/*
[
  {
    "type": "space",
    "raw": "\n"
  },
  {
    "type": "paragraph",
    "raw": "[http://example.com](http://example.com)",
    "text": "[http://example.com](http://example.com)",
    "tokens": [
      {
        "type": "link",
        "raw": "[http://example.com](http://example.com)",
        "href": "http://example.com",
        "title": null,
        "text": "http://example.com",
        "tokens": [
          {
            "type": "text",
            "raw": "http://example.com",
            "text": "http://example.com"
          }
        ]
      }
    ]
  },
  {
    "type": "space",
    "raw": "\n\n"
  },
  {
    "type": "paragraph",
    "raw": "http://example.com",
    "text": "http://example.com",
    "tokens": [
      {
        "type": "link",
        "raw": "http://example.com",
        "text": "http://example.com",
        "href": "http://example.com",
        "tokens": [
          {
            "type": "text",
            "raw": "http://example.com",
            "text": "http://example.com"
          }
        ]
      }
    ]
  },
  {
    "type": "space",
    "raw": "\n\n"
  },
  {
    "type": "paragraph",
    "raw": "[http://example.com][example]",
    "text": "[http://example.com][example]",
    "tokens": [
      {
        "type": "link",
        "raw": "[http://example.com][example]",
        "href": "http://example.com",
        "title": null,
        "text": "http://example.com",
        "tokens": [
          {
            "type": "text",
            "raw": "http://example.com",
            "text": "http://example.com"
          }
        ]
      }
    ]
  },
  {
    "type": "space",
    "raw": "\n\n"
  }
  links: [Object: null prototype] {
    example: { href: 'http://example.com', title: undefined }
  }
]
*/

@UziTech
Copy link
Member

UziTech commented Nov 1, 2024

I'm going to close this as stale. If you would like to continue working on this feel free to get the tests passing and reopen this.

@UziTech UziTech closed this Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants