🐛 Fix: Fix comment origin html tag perform (#222)

pull/223/head
hshanx 2020-08-04 21:36:46 +08:00 committed by GitHub
parent c2864ef695
commit 3ceec997b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -44,3 +44,12 @@ export function isObject(value) {
export function datetimeFormat(value, pattern = 'YYYY-MM-DD HH:mm') {
return moment(value).format(pattern)
}
// decode html tag
export function decodeHTML(html) {
let elem = document.createElement('div')
elem.innerHTML = html
const output = elem.innerText || elem.textContent
elem = null
return output
}

View File

@ -441,6 +441,8 @@ import { mixin, mixinDevice } from '@/utils/mixin.js'
import CommentDetail from './CommentDetail'
import marked from 'marked'
import commentApi from '@/api/comment'
import { decodeHTML } from '@/utils/util'
const postColumns = [
{
title: '昵称',
@ -576,7 +578,7 @@ export default {
formattedComments() {
return this.comments.map(comment => {
comment.statusProperty = this.commentStatus[comment.status]
comment.content = marked(comment.content)
comment.content = marked(decodeHTML(comment.content))
return comment
})
}

View File

@ -97,6 +97,8 @@
</template>
<script>
import marked from 'marked'
import { decodeHTML } from '@/utils/util'
export default {
name: 'TargetCommentTree',
props: {
@ -111,7 +113,7 @@ export default {
return `//cn.gravatar.com/avatar/${this.comment.gravatarMd5}/?s=256&d=mp`
},
content() {
return marked(this.comment.content)
return marked(decodeHTML(this.comment.content))
}
},
methods: {