let ProcessText = module.exports = {} ProcessText.removeHtml = (string) => { if(string == undefined || string == null || string.length == 0){ return '' } return string .replace(/&[[#A-Za-z0-9]+A-Za-z0-9]+;/g,' ') //Rip out all HTML entities .replace(/<[^>]+>/g, ' ') //Rip out all HTML tags .replace(/\s+/g, ' ') //Remove all whitespace .trim() } //Remove Empty HTML lines from a string ProcessText.stripBlankHtmlLines = (string) => { if(string == undefined || string == null || string.length == 0){ return '' } //Blank lines look like this ->


return string.replace(/\\\<\/p\>/g,'') } //Remove Double Empty HTML lines from a string ProcessText.stripDoubleBlankLines = (string) => { if(string == undefined || string == null || string.length == 0){ return '' } //Blank lines look like this ->


return string.replace(/\\\<\/p\>\\\<\/p\>/g,'') } ProcessText.getUrlsFromString = (string) => { const urlPattern = /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/igm return string.match(urlPattern) } /* Pulls out title and subtext of note + Title is always first line + Empty lines are skipped + URLs are turned into links + All URLs are givent the target="_blank" property + Lists are given extra display characters + If note starts as a list, skip the title */ ProcessText.deduceNoteTitle = (inTitle, inString) => { let title = inTitle //Title of note let sub = '' //sub text below note //Always return a title as a String if(title == null){ title = '' } if(!inString || inString == null || inString.length == 0){ return {title, sub} } //Remove inline styles that may be added by editor // inString = inString.replace(/style=".*?"/g,'') // const tagFreeLength = ProcessText.removeHtml(inString).length // // Simplified attempt! // Remove tags, push caret if greater than 200 chars...thats it // Still needs, links to open in a new window. sub = ProcessText.stripDoubleBlankLines(inString) // if(tagFreeLength > 200){ // sub += '... ' // } // inString += '' return {title, sub} //Emergency ending tag if truncated. This will help regex find all the lines //Match full line and closing tag or just closing tag let lines = inString.match(/[<[a-zA-Z0-9]+>(.*?)<\/[a-zA-Z0-9]+>|<\/[a-zA-Z0-9>]+?>/gms) if(lines == null){ lines = [inString] } //.match(/[^\r\n]+/g) //Match return or newline // console.log('----------------') // console.log(lines) // console.log('----------------') let finalLines = [] const startTags = ['','') .trim() const lineStart = lines[i].trim().substring(0, 3) charLimit -= cleanLine.length //Close out list if char limit is hit if(charLimit <= 0 && listStart){ finalLines.push(lines[i]) break } //Images appear as empty, push em! if(cleanLine.length == 0 && lines[i].indexOf('') == -1){ const url = containsUrls[0] lines[i] = lines[i].replace(url, `${url}`) } //Insert target=_blank into links if set, do it for every link in line if(lines[i].indexOf('') > 0){ lines[i] = lines[i].replace(/= 300 || appendCaret){ finalLines.push('... ') } //Pull out title if its not an empty string if(!noTitleJustList && title == ''){ title = ProcessText.removeHtml( finalLines.shift() ).replace(' ','') } sub = finalLines.join('') //Return final display lengths let titleLength = ProcessText.removeHtml(title).trim().replace(' ','').length let subtextLength = ProcessText.removeHtml(sub).trim().replace(' ','').length return { title, sub, titleLength, subtextLength } }