Adding A New HTML Feature!
In order to support HTML files we created a new htmlObject class that implements the "IPreviewObject" interface.
For the local HTML files, we decided to allow the option to open to resoure (code) file in a new tab.
To do so we created a new command, very much similar to the text and css command:
This command is called in the "getLocalHtmlMarkdownString" function. (more explenation in this tutorial)
For the external html path we decided to support 3 previews:
1. open in external browser
2. open in "internal" browser (webview panel)- we used the commandUriNewTab command we already made for previewing images in a new tab in order to view the rendered html content as a web page.
The "getHtmlContent" methos in this object looks like this:
3. open resource html file (the html code)- we created a new command which calls the "getHtmlResource" function.
This function sends a GET request in order to get the url resource.
When the response arrives it creates a new temporary document with the responded text, as a html file.
* We needed to run "npm install xmlhttprequest" command in cmd.
So, the total markdown method looks like this:
The third and last method we needed to implement from the interface was "makeMrkdownString".
In this function we checked if the url is a local or external html file and called the "getWebHtmlMarkdownString" or "getLocalHtmlMarkdownString" function we saw earlier.
THE TOTAL LOOK:
Comments
Post a Comment