Marked: Translate IPv6 url to link

Created on 24 Sep 2020  路  9Comments  路  Source: markedjs/marked

Describe the feature
Automatic translate ipv6 urls to links

Problem

> marked("IPv4 url: http://127.0.0.1/index.html\n IPv6 url: http://[1080:0:0:0:8:800:200C:417A]/index.html")
< "<p>IPv4 url: <a href="http://127.0.0.1/index.html">http://127.0.0.1/index.html</a>
 IPv6 url: http://[1080:0:0:0:8:800:200C:417A]/index.html</p>
"

Related rfc: https://tools.ietf.org/html/rfc2732

links GFM works as intended

Most helpful comment

Looks like they are using an old version of marked. The latest version does work with angle brackets. demo

The example also results in "about:blank#blocked", because the [ and ] in the generated html href got url encoded:

<p><a href="http://%5B1080:0:0:0:8:800:200C:417A%5D/index.html">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></p>

Test: http://[1080:0:0:0:8:800:200C:417A]/index.html

All 9 comments

IPv4 url: http://127.0.0.1/index.html
IPv6 url: http://[1080:0:0:0:8:800:200C:417A]/index.html


It doesn't look like GFM autolinks IPv6 urls. If you want it to become part of the GFM spec you can create an issue here.

A work around is to surround it in angle brackets (<>):

<http://[1080:0:0:0:8:800:200C:417A]/index.html>

IPv4 url: http://127.0.0.1/index.html
IPv6 url: http://[1080:0:0:0:8:800:200C:417A]/index.html

It doesn't look like GFM autolinks IPv6 urls. If you want it to become part of the GFM spec you can create an issue here.

A work around is to surround it in angle brackets (<>):

<http://[1080:0:0:0:8:800:200C:417A]/index.html>

Angle brackets didn't work.

I get the same error as here:

https://github.com/HelloZeroNet/ZeroMe/issues/147

Looks like they are using an old version of marked. The latest version does work with angle brackets. demo

Looks like they are using an old version of marked. The latest version does work with angle brackets. demo

about:blank#blocked

^I keep getting this, clicking the links in Chrome. Firefox just ignores link clicks, doing nothing in response instead of showing the error, so both browsers are affected.

Note that another ZeroNet site by @HelloZeroNet doesn't have this problem. It lets you proceed to the site, so then both browsers are fine in this case.

There is nothing marked can do about that you will have to create an issue with chrome and firefox.

A quick google search finds this support thread. Hope that helps.

You sure it's not the site?

It seems like it is the browser blocking that link from that site for security reasons. It could be a change to the site that fixes it (maybe it has mixed content or invalid certificates), but I know that changing marked will not help it in any way.

Looks like they are using an old version of marked. The latest version does work with angle brackets. demo

The example also results in "about:blank#blocked", because the [ and ] in the generated html href got url encoded:

<p><a href="http://%5B1080:0:0:0:8:800:200C:417A%5D/index.html">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></p>

Test: http://[1080:0:0:0:8:800:200C:417A]/index.html

The example also results in "about:blank#blocked", because the [ and ] in the generated html href got url encoded

That is also according to the spec.

commonmark demo

If you want to change that behavior in marked you can create a renderer.

The following proof of concept code has not been tested and most likely will need to be changed to cover edge cases and fix any bugs.

const renderer = {
  link(href, title, text) {
    href = href.replace(/^(https?:\/\/)%5B(.*?)%5D/, '$1[$2]');
    return marked.Renderer.prototype.link(href, title, text);
};

marked.use({ renderer });

console.log(marked('<http://[1080:0:0:0:8:800:200C:417A]/index.html>'));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bennycode picture bennycode  路  4Comments

UziTech picture UziTech  路  4Comments

learykara picture learykara  路  3Comments

raguay picture raguay  路  4Comments

pigtooter picture pigtooter  路  4Comments