let ProcessText = module.exports = {} ProcessText.removeHtml = (string) => { if(string == undefined || string == null || string.length == 0){ return '' } return string .replace(/&[#A-Za-z0-9]+;/g,' ') //Rip out all HTML entities .replace(/<[^>]+>/g, ' ') //Rip out all HTML tags .replace(/\s+/g, ' ') //Remove all whitespace .trim() } 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 */ ProcessText.deduceNoteTitle = (inString) => { let title = '' //Title of note let sub = '' //sub text below note if(!inString || inString == null || inString.length == 0){ return {title, sub} } let lines = inString.match(/[^\r\n]+/g) let finalLines = [] const startTags = ['') == -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(/ 0){ title = finalLines.shift() } 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 } }