"use strict"; var path = require( "path" ); var url = require( "url" ); var fs = require( "fs" ); var colors = require( "ansi-colors" ); var mime = require( 'mime' ); var validDataUrl = require( "valid-data-url" ); var util = {}; module.exports = util; util.defaults = { images: 8, svgs: 8, scripts: true, links: true, strict: false, relativeTo: "", rebaseRelativeTo: "", inlineAttribute: "data-inline", fileContent: "", requestResource: undefined, scriptTransform: undefined, linkTransform: undefined }; util.attrValueExpression = "(=[\"']([^\"']+?)[\"'])?"; /** * Escape special regex characters of a particular string * * @example * "http://www.test.com" --> "http:\/\/www\.test\.com" * * @param {String} str - string to escape * @return {String} string with special characters escaped */ util.escapeSpecialChars = function( str ) { return str.replace( /(\/|\.|\$|\^|\{|\[|\(|\||\)|\*|\+|\?|\\)/gm, "\\$1" ); }; util.isRemotePath = function( url ) { return /^'?https?:\/\/|^\/\//.test( url ); }; util.isBase64Path = function( url ) { return /^'?data.*base64/.test( url ); }; util.getAttrs = function( tagMarkup, settings ) { var tag = tagMarkup.match( /^<[^\W>]*/ ); if( tag ) { tag = tag[ 0 ]; var attrs = tagMarkup .replace( /(<[\s\S]*?(?=\>))([\s\S]*?(?=\<\/))(<\/[\w\W]>)?/gm, "$1>$3" ) .replace( /^<[^\s>]*/, "" ) .replace( /\/?>/, "" ) .replace( />?\s?<\/[^>]*>$/, "" ) .replace( new RegExp( settings.inlineAttribute + "-ignore" + util.attrValueExpression, "gi" ), "" ) .replace( new RegExp( settings.inlineAttribute + util.attrValueExpression, "gi" ), "" ); if( tag === "