marked-ast icon indicating copy to clipboard operation
marked-ast copied to clipboard

Link href with parens generates incorrect ast

Open zeusdeux opened this issue 6 years ago • 4 comments

Hey! Thanks for a great package! The application I'm working on ran into this issue recently where if the href for a link contains non url encoded parens (()), the ast node generated for the link doesn't contain the full href.

marked-ast version: 0.3.0

Steps to reproduce:

  1. Invoke MarkedAst._marked like so —
MarkedAst._marked('[Some link](https://something.xyz/(12)/1)', {
      // use renderer with altered methods for links and images
      renderer: new MarkedAst.AstBuilder(),
      // turn on Github-flavored MD goodies
      gfm: true,
      tables: true,
      breaks: true,
      smartypants: true,
      sanitize: false
    });

Expected ast:

[
  {
    "type": "paragraph",
    "text": [
      {
        "type": "link",
        "href": "https://something.xyz/(12)/1",
        "title": null,
        "text": [
          "Some link"
        ]
      }
    ]
  }
]

Received/Actual:

[
  {
    "type": "paragraph",
    "text": [
      {
        "type": "link",
        "href": "https://something.xyz/(12",
        "title": null,
        "text": [
          "Some link"
        ]
      },
      "/1)"
    ]
  }
]

Any ideas on how we can resolve this? Thanks in advance!

zeusdeux avatar Apr 26 '19 11:04 zeusdeux

Have you tried testing with the latest version of marked? If it parsely properly there, then it can probably be solved by updating this package to use the new version.

pdubroy avatar Apr 27 '19 10:04 pdubroy

Just did and marked.parse('[Some link](https://something.xyz/(12)/1)') returns '<p><a href="https://something.xyz/(12)/1">Some link</a></p>\n' which looks correct so maybe the update in this package would work! ^_^

zeusdeux avatar Apr 27 '19 12:04 zeusdeux

I've tried updating this package but it's incredibly hard as all the tests fail as soon as I switch to a newer version of marked. Could you help with that @pdubroy?

zeusdeux avatar Jul 15 '19 11:07 zeusdeux

@zeusdeux Looks like you need to copy the tests from marked too. npm run update-tests should do it.

pdubroy avatar Jul 27 '19 12:07 pdubroy