hexojs / hexo-renderer-markdown-it

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

Anchors abnormal(锚点异常) #118

Closed KumaNNN closed 4 years ago

KumaNNN commented 4 years ago

Problem

_config.yml

anchors:
    permalinkSide: 'right'

Expected results(预期的结果) 2

Actual results(实际的结果) 1

Fix

Fix in hexo-renderer-markdown-it\lib\anchors.js

修复在 hexo-renderer-markdown-it\lib\anchors.js

//Old
const renderPermalink = function(slug, opts, tokens, idx) {
  const permalink = [Object.assign(new Token('link_open', 'a', 1), {
    attrs: [['class', opts.permalinkClass], ['href', '#' + slug]]  
  }), Object.assign(new Token('text', '', 0), {
    content: opts.permalinkSymbol
  }), new Token('link_close', 'a', -1), Object.assign(new Token('text', '', 0), {
    content: ''
  })];
//New
const renderPermalink = function(slug, opts, tokens, idx) {
  if (opts.permalinkSide === 'right') {
      var floatStr = 'none';
  } else {
      var floatStr = opts.permalinkSide;
  }
  const permalink = [Object.assign(new Token('link_open', 'a', 1), {    
    attrs: [['class', opts.permalinkClass], ['href', '#' + slug], ['style', 'float: ' + floatStr]]
  }), Object.assign(new Token('text', '', 0), {
    content: opts.permalinkSymbol
  }), new Token('link_close', 'a', -1), Object.assign(new Token('text', '', 0), {
    content: ''
  })];

Results(结果) 3

curbengh commented 4 years ago

https://github.com/hexojs/hexo-renderer-markdown-it/pull/119#issuecomment-671650546