解决cherry-markdown的图片base64太长影响预览问题

在实际生产过程中,在粘贴插入图片或者说是把内容传给后台,后台再传递回来时,被压缩的base64字符串将会以长字符串的显示,妨碍阅读,状况如下

在查询完解决方案,并参考了官方issues的更改:https://github.com/Tencent/cherry-markdown/pull/727icon-default.png?t=N7T8https://github.com/Tencent/cherry-markdown/pull/727

在issues的更改基础上,我们需要在if语句里面也加上 this.editor.dealSpecialWords();

更改如下,假如你引用的是cherry-markdown.js,需要对setValue函数进行更改,行数大概在71034行(见截图):

function setValue(content) {
  var keepCursor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  this.editor.storeDocumentScroll();

  // keepCursor 用于确定在设置文本后是否需要保持光标的当前位置
  if (keepCursor === false) {
	// 在这里也需要进行base64的处理
    this.editor.dealSpecialWords(); // 添加这一句
    return this.editor.editor.setValue(content);
  }

  var codemirror = this.editor.editor;
  var old = this.getValue();
  var pos = codemirror.getDoc().indexFromPos(codemirror.getCursor());
  var newPos = getPosBydiffs(pos, old, content);
  codemirror.setValue(content);
  var cursor = codemirror.getDoc().posFromIndex(newPos);
  codemirror.setCursor(cursor);
  this.editor.dealSpecialWords();
}

如果你引用的是cherry-markdown.min.js,需要对定位到更改的地方, 建议使用 return this.editor.editor.setValue(  来进行定位,然后进行代码修改,修改为 {this.editor.dealSpecialWords();return this.editor.editor.setValue(t);} 。详见截图和代码:

// 注意这一段代码需要加上{},因为没改之前if语句后面只有一句话,现在有两句
{this.editor.dealSpecialWords();return this.editor.editor.setValue(t);}

以下是解决完的效果图:

愿能帮到大家少走弯路,如果有更好的解决方法也可以私我一下,哈哈哈

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值