Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Change markdow-it to marked.
Browse files Browse the repository at this point in the history
  • Loading branch information
潘伟洲 committed Jul 22, 2017
1 parent 11ff1b8 commit 5ab0f95
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ Pure JavaScript to make a Disqus-like comment system. Use issue system of code h
## Dependencies

* [jQuery](https://jquery.com/) - for making Ajax requests and manipulating DOM.
* [markdown-it](https://github.com/markdown-it/markdown-it) - for rendering markdown.
* [marked](https://github.com/chjj/marked) - for rendering markdown.
* [timeago.js](https://github.com/hustcc/timeago.js) - for formatting time labels.
* [highlight.js](http://highlightjs.org) - for syntax highlighting(optional).
* [spin](https://github.com/fgnass/spin.js) - for displaying a spinning indicator(optional).

## How to use
Expand All @@ -55,9 +56,32 @@ Pure JavaScript to make a Disqus-like comment system. Use issue system of code h

<!-- javascripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js">/script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.3.1/markdown-it.min.js">/script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/3.0.2/timeago.min.js"></script>

<!-- loading spin indicator(optional) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>

<!-- syntax highlighting(optional) -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script type="text/javascript">
marked.setOptions({
highlight: function (code, lang) {
return hljs.highlightAuto(code).value;
}
});
function Highlighting(){
var markdowns = document.getElementsByClassName('markdown');
for(var i=0;i<markdowns.length;i++){
if(markdowns[i].innerHTML) markdowns[i].innerHTML =marked(markdowns[i].innerHTML);
}
}
window.addEventListener('DOMContentLoaded', Highlighting, false);
window.addEventListener('load', Highlighting, false);
</script>

<!-- comment.js -->
<script src="path_to_comment_js/comment.js"></script>
```

Expand Down
20 changes: 17 additions & 3 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

<link rel="stylesheet" href="http://onmw7y6f4.bkt.clouddn.com/comment-v1.0.4.1.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.3.1/markdown-it.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/3.0.2/timeago.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>
<script src="http://onmw7y6f4.bkt.clouddn.com/comment-v1.0.7.js"></script>
<script src="http://onmw7y6f4.bkt.clouddn.com/comment-v1.0.7.1.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

Expand Down Expand Up @@ -135,6 +135,20 @@ <h1>{{ site.title | default: site.github.repository_name }}</h1>
};
getRecentCommentsList(opt2);
</script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
marked.setOptions({
highlight: function (code, lang) {
return hljs.highlightAuto(code).value;
}
});
function Highlighting(){
var markdowns = document.getElementsByClassName('markdown');
for(var i=0;i<markdowns.length;i++){
if(markdowns[i].innerHTML) markdowns[i].innerHTML =marked(markdowns[i].innerHTML);
}
}
window.addEventListener('DOMContentLoaded', Highlighting, false);
window.addEventListener('load', Highlighting, false);
</script>
</body>
</html>
5 changes: 2 additions & 3 deletions comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
'use strict';

var type, username, repo, client_id, client_secret, no_comment, go_to_comment, btn_class, comments_target, recent_comments_target, loading_target;
var md = window.markdownit();
var github_addr = "https://github.com/";
var github_api_addr = "https://api.github.com/repos/";
var oschina_addr = "http://git.oschina.net/";
Expand Down Expand Up @@ -158,7 +157,7 @@ var _getIssueByUrl = function _getIssueByUrl(issue_url, callback) {
var _renderComment = function _renderComment(comment) {
var timeagoInstance = timeago();
var user = comment.user;
var content = md.render(comment.body);
var content = marked(comment.body);
var ago = timeagoInstance.format(comment.created_at);
var current_user = user.login == username ? "current-user" : "";
var addr = type == 'github' ? github_addr : oschina_addr;
Expand All @@ -181,7 +180,7 @@ var _getRecentCommentList = function _getRecentCommentList(comment_list, i, rend
}
var comment = comments[i];
if (!comment) return;
var content = md.render(comment.body);
var content = marked(comment.body);
var title = comment.title;
var user = comment.user;
var timeagoInstance = timeago();
Expand Down
5 changes: 2 additions & 3 deletions src/comment-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
'use strict';

var type, username, repo, client_id, client_secret, no_comment, go_to_comment, btn_class, comments_target, recent_comments_target, loading_target;
var md = window.markdownit();
var github_addr = "https://github.com/";
var github_api_addr = "https://api.github.com/repos/";
var oschina_addr = "http://git.oschina.net/";
Expand Down Expand Up @@ -150,7 +149,7 @@ var _getIssueByUrl = function (issue_url, callback) {
var _renderComment = function (comment) {
var timeagoInstance = timeago();
let user = comment.user;
let content = md.render(comment.body);
let content = marked(comment.body);
let ago = timeagoInstance.format(comment.created_at);
let current_user = user.login == username ? "current-user" : "";
let addr = type == 'github' ? github_addr : oschina_addr;
Expand Down Expand Up @@ -231,7 +230,7 @@ var _getRecentCommentList = function (comment_list, i, render_count, total_count
}
let comment = comments[i];
if (!comment) return;
let content = md.render(comment.body);
let content = marked(comment.body);
let title = comment.title;
let user = comment.user;
var timeagoInstance = timeago();
Expand Down

0 comments on commit 5ab0f95

Please sign in to comment.