Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
🐛 Fix: 修复评论不能换行的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhuz committed Jul 13, 2020
1 parent b665a19 commit 9127cf5
Show file tree
Hide file tree
Showing 9 changed files with 6,331 additions and 5,669 deletions.
11,955 changes: 6,301 additions & 5,654 deletions dist/halo-comment.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/halo-comment.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/halo-comment.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/halo-comment.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"dependencies": {
"autosize": "^4.0.2",
"axios": "^0.19.0",
"marked": "^0.8.0",
"highlight": "^0.2.4",
"highlight.js": "^10.1.1",
"highlightjs": "^9.16.2",
"marked": "^1.1.0",
"md5": "^2.2.1",
"promise.prototype.finally": "^3.1.2",
"ua-parser-js": "^0.7.21",
Expand Down
11 changes: 7 additions & 4 deletions src/components/CommentEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,30 @@
methods: {
handleSubmitClick() {
if (isEmpty(this.comment.author)) {
this.warnings.push("评论者昵称不能为空");
return;
// this.warnings.push("评论者昵称不能为空");
// return;
this.comment.author = 'Anonymous';
}
if (isEmpty(this.comment.email)) {
this.warnings.push("邮箱不能为空");
return;
// this.comment.email = '[email protected]';
}
if (isEmpty(this.comment.content)) {
this.warnings.push("评论内容不能为空");
return;
}
// comment 需要是 Markdown 格式的
this.comment.content = marked(this.comment.content);
const content = marked(this.comment.content);
// Submit the comment
this.comment.postId = this.targetId;
if (this.replyComment) {
// Set parent id if available
this.comment.parentId = this.replyComment.id;
}
commentApi
.createComment(this.target, this.comment)
.createComment(this.target, {...this.comment, content})
.then(response => {
// Store comment author, email, authorUrl
localStorage.setItem("comment-author", this.comment.author);
Expand Down
4 changes: 2 additions & 2 deletions src/components/CommentNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</template>
<script>
import "./index";
import {timeAgo} from "@/utils/util";
import {timeAgo, decodeHTML} from "@/utils/util";
import ua from "ua-parser-js";
import marked from "marked";
Expand Down Expand Up @@ -159,7 +159,7 @@
'">@' + this.comment.parentAuthor +
"</a>";
}
return at + marked(this.comment.content);
return at + marked(decodeHTML(this.comment.content));
},
createTimeAgo() {
return timeAgo(this.comment.createTime);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@
}

.comment-content.markdown-body > p {
display: inline-block;
//display: inline-block;
margin-left: .5rem;
}
.comment-content.markdown-body a {
Expand Down
9 changes: 9 additions & 0 deletions src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ export function getUrlKey(name) {
) || "")[1].replace(/\+/g, "%20")
) || null
);
}

// 特殊字符转义成HTML标签
export function decodeHTML(html){
var output, elem = document.createElement('div');
elem.innerHTML = html;
output = elem.innerText || elem.textContent;
elem = null;
return output;
}

0 comments on commit 9127cf5

Please sign in to comment.