Sublime Forum

Preview

#1

https://github.com/iafan/SublimeTextPreview

Preview plugin maps your local project files to URLs and opens them in your browser for preview (default key binding is F12).

It allows you to match files by path prefix, path suffix (e.g. extension) and replace the prefix/suffix with something else when constructing a final URL. Here’s the sample configuration file that comes with the plugin to help you grasp the idea:

[code]{
“rules”:
// prohibit previewing local files (i.e. files that don’t match any rule)
{
“url”: “”
},

    // allow opening local .htm and .html in browser
    {
        "path_suffix": ".htm",
        "url_prefix": "file:///"
    },
    {
        "path_suffix": ".html",
        "url_prefix": "file:///"
    },

    // sample website
    {
        // for all files matching the path_prefix, construct URL using url_prefix
        "path_prefix": "C:/Work/www/",
        "url_prefix": "http://localhost/",
        // append this string to all URLs
        "url_append": "?debug"
    },
    {
        // files in /inc/ subdirectory can't be previewed directly, so just open the root URL
        "path_prefix": "C:/Work/www/inc/",
        "url": "http://localhost/"
    },
    {
        // when editing .htaccess files, just open the containing folder
        "path_prefix": "C:/Work/www/inc/",
        "path_suffix": "/.htaccess",
        "url_prefix": "http://localhost/",
        "url_suffix": "/"
    }
]

}[/code]

The plugin is not in the package manager yet; pull request submitted. To install, just grab this zip and unpack it into Sublime Text 2 “Packages” folder.

0 Likes