|
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import dateFnsFormat from 'date-fns/format';
|
|
import dateFnsFormat from 'date-fns/format';
|
|
|
|
|
|
|
|
|
|
+import RevisionBody from '../Page/RevisionBody';
|
|
|
|
|
+
|
|
|
import ReactUtils from '../ReactUtils';
|
|
import ReactUtils from '../ReactUtils';
|
|
|
import UserPicture from '../User/UserPicture';
|
|
import UserPicture from '../User/UserPicture';
|
|
|
|
|
|
|
@@ -19,11 +21,30 @@ export default class Comment extends React.Component {
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ html: '',
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
this.isCurrentUserIsAuthor = this.isCurrentUserEqualsToAuthor.bind(this);
|
|
this.isCurrentUserIsAuthor = this.isCurrentUserEqualsToAuthor.bind(this);
|
|
|
this.isCurrentRevision = this.isCurrentRevision.bind(this);
|
|
this.isCurrentRevision = this.isCurrentRevision.bind(this);
|
|
|
this.getRootClassName = this.getRootClassName.bind(this);
|
|
this.getRootClassName = this.getRootClassName.bind(this);
|
|
|
this.getRevisionLabelClassName = this.getRevisionLabelClassName.bind(this);
|
|
this.getRevisionLabelClassName = this.getRevisionLabelClassName.bind(this);
|
|
|
this.deleteBtnClickedHandler = this.deleteBtnClickedHandler.bind(this);
|
|
this.deleteBtnClickedHandler = this.deleteBtnClickedHandler.bind(this);
|
|
|
|
|
+ this.renderHtml = this.renderHtml.bind(this);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentWillMount() {
|
|
|
|
|
+ this.renderHtml(this.props.comment.comment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentWillReceiveProps(nextProps) {
|
|
|
|
|
+ this.renderHtml(nextProps.comment.comment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //not used
|
|
|
|
|
+ setMarkdown(markdown) {
|
|
|
|
|
+ this.setState({ markdown });
|
|
|
|
|
+ this.renderHtml(markdown);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
isCurrentUserEqualsToAuthor() {
|
|
isCurrentUserEqualsToAuthor() {
|
|
@@ -48,13 +69,57 @@ export default class Comment extends React.Component {
|
|
|
this.props.deleteBtnClicked(this.props.comment);
|
|
this.props.deleteBtnClicked(this.props.comment);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ renderRevisionBody() {
|
|
|
|
|
+ const config = this.props.crowi.getConfig();
|
|
|
|
|
+ const isMathJaxEnabled = !!config.env.MATHJAX;
|
|
|
|
|
+ return (
|
|
|
|
|
+ <RevisionBody html={this.state.html}
|
|
|
|
|
+ inputRef={el => this.revisionBodyElement = el}
|
|
|
|
|
+ isMathJaxEnabled={isMathJaxEnabled}
|
|
|
|
|
+ renderMathJaxOnInit={true} />
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderHtml(markdown) {
|
|
|
|
|
+ var context = {
|
|
|
|
|
+ markdown,
|
|
|
|
|
+ dom: this.revisionBodyElement,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const crowiRenderer = this.props.crowiRenderer;
|
|
|
|
|
+ const interceptorManager = this.props.crowi.interceptorManager;
|
|
|
|
|
+ interceptorManager.process('preCommentRender', context)
|
|
|
|
|
+ .then(() => interceptorManager.process('preCommentPreProcess', context))
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ context.markdown = crowiRenderer.preProcess(context.markdown);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => interceptorManager.process('postCommentPreProcess', context))
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ var parsedHTML = crowiRenderer.process(context.markdown);
|
|
|
|
|
+ context['parsedHTML'] = parsedHTML;
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => interceptorManager.process('preCommentPostProcess', context))
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ context.parsedHTML = crowiRenderer.postProcess(context.parsedHTML, context.dom);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => interceptorManager.process('postCommentPostProcess', context))
|
|
|
|
|
+ .then(() => interceptorManager.process('preCommentRenderHtml', context))
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ this.setState({ html: context.parsedHTML });
|
|
|
|
|
+ })
|
|
|
|
|
+ // process interceptors for post rendering
|
|
|
|
|
+ .then(() => interceptorManager.process('postCommentRenderHtml', context));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
const comment = this.props.comment;
|
|
const comment = this.props.comment;
|
|
|
const creator = comment.creator;
|
|
const creator = comment.creator;
|
|
|
|
|
+ const isMarkdown = comment.isMarkdown;
|
|
|
|
|
|
|
|
const rootClassName = this.getRootClassName();
|
|
const rootClassName = this.getRootClassName();
|
|
|
const commentDate = dateFnsFormat(comment.createdAt, 'YYYY/MM/DD HH:mm');
|
|
const commentDate = dateFnsFormat(comment.createdAt, 'YYYY/MM/DD HH:mm');
|
|
|
- const commentBody = ReactUtils.nl2br(comment.comment);
|
|
|
|
|
|
|
+ const commentBody = isMarkdown ? this.renderRevisionBody(): ReactUtils.nl2br(comment.comment);
|
|
|
const creatorsPage = `/user/${creator.username}`;
|
|
const creatorsPage = `/user/${creator.username}`;
|
|
|
const revHref = `?revision=${comment.revision}`;
|
|
const revHref = `?revision=${comment.revision}`;
|
|
|
const revFirst8Letters = comment.revision.substr(-8);
|
|
const revFirst8Letters = comment.revision.substr(-8);
|
|
@@ -90,4 +155,6 @@ Comment.propTypes = {
|
|
|
currentRevisionId: PropTypes.string.isRequired,
|
|
currentRevisionId: PropTypes.string.isRequired,
|
|
|
currentUserId: PropTypes.string.isRequired,
|
|
currentUserId: PropTypes.string.isRequired,
|
|
|
deleteBtnClicked: PropTypes.func.isRequired,
|
|
deleteBtnClicked: PropTypes.func.isRequired,
|
|
|
|
|
+ crowi: PropTypes.object.isRequired,
|
|
|
|
|
+ crowiRenderer: PropTypes.object.isRequired,
|
|
|
};
|
|
};
|