hexojs / hexo-renderer-markdown-it

Markdown-it is a Markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
MIT License
343 stars 60 forks source link

Render problem with image inside a link (linked image) #46

Closed noraj closed 7 years ago

noraj commented 7 years ago

Image inside a link (linked image) is not rendered properly.

Markdown:

[![](https://ctftime.org/static/images/CTFTIME-flat-logo-true.png)](https://ctftime.org/user/16344)

Rendered with hexo render markdown it:

<a href="https://ctftime.org/user/16344">
    <a href="https://ctftime.org/static/images/CTFTIME-flat-logo-true.png" title="">
        <img src="https://ctftime.org/static/images/CTFTIME-flat-logo-true.png" alt="">
    </a>
</a>

Rendered with official markdown previewer:

<a href="https://ctftime.org/user/16344">
    <img src="https://ctftime.org/static/images/CTFTIME-flat-logo-true.png" alt="" title="">
</a>

The fun fact is that markdown-it demo render it well but hexo-renderer-markdown-it not.

NoahDragon commented 7 years ago

Could you please post the plugins you have installed and the theme is using?

noraj commented 7 years ago
NoahDragon commented 7 years ago

I think it may cause by the fancybox. Could you please turn it off, and see if there is a difference?

noraj commented 7 years ago

@NoahDragon . I tested, changed nothing.

noraj commented 7 years ago

I also made an fresh default hexo site with hexo init uninstalled marked and install markdown-it, desactivated the fancybox and the problem is still the same. So this is really a problem of the hexo renderer.

NoahDragon commented 7 years ago

@noraj1337 I'm not sure, because I couldn't reproduce this issue, and I'm using the marked renderer.

noraj commented 7 years ago

@NoahDragon I tried again. The html content generated by markdown it is good. But even with fancybox set to False, there is some javascript dynamically adding a fancybox class and changing the href.

At the end of each page there is

<script src="/js/script.js"></script>

This script contain:

[...]
// Caption
  $('.article-entry').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;

      var alt = this.alt;

      if (alt) $(this).after('<span class="caption">' + alt + '</span>');

      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });

    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });

  if ($.fancybox){
    $('.fancybox').fancybox();
  }
[...]
noraj commented 7 years ago

The ejs template including the script is themes/landscape/layout/_partial/after-footer.ejs.

Where you can see:

[...]
<% if (theme.fancybox){ %>
  <%- css('fancybox/jquery.fancybox') %>
  <%- js('fancybox/jquery.fancybox.pack') %>
<% } %>

<%- js('js/script') %>

So <%- js('js/script') %> is included even if theme.fancybox is false and that script is generating the problem.

noraj commented 7 years ago

Issue open https://github.com/hexojs/hexo-theme-landscape/issues/96

noraj commented 7 years ago

We can close it here.