6

I'd like to run a HTML page so I configured the Execute / F5 command as following:

chrome.exe http://localhost:8080/$(FILE_NAME)

It works when the HTML file is located in the root of my Workspace (because my HTTP Web server is set up to do so). But it doesn't work when the file is in a subfolder.

Is there a predefined variable (i.e. $(RELATIVE_PATH)) that can be used to get the file path relative to the Workspace directory?

Thank you by advance for your help.

4 Answers4

5

Instead of using Chrome directly, you could use a .bat file.

Below is one version of such a .bat file that should be executed in Notepadd++ like this :

"path\to\file.bat" "$(FULL_CURRENT_PATH)"

For Windows, where the document root is in C:\inetpub\wwwroot, the .bat file is :

@echo off
set "param=%~1"
set "url=http://localhost/%param:C:\inetpub\wwwroot\=%"
start "" chrome.exe "%url%"

The general DOS syntax used above for replacing strings in a variable is :

"%variable-name:search-string=replacement-string%"

where in our case replacement-string is empty.

This simple .bat file can easily be improved to accept the string C:\inetpub\wwwroot\ as second parameter, and more.

The batch file may cause a black DOS window to appear momentarily, to disappear immediately once Chrome is launched. If it is still too annoying, see this answer.

harrymc
  • 498,455
1

As of the current version of Notepad++ 6.9.1, the problem with the files in sub-folders path in a web-server has not been fixed yet. The only variable for files path is $(FULL_CURRENT_PATH).

Check: Configuring Notepad++ to run php on localhost.

Maybe this issue will be fixed in the future releases of Notepad++.

iSR5
  • 1,759
1

Python Solution

With Np++ plugins even miracles can be achieved. I wrote a simple Np++ Python Script that achieves exactly this functionality. This solution only requires Notepad++ and the PythonScript plugin.

  1. Install Python Script from Plugins > Plugin Manager
  2. Plugins > Python Script > New Script
  3. Name it "OpenInBrowser.py" (for example) and paste the script: http://pastebin.com/wS4jThcp
  4. In the script, remember to configure your browserExeFullPath, browserUrl and your webpage's rootDir (under which the toplevel index.html would be located).
  5. Plugins > Python Script > Configuration and add your user script to the Menu (left hand list)
  6. Restart Notepad++, Settings > Shortcut Mapper > Plugin commands and map your script to a key, for instance F9. Now pressing that key will open your active document in the browser. No external solutions required.
pKami
  • 163
  • 6
0

Node.js Solution

Based on @harrymc's first comment, I ported the PHP workaround to my Node server.

1° In Notepad++:

Change the <Command> content in the file shortcuts.xml (you can find it under the folder %appdata%/Notepad++), for example:

chrome http://localhost:8080/npp?path=$(FULL_CURRENT_PATH) 

2° In Node.js:

Add a route in the server script (server.js) to handle HTTP GET request:

//redirection for Notepad++
app.get( '/npp', function ( req, res ) 
{
    res.redirect( req.query.path.substr( __dirname.length + 8 ) )
} )

where:

  • app is my Express component (app = express()),
  • +8 is needed because my web pages are located in a subfolder /public/.