html2wxml icon indicating copy to clipboard operation
html2wxml copied to clipboard

markdown 的代码块,q请求加个复制按钮

Open ZhangLe1993 opened this issue 4 years ago • 2 comments

ZhangLe1993 avatar Nov 07 '21 06:11 ZhangLe1993

我是改了大佬源码实现了,求指点 在html2xml.wxml 113行添加 <view class="copyMdBox" wx:if="{{item.tag == 'pre'}}"> <view class="copyMd copyMd-title">code</view> <view class="copyMd"> <text bind:tap="copyMdCode" data-copy="{{item.nodes}}" wx:if="{{!textCopy}}">点击复制</text> <icon wx:else class="icon-small" type="success_no_circle" size="23"></icon> </view> </view> html2xml.js copyMdCode(e) { console.log(e); let that = this; let dt = e.currentTarget.dataset.copy; let res = this.getText(dt); wx.setClipboardData({ data: res, success: function (res) { that.setData({ textCopy: "点击复制" }); } }) }, getText(data) { let text = ''; for (let i = 0; i < data.length; i++) { if (data[i].text) { text += data[i].text; } if (data[i].nodes && data[i].nodes.length > 0) { text += this.getText(data[i].nodes); } } return text; }, },

Lxb921006 avatar Jan 08 '24 07:01 Lxb921006

111 效果展示

Lxb921006 avatar Jan 08 '24 07:01 Lxb921006