Settings

Theme

Commonmark.js: Problem with bare hyperlinks enclosed in angle brackets

1 points by jsx2 a year ago · 0 comments · 1 min read


I try to use Commonmark.js on a local HTML page. And there is a problem with bare hyperlinks enclosed in angle brackets:

    <div id="input">

    **bold** and <em>italic</em>

    - <https://example.com>
    - <https://example.net>

    </div>

    <script src="https://unpkg.com/commonmark@0.29.3/dist/commonmark.js"></script>
    <script>
    window.onload = function() {
      var markdown = document.querySelector('#input').innerHTML;
      var reader = new commonmark.Parser();
      var writer = new commonmark.HtmlRenderer();
      var parsed = reader.parse(markdown);
      var result = writer.render(parsed);
      document.querySelector('body').innerHTML = result;
    }
    </script>

 Why is that? How to prevent bare hyperlinks enclosed in angle brackets to be treated as tags, and at the same time to keep ability to parse HTML (that is `<em>italic</em>` should be rendered as *italic*)?

 I tried the Commonmark demo and it doesn’t have this problem.

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection