TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

1 点作者 jsx24 个月前
I try to use Commonmark.js on a local HTML page. And there is a problem with bare hyperlinks enclosed in angle brackets:<p><pre><code> &lt;div id=&quot;input&quot;&gt; **bold** and &lt;em&gt;italic&lt;&#x2F;em&gt; - &lt;https:&#x2F;&#x2F;example.com&gt; - &lt;https:&#x2F;&#x2F;example.net&gt; &lt;&#x2F;div&gt; &lt;script src=&quot;https:&#x2F;&#x2F;unpkg.com&#x2F;commonmark@0.29.3&#x2F;dist&#x2F;commonmark.js&quot;&gt;&lt;&#x2F;script&gt; &lt;script&gt; window.onload = function() { var markdown = document.querySelector(&#x27;#input&#x27;).innerHTML; var reader = new commonmark.Parser(); var writer = new commonmark.HtmlRenderer(); var parsed = reader.parse(markdown); var result = writer.render(parsed); document.querySelector(&#x27;body&#x27;).innerHTML = result; } &lt;&#x2F;script&gt; 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 `&lt;em&gt;italic&lt;&#x2F;em&gt;` should be rendered as *italic*)? I tried the Commonmark demo and it doesn’t have this problem.</code></pre>

暂无评论

暂无评论