import { TextEditor , Uri , ViewColumn } from "vscode" ; import { DocumentContentManagerInterface } from "./documentContentManagerInterface" ; import { HtmlPreview , SourceType } from "../util/htmlPreview" ; export class HtmlDocumentContentManager implements DocumentContentManagerInterface { private _editor : TextEditor ; public constructor ( editor ) { this . _editor = editor ; return this ; } public editor ( ) { return this . _editor ; } public async createContentSnippet ( ) { let editor = this . _editor ; if ( ! editor || ! editor . document ) { return HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ; } let previewSnippet = this . generatePreviewSnippet ( editor ) ; if ( ! previewSnippet || previewSnippet . length <= 0 ) { return HtmlPreview . errorSnippet ( this . getErrorMessage ( ) ) ; } console . info ( "previewSnippet = " + previewSnippet ) ; return previewSnippet ; } public sendPreviewCommand ( previewUri , displayColumn , _editor ) { return HtmlPreview . sendPreviewCommand ( previewUri , displayColumn ) ; } private getErrorMessage ( ) { return `Active editor doesn't show a HTML document - no properties to preview.` ; } private getWindowErrorMessage ( ) { return `No Active editor - no properties to preview.` ; } private generatePreviewSnippet ( editor ) { if ( ! editor || ! editor . document ) { return HtmlPreview . errorSnippet ( "No Active editor - no properties to preview." ) ; } let doc = editor . document ; return HtmlPreview . createLocalSource ( SourceType . STYLE , "header_fix.css" ) + HtmlPreview . createRemoteSource ( SourceType . BR ) + HtmlPreview . fixNoneNetLinks ( doc . getText ( ) , doc . fileName ) ; } }