|
@@ -8,6 +8,24 @@ export default class PageBody extends React.Component {
|
|
|
|
|
|
|
|
this.crowiRenderer = window.crowiRenderer; // FIXME
|
|
this.crowiRenderer = window.crowiRenderer; // FIXME
|
|
|
this.getMarkupHTML = this.getMarkupHTML.bind(this);
|
|
this.getMarkupHTML = this.getMarkupHTML.bind(this);
|
|
|
|
|
+ this.getHighlightBody = this.getHighlightBody.bind(this);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getHighlightBody(body, keywords) {
|
|
|
|
|
+ let returnBody = body;
|
|
|
|
|
+
|
|
|
|
|
+ keywords.replace(/"/g, '').split(' ').forEach((keyword) => {
|
|
|
|
|
+ if (keyword === '') {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const k = keyword
|
|
|
|
|
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
|
|
|
+ .replace(/(^"|"$)/g, ''); // for phrase (quoted) keyword
|
|
|
|
|
+ const keywordExp = new RegExp(`(${k}(?!(.*?")))`, 'ig');
|
|
|
|
|
+ returnBody = returnBody.replace(keywordExp, '<em class="highlighted">$&</em>');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return returnBody;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getMarkupHTML() {
|
|
getMarkupHTML() {
|
|
@@ -16,11 +34,17 @@ export default class PageBody extends React.Component {
|
|
|
body = this.props.page.revision.body;
|
|
body = this.props.page.revision.body;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return { __html: this.crowiRenderer.render(body) };
|
|
|
|
|
|
|
+ body = this.crowiRenderer.render(body);
|
|
|
|
|
+
|
|
|
|
|
+ if (this.props.highlightKeywords) {
|
|
|
|
|
+ body = this.getHighlightBody(body, this.props.highlightKeywords);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return { __html: body };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const parsedBody = this.getMarkupHTML();
|
|
|
|
|
|
|
+ let parsedBody = this.getMarkupHTML();
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div
|
|
<div
|
|
@@ -33,6 +57,7 @@ export default class PageBody extends React.Component {
|
|
|
|
|
|
|
|
PageBody.propTypes = {
|
|
PageBody.propTypes = {
|
|
|
page: PropTypes.object.isRequired,
|
|
page: PropTypes.object.isRequired,
|
|
|
|
|
+ highlightKeywords: PropTypes.string,
|
|
|
pageBody: PropTypes.string,
|
|
pageBody: PropTypes.string,
|
|
|
};
|
|
};
|
|
|
|
|
|