支持单击渲染markdown
This commit is contained in:
parent
0c8931c446
commit
3a7cea8c50
@ -80,6 +80,29 @@ Component({
|
||||
},
|
||||
})
|
||||
},
|
||||
renderMd: function (e) {
|
||||
var index = e.currentTarget.dataset.index
|
||||
var data = this.data.chatList[index]
|
||||
var content = data.originContent
|
||||
if (!this.data.chatList[index].content) {
|
||||
var matches = content.match(/```markdown[\s\S]*(```)?/g)
|
||||
if (null != matches) {
|
||||
matches.forEach(m => {
|
||||
var m1 = m.replace('```markdown', '')
|
||||
if (m1.trim().endsWith('```')) {
|
||||
m1 = m1.substring(0, m1.trim().length - 3)
|
||||
}
|
||||
content = content.replace(m, m1)
|
||||
})
|
||||
}
|
||||
data.content = content
|
||||
} else {
|
||||
data.content = null
|
||||
}
|
||||
this.setData({
|
||||
chatList: this.data.chatList
|
||||
})
|
||||
},
|
||||
suggestSubmit: function (e) {
|
||||
var suggest = e.currentTarget.dataset.suggest
|
||||
this.triggerEvent(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<!-- <wxs src="../../tools.wxs" module="tools" /> -->
|
||||
<wxs src="../../tools.wxs" module="tools" />
|
||||
<view catchlongpress="deletAllChat">
|
||||
<view wx:if="{{chatList.length == 0}}" style="text-align:center;color: rgb(180, 187, 196);font-size: 28rpx;">输入问题开始和New Bing聊天吧~</view>
|
||||
<scroll-view class="chat" scroll-y="true" scroll-into-view="{{scrollId}}" style="height:{{systemInfo.windowHeight - 70}}px;" enable-back-to-top="{{true}}" scroll-anchoring="{{true}}" enhanced="{{true}}" enable-flex="{{true}}">
|
||||
@ -7,7 +7,7 @@
|
||||
<image class="avatar" src="{{item.avatarUrl}}" style="display: flex;" catchlongpress="clearChat" data-index="{{index}}"></image>
|
||||
<view class="chat-box" style="margin-left: 20rpx;">
|
||||
<view style="display: flex;flex-direction: row;align-items: center;"><text class="dt" style="flex: 1;">{{item.dt}}</text><view wx:if="{{item.num_in_conversation && item.num_in_conversation != -1}}" style="display:flex;justify-content:flex-end; flex: 1;align-items: center;"><text class="conversation_num">{{item.num_in_conversation}}</text></view></view>
|
||||
<view class="content bg-white" catchlongpress="copyContent" data-index="{{index}}"><view class="{{item.blink ? 'blinking': ''}}"><mp-html content="{{item.originContent}}" preview-img selectable="{{true}}" markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" use-anchor="{{true}}" container-style="margin-top: -1em;"/></view></view>
|
||||
<view class="content bg-white" catchlongpress="copyContent" data-index="{{index}}" catchtap="{{tools.indexOf(item.originContent, '```markdown') ? 'renderMd': ''}}"><view class="{{item.blink ? 'blinking': ''}}"><mp-html content="{{item.content ? item.content: item.originContent}}" preview-img selectable="{{true}}" markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" use-anchor="{{true}}" container-style="margin-top: -1em;"/></view></view>
|
||||
<view class="suggest">
|
||||
<view hover-class="suggest-item-hover" class="suggest-item" bindtap="suggestSubmit" data-suggest="{{suggest}}" wx:for="{{item.suggests}}" wx:for-item="suggest" wx:if="{{suggest && suggest.length > 0}}">{{suggest}}</view>
|
||||
</view>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -119,6 +119,7 @@ Page({
|
||||
suggests.push(content)
|
||||
} else {
|
||||
robContent = "抱歉😭,发生错误:" + msg
|
||||
suggests.push("重新对话!")
|
||||
suggests.push(content)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user