Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the web page preview inside Visual Studio Code?

Given that the Visual Studio Code is based on Chrome web kit

enter image description here

Could we open the preview inside the editor as a panel ?

According to this page, this feature is highly requested !

like image 717
Nassim MOUALEK Avatar asked Sep 29 '15 21:09

Nassim MOUALEK


People also ask

How do I use browser preview in Visual Studio Code?

Start by opening the extensions tab inside of VS Code. Then search for Browser Preview and click install. Now that you have the extension installed, let's see how to use it. This extension basically opens a (headless) browser window inside of VS Code.

How to preview HTML code on web server?

This extension provide preview of HTML which execute on web server. When you save files, this extension automatically reload browser or side panel (live preview feature). You can call these features from the context menu or editor menu. The main features are as follows. Preview on side panel (ctrl+shift+v): Open preview of HTML on side panel.

What is a WebView in Visual Studio Code?

For example, the built-in Markdown extension uses webviews to render Markdown previews. Webviews can also be used to build complex user interfaces beyond what VS Code's native APIs support. Think of a webview as an iframe within VS Code that your extension controls.

What is VSCode-preview-server extension?

vscode-preview-server. Features. This extension provide preview of HTML which execute on web server. When you save files, this extension automatically reload browser or side panel (live preview feature). You can call these features from the context menu or editor menu. The main features are as follows.


2 Answers

Well for now, based on Dan Shryock's answer here and this post, here is what I did:

  1. Install nodejs then live-server npm install -g live-server
  2. Run live-server at the project folder
  3. Create a live-view.md file with this in it (Place it wherever you want. I put it at the base folder of all my projects since I can use it for whatever I'm currently working on):

    <div style="border:1px solid #777;position:absolute;left:10px;top:10px;bottom:10px;right:10px;"> <iframe src="http://localhost:8080/"; width="100%" height="100%" frameborder="0" /> </div>

  4. Open live-view.md in the second/split pane in VS Code and click the "Open preview" button (top right of file).

Now whenever I save I see the changes show in the live-preview.

like image 198
DrCJones Avatar answered Nov 15 '22 07:11

DrCJones


For the moment, here how i solve it : Editing the file

C:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\parts\
markdown\browser\resources\welcome-mac.md

with super-admin rights, and adding

<input type="text" value="http://127.0.0.1:8080/" id="preview" onkeydown="var k = event.which; if (k==8) this.value = this.value.slice(0, -1);else if (k==13) document.getElementById('prevButton').click(); else this.value+=String.fromCharCode((96 <= k && k <= 105)? k-48 : k); "/>
<input type="button" onclick="window.location.replace(document.getElementById('preview').value);" value="Preview" id="prevButton" />

Then just open Welcom Page in the Menu you will have this enter image description here

Finally add a white background to your html body

like image 24
Nassim MOUALEK Avatar answered Nov 15 '22 07:11

Nassim MOUALEK