function imagePreviewProvider(editor, pos, token, line) {
        var cm = editor._codeMirror;

        // Check for image name
        var urlRegEx = /url\(([^\)]*)\)/gi,
            tokenString,
            urlMatch;

        if (token.type === "string") {
            tokenString = token.string;
        } else {
            urlMatch = urlRegEx.exec(line);
            while (urlMatch) {
                if (pos.ch < urlMatch.index) {
                    // match is past cursor, so stop looping
                    break;
                } else if (pos.ch <= urlMatch.index + urlMatch[0].length) {
                    tokenString = urlMatch[1];
                    break;
                }
                urlMatch = urlRegEx.exec(line);
            }
        }

        if (!tokenString) {
            return null;
        }

        // Strip leading/trailing quotes, if present
        tokenString = tokenString.replace(/(^['"])|(['"]$)/g, "");

        var sPos, ePos;
        var docPath = editor.document.file.fullPath;
        var imgPath;

        // Determine whether or not this URL/path is likely to be an image.
        var parsed = PathUtils.parseUrl(tokenString);
        // If the URL has a protocol, check if it's one of the supported protocols
        var hasProtocol = parsed.protocol !== "" && validProtocols.indexOf(parsed.protocol.trim().toLowerCase()) !== -1;
        var ext = parsed.filenameExtension.replace(/^\./, '');
        var language = LanguageManager.getLanguageForExtension(ext);
        var id = language && language.getId();
        var isImage = id === "image" || id === "svg";

        // Use this URL if this is an absolute URL and either points to a
        // filename with a known image extension, or lacks an extension (e.g.,
        // a web service that returns an image). Honour the extensionlessImagePreview
        // preference as well in the latter case.
        if (hasProtocol && (isImage || (!ext && extensionlessImagePreview))) {
            imgPath = tokenString;
        }
        // Use this filename if this is a path with a known image extension.
        else if (!hasProtocol && isImage) {
            imgPath = "file:///" + FileUtils.getDirectoryPath(docPath) + tokenString;
        }

        if (!imgPath) {
            return null;
        }

        if (urlMatch) {
            sPos = {line: pos.line, ch: urlMatch.index};
            ePos = {line: pos.line, ch: urlMatch.index + urlMatch[0].length};
        } else {
            sPos = {line: pos.line, ch: token.start};
            ePos = {line: pos.line, ch: token.end};
        }

        var imgPreview = "<div class='image-preview'>"          +
                         "    <img src=\"" + imgPath + "\">"    +
                         "</div>";
        var coord = cm.charCoords(sPos);
        var xpos = (cm.charCoords(ePos).left - coord.left) / 2 + coord.left;

        var showHandler = function () {
            // Hide the preview container until the image is loaded.
            $previewContainer.hide();

            $previewContainer.find(".image-preview > img").on("load", function () {
                $previewContent
                    .append("<div class='img-size'>" +
                                this.naturalWidth + " &times; " + this.naturalHeight + " " + Strings.UNIT_PIXELS +
                            "</div>"
                        );
                $previewContainer.show();
                positionPreview(editor, popoverState.xpos, popoverState.ytop, popoverState.ybot);
            }).on("error", function (e) {
                e.preventDefault();
                hidePreview();
            });
        };

        return {
            start: sPos,
            end: ePos,
            content: imgPreview,
            onShow: showHandler,
            xpos: xpos,
            ytop: coord.top,
            ybot: coord.bottom,
            _imgPath: imgPath
        };
    }
function imagePreviewProvider(editor, pos, token, line) {
        var cm = editor._codeMirror;

        // Check for image name
        var urlRegEx = /url\(([^\)]*)\)/gi,
            tokenString,
            urlMatch;

        if (token.type === "string") {
            tokenString = token.string;
        } else {
            urlMatch = urlRegEx.exec(line);
            while (urlMatch) {
                if (pos.ch < urlMatch.index) {
                    // match is past cursor, so stop looping
                    break;
                } else if (pos.ch <= urlMatch.index + urlMatch[0].length) {
                    tokenString = urlMatch[1];
                    break;
                }
                urlMatch = urlRegEx.exec(line);
            }
        }

        if (!tokenString) {
            return null;
        }

        // Strip leading/trailing quotes, if present
        tokenString = tokenString.replace(/(^['"])|(['"]$)/g, "");

        var sPos, ePos;
        var docPath = editor.document.file.fullPath;
        var imgPath;

        // Determine whether or not this URL/path is likely to be an image.
        var parsed = PathUtils.parseUrl(tokenString);
        // If the URL has a protocol, check if it's one of the supported protocols
        var hasProtocol = parsed.protocol !== "" && validProtocols.indexOf(parsed.protocol.trim().toLowerCase()) !== -1;
        var ext = parsed.filenameExtension.replace(/^\./, '');
        var language = LanguageManager.getLanguageForExtension(ext);
        var id = language && language.getId();
        var isImage = id === "image" || id === "svg";

        // Use this URL if this is an absolute URL and either points to a
        // filename with a known image extension, or lacks an extension (e.g.,
        // a web service that returns an image). Honour the extensionlessImagePreview
        // preference as well in the latter case.
        if (hasProtocol && (isImage || (!ext && extensionlessImagePreview))) {
            imgPath = tokenString;
        }
        // Use this filename if this is a path with a known image extension.
        else if (!hasProtocol && isImage) {
            imgPath = "file:///" + FileUtils.getDirectoryPath(docPath) + tokenString;
        }

        if (!imgPath) {
            return null;
        }

        if (urlMatch) {
            sPos = {line: pos.line, ch: urlMatch.index};
            ePos = {line: pos.line, ch: urlMatch.index + urlMatch[0].length};
        } else {
            sPos = {line: pos.line, ch: token.start};
            ePos = {line: pos.line, ch: token.end};
        }

        var imgPreview = "<div class='image-preview'>"          +
                         "    <img src=\"" + imgPath + "\">"    +
                         "</div>";
        var coord = cm.charCoords(sPos);
        var xpos = (cm.charCoords(ePos).left - coord.left) / 2 + coord.left;

        var showHandler = function () {
            // Hide the preview container until the image is loaded.
            $previewContainer.hide();

            $previewContainer.find(".image-preview > img").on("load", function () {
                $previewContent
                    .append("<div class='img-size'>" +
                                this.naturalWidth + " &times; " + this.naturalHeight + " " + Strings.UNIT_PIXELS +
                            "</div>"
                        );
                $previewContainer.show();
                positionPreview(editor, popoverState.xpos, popoverState.ytop, popoverState.ybot);
            }).on("error", function (e) {
                e.preventDefault();
                hidePreview();
            });
        };

        return {
            start: sPos,
            end: ePos,
            content: imgPreview,
            onShow: showHandler,
            xpos: xpos,
            ytop: coord.top,
            ybot: coord.bottom,
            _imgPath: imgPath
        };
    }
function imagePreviewProvider ( editor , pos , token , line ) { var cm = editor . _codeMirror ; // Check for image name var urlRegEx = / url\(([^\)]*)\) / gi , tokenString , urlMatch ; if ( token . type === "string" ) { tokenString = token . string ; } else { urlMatch = urlRegEx . exec ( line ) ; while ( urlMatch ) { if ( pos . ch < urlMatch . index ) { // match is past cursor, so stop looping break ; } else if ( pos . ch <= urlMatch . index + urlMatch [ 0 ] . length ) { tokenString = urlMatch [ 1 ] ; break ; } urlMatch = urlRegEx . exec ( line ) ; } } if ( ! tokenString ) { return null ; } // Strip leading/trailing quotes, if present tokenString = tokenString . replace ( / (^['"])|(['"]$) / g , "" ) ; var sPos , ePos ; var docPath = editor . document . file . fullPath ; var imgPath ; // Determine whether or not this URL/path is likely to be an image. var parsed = PathUtils . parseUrl ( tokenString ) ; // If the URL has a protocol, check if it's one of the supported protocols var hasProtocol = parsed . protocol !== "" && validProtocols . indexOf ( parsed . protocol . trim ( ) . toLowerCase ( ) ) !== - 1 ; var ext = parsed . filenameExtension . replace ( / ^\. / , '' ) ; var language = LanguageManager . getLanguageForExtension ( ext ) ; var id = language && language . getId ( ) ; var isImage = id === "image" || id === "svg" ; // Use this URL if this is an absolute URL and either points to a // filename with a known image extension, or lacks an extension (e.g., // a web service that returns an image). Honour the extensionlessImagePreview // preference as well in the latter case. if ( hasProtocol && ( isImage || ( ! ext && extensionlessImagePreview ) ) ) { imgPath = tokenString ; } // Use this filename if this is a path with a known image extension. else if ( ! hasProtocol && isImage ) { imgPath = "file:///" + FileUtils . getDirectoryPath ( docPath ) + tokenString ; } if ( ! imgPath ) { return null ; } if ( urlMatch ) { sPos = { line : pos . line , ch : urlMatch . index } ; ePos = { line : pos . line , ch : urlMatch . index + urlMatch [ 0 ] . length } ; } else { sPos = { line : pos . line , ch : token . start } ; ePos = { line : pos . line , ch : token . end } ; } var imgPreview = "<div class='image-preview'>" + "    <img src=\"" + imgPath + "\">" + "</div>" ; var coord = cm . charCoords ( sPos ) ; var xpos = ( cm . charCoords ( ePos ) . left - coord . left ) / 2 + coord . left ; var showHandler = function ( ) { // Hide the preview container until the image is loaded. $previewContainer . hide ( ) ; $previewContainer . find ( ".image-preview > img" ) . on ( "load" , function ( ) { $previewContent . append ( "<div class='img-size'>" + this . naturalWidth + " &times; " + this . naturalHeight + " " + Strings . UNIT_PIXELS + "</div>" ) ; $previewContainer . show ( ) ; positionPreview ( editor , popoverState . xpos , popoverState . ytop , popoverState . ybot ) ; } ) . on ( "error" , function ( e ) { e . preventDefault ( ) ; hidePreview ( ) ; } ) ; } ; return { start : sPos , end : ePos , content : imgPreview , onShow : showHandler , xpos : xpos , ytop : coord . top , ybot : coord . bottom , _imgPath : imgPath } ; }
Image preview provider -------------------------------------------------
Image preview provider -------------------------------------------------
Image preview provider