Skip to content

Commit

Permalink
Merge pull request #24 from kadirahq/fix-8
Browse files Browse the repository at this point in the history
Support markdown #8
  • Loading branch information
arunoda authored Oct 11, 2016
2 parents 62e51ab + 55b5077 commit 988b7a3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"insert-css": "^1.0.0",
"marked": "^0.3.6",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-render-html": "^0.1.6",
Expand Down
21 changes: 18 additions & 3 deletions src/manager/components/CommentForm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import React, { Component } from 'react';
import Textarea from 'react-textarea-autosize';
import marked from 'marked';
import style from './style';

const renderer = new marked.Renderer();
renderer.heading = function (text, level) {
return text;
}

marked.setOptions({
renderer: renderer,
gfm: true,
tables: false,
breaks: true,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
});

export default class CommentForm extends Component {
constructor(props, ...args) {
super(props, ...args);
Expand All @@ -27,10 +44,8 @@ export default class CommentForm extends Component {
return;
}

const processedText = text.replace(/\r?\n/g, '<br />');
addComment(processedText);
addComment(marked(text));
this.setState({ text: '' });
this.forceUpdate();
}

render() {
Expand Down
58 changes: 56 additions & 2 deletions src/manager/components/CommentList/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
import React, { Component } from 'react';
import moment from 'moment';
import renderHTML from 'react-render-html';
import insertCss from 'insert-css';
import style from './style';

export default class CommentList extends Component {
const customStyle = `
.comment-content p {
margin: 0;
padding: 0;
}
.comment-content pre {
white-space: pre-wrap;
word-wrap: break-word;
padding: 5px 8px;
color: #000;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 0.94em;
border-radius: 3px;
background-color: #F8F8F8;
border: 1px solid #f1f1f1;
}
.comment-content pre code {
border: 0px !important;
background: transparent !important;
line-height: 1.3em;
}
.comment-content code {
padding: 0 3px 0 3px;
color: #000;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 0.94em;
border-radius: 3px;
background-color: #F8F8F8;
border: 1px solid #f1f1f1;
}
.comment-content blockquote {
color: #666666;
margin: 3px 0;
padding-left: 12px;
border-left: 0.5em #EEE solid;
}
.comment-content ul, .comment-content ol {
margin: 1em 0;
padding: 0 0 0 2em;
}
.comment-content a {
color: #0645ad;
text-decoration: none;
}
`;

insertCss(customStyle);

export default class CommentList extends Component {
componentDidMount() {
const wrapper = this.refs.wrapper;
wrapper.scrollTop = wrapper.scrollHeight;
Expand Down Expand Up @@ -34,7 +88,7 @@ export default class CommentList extends Component {
<div style={style.commentAside}>
<img style={style.commentAvatar} src={comment.user.avatar} />
</div>
<div style={style.commentContent}>
<div className="comment-content" style={style.commentContent}>
<div style={style.commentHead}>
<span style={style.commentUser}>{comment.user.name}</span>
<span style={style.commentTime}>{this.formatTime(comment.time)}</span>
Expand Down

0 comments on commit 988b7a3

Please sign in to comment.