From 3933d94bad5ab4c89f0931f32fcb809e4e47d615 Mon Sep 17 00:00:00 2001 From: Wisani Shilumani Date: Thu, 19 Jul 2018 14:57:53 +0200 Subject: [PATCH] Remove all html tags --- components/browseArchives/index.js | 11 ------- components/searchResults/index.js | 48 ++++-------------------------- 2 files changed, 5 insertions(+), 54 deletions(-) diff --git a/components/browseArchives/index.js b/components/browseArchives/index.js index f3a172e..01379c6 100644 --- a/components/browseArchives/index.js +++ b/components/browseArchives/index.js @@ -132,7 +132,6 @@ class BrowseArchives extends React.Component { betterInterviews.push({ id: i + 1, - tags: 'tag1, tag2, tag3', name: interview.Name, matchedIndex: -1, interview: interviewFormatted, @@ -181,16 +180,6 @@ class BrowseArchives extends React.Component { }; } - const matchesTag = interview.tags.toLowerCase().indexOf(lcTerm) !== -1; - - if (matchesTag) { - return { - found: true, - foundIndex: 0, - matchCount: 0, - }; - } - const matchingQuestionAnswerPositions = []; const matchingQuestions = interview.interview diff --git a/components/searchResults/index.js b/components/searchResults/index.js index 0ea3fca..dacec60 100644 --- a/components/searchResults/index.js +++ b/components/searchResults/index.js @@ -16,39 +16,12 @@ const SearchResults = (props) => { // sort array alphabetically const sortedInterviews = props.data.sort((a, b) => a.name.localeCompare(b.name)); - const getStartOffset = (text) => { - if (text.indexOf('/p>') === 0) { - return 3; - } else if (text.indexOf('>') === 0) { - return 1; - } else if (text.indexOf('p>') === 0) { - return -1; - } else if (text.indexOf('

') !== 0) { - return false; - } - - return false; - }; - - const getEndOffset = (text) => { - if (text.substr(text.length - 1, 1) === '<') { - return -1; - } else if (text.substr(text.length - 2, 2) === '') { - return -3; - } - - return 0; - }; - const trimText = (text, strpos, length) => { let offset = 0; let firstEllipses = ''; let lastEllipses = ''; - let startOffset = 0; - let endOffset = 0; const allowance = props.term.length + 5; + const cleanText = text.replace(/<(?:.|\n)*?>/gm, ''); if (text === null) { return ''; @@ -63,27 +36,16 @@ const SearchResults = (props) => { if (strpos > length && strpos !== -1 && length > 50 && text.length > length) { offset = strpos - (length - allowance); - firstEllipses = '

...

'; + firstEllipses = '...'; } - const offsetText = text.substr(offset, length + offset); - startOffset = getStartOffset(offsetText); - endOffset = getEndOffset(offsetText); + const offsetText = cleanText.substr(offset, length + offset); - /** - * We only append a p tag if we haven't found any of the tags in getStartOffset() - * or if we've found a '>' in the first position. Since this could be an opening - * or a closing tag. So we remove it and add a p tag - */ - const newOffsetText = startOffset !== false && startOffset !== -1 ? - text.substr(offset + startOffset, length + offset + endOffset) : - `

${text.substr(offset + 0, length + offset + endOffset)}`; - - if (newOffsetText.substr(newOffsetText.length - 1, 1) !== '.' && newOffsetText.substr(newOffsetText.length - 1, 1) !== '>') { + if (offsetText.substr(offsetText.length - 1, 1) !== '.') { lastEllipses = '...'; } - return text.length <= length ? text : `${firstEllipses}${newOffsetText}${lastEllipses}`; + return cleanText.length <= length ? `

${offsetText}

` : `

${firstEllipses}${offsetText}${lastEllipses}

`; }; const highlightTerm = (text) => {