import React from 'react'; import PageBody from '../Page/PageBody.js'; export default class SearchResultList extends React.Component { constructor(props) { super(props); this.getHighlightBody = this.getHighlightBody.bind(this); } getHighlightBody(body) { let returnBody = body; this.props.searchingKeyword.split(' ').forEach((keyword) => { const k = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); const keywordExp = new RegExp(`(${k}(?!(.*?\]|.*?\\)|.*?"|.*?>)))`, 'ig'); returnBody = returnBody.replace(keywordExp, '$&'); }); //console.log(this.props.searchingKeyword, body); return returnBody; } render() { const resultList = this.props.pages.map((page) => { const pageBody = this.getHighlightBody(page.revision.body); return (

{page.path}

); }); return (
{resultList}
); } } SearchResultList.propTypes = { pages: React.PropTypes.array.isRequired, searchingKeyword: React.PropTypes.string.isRequired, }; SearchResultList.defaultProps = { pages: [], searchingKeyword: '', };