芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/cloud.pulsehost.co.uk/modules/CoreWebclient/js/utils/Text.js
'use strict'; var Types = require('%PathToCoreWebclientModule%/js/utils/Types.js'), Settings = require('%PathToCoreWebclientModule%/js/Settings.js'), TextUtils = {} ; TextUtils.trim = function (text = '') { return typeof text === 'string' ? text.trim() : ''; }; TextUtils.isHtml = function (text = '') { // Alternative way // var doc = new DOMParser().parseFromString(text, "text/html"); // return Array.from(doc.body.childNodes).some(node => node.nodeType === 1); // checking for tags (including closing ones) with names that consist of letters and dashes only return /<\/?[a-zA-Z-]+(?:\s|\s[^>]+|\S)?>/i.test(text) }; /** * Converts plaintext to HTML text. * @param {string} text * @param {boolean} prepareLinks * @returns {string} */ TextUtils.plainToHtml = function (text = '', prepareLinks = false) { let html = text.toString() .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') .replaceAll('>', ' >') /* whitespace is required to separate encoded > from the end of a link */ ; if (prepareLinks) { //URLs starting with http://, https://, or ftp:// const replacePattern1 = /(\b(?:https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; html = html.replace(replacePattern1, '
$1
'); //URLs starting with "www." (without // before it, or it'd re-link the ones done above). const replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim; html = html.replace(replacePattern2, '$1
$2
'); //Change email addresses to mailto:: links. const replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim; html = html.replace(replacePattern3, '
$1
'); } /* removing spaces befor > that where added on purpose */ html = html.replaceAll(' >', '>'); return html.replace(/\r/g, '').replace(/\n/g, '
'); }; /** * Converts HTML text to plaintext. * @param {string} html * @returns {string} */ TextUtils.htmlToPlain = function(html = '') { return html.toString() .replace(/([^>]{1})
/gi, '$1\n') .replace(/