File tree 5 files changed +100
-4
lines changed
module/PowerShellEditorServices.VSCode/Public/HtmlContentView
src/PowerShellEditorServices.VSCode/CustomViews
5 files changed +100
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ function Set-VSCodeHtmlContentView {
19
19
The HTML content that will be placed inside the <body> tag
20
20
of the view.
21
21
22
+ . PARAMETER JavaScriptPaths
23
+ An array of paths to JavaScript files that will be loaded
24
+ into the view.
25
+
26
+ . PARAMETER StyleSheetPaths
27
+ An array of paths to stylesheet (CSS) files that will be
28
+ loaded into the view.
29
+
22
30
. EXAMPLE
23
31
# Set the view content with an h1 header
24
32
Set-VSCodeHtmlContentView -HtmlContentView $htmlContentView -HtmlBodyContent "<h1>Hello world!</h1>"
@@ -39,10 +47,23 @@ function Set-VSCodeHtmlContentView {
39
47
[Alias (" Content" )]
40
48
[AllowEmptyString ()]
41
49
[string ]
42
- $HtmlBodyContent
50
+ $HtmlBodyContent ,
51
+
52
+ [Parameter (Mandatory = $false )]
53
+ [string []]
54
+ $JavaScriptPaths ,
55
+
56
+ [Parameter (Mandatory = $false )]
57
+ [string []]
58
+ $StyleSheetPaths
43
59
)
44
60
45
61
process {
46
- $HtmlContentView.SetContent ($HtmlBodyContent ).Wait();
62
+ $htmlContent = New-Object Microsoft.PowerShell.EditorServices.VSCode.CustomViews.HtmlContent
63
+ $htmlContent.BodyContent = $HtmlBodyContent
64
+ $htmlContent.JavaScriptPaths = $JavaScriptPaths
65
+ $htmlContent.StyleSheetPaths = $StyleSheetPaths
66
+
67
+ $HtmlContentView.SetContent ($htmlContent ).Wait();
47
68
}
48
69
}
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright (c) Microsoft. All rights reserved.
3
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
+ //
5
+
6
+ namespace Microsoft . PowerShell . EditorServices . VSCode . CustomViews
7
+ {
8
+ /// <summary>
9
+ /// Contains details about the HTML content to be
10
+ /// displayed in an IHtmlContentView.
11
+ /// </summary>
12
+ public class HtmlContent
13
+ {
14
+ /// <summary>
15
+ /// Gets or sets the HTML body content.
16
+ /// </summary>
17
+ public string BodyContent { get ; set ; }
18
+
19
+ /// <summary>
20
+ /// Gets or sets the array of JavaScript file paths
21
+ /// to be used in the HTML content.
22
+ /// </summary>
23
+ public string [ ] JavaScriptPaths { get ; set ; }
24
+
25
+ /// <summary>
26
+ /// Gets or sets the array of stylesheet (CSS) file
27
+ /// paths to be used in the HTML content.
28
+ /// </summary>
29
+ public string [ ] StyleSheetPaths { get ; set ; }
30
+ }
31
+ }
Original file line number Diff line number Diff line change 4
4
//
5
5
6
6
using System ;
7
+ using System . IO ;
8
+ using System . Linq ;
7
9
using System . Threading . Tasks ;
8
10
using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol ;
9
11
using Microsoft . PowerShell . EditorServices . Utility ;
@@ -32,7 +34,27 @@ public Task SetContent(string htmlBodyContent)
32
34
new SetHtmlContentViewRequest
33
35
{
34
36
Id = this . Id ,
35
- HtmlBodyContent = htmlBodyContent
37
+ HtmlContent = new HtmlContent { BodyContent = htmlBodyContent }
38
+ } , true ) ;
39
+ }
40
+
41
+ public Task SetContent ( HtmlContent htmlContent )
42
+ {
43
+ HtmlContent validatedContent =
44
+ new HtmlContent ( )
45
+ {
46
+ BodyContent = htmlContent . BodyContent ,
47
+ JavaScriptPaths = this . GetUriPaths ( htmlContent . JavaScriptPaths ) ,
48
+ StyleSheetPaths = this . GetUriPaths ( htmlContent . StyleSheetPaths )
49
+ } ;
50
+
51
+ return
52
+ this . messageSender . SendRequest (
53
+ SetHtmlContentViewRequest . Type ,
54
+ new SetHtmlContentViewRequest
55
+ {
56
+ Id = this . Id ,
57
+ HtmlContent = validatedContent
36
58
} , true ) ;
37
59
}
38
60
@@ -47,5 +69,18 @@ public Task AppendContent(string appendedHtmlBodyContent)
47
69
AppendedHtmlBodyContent = appendedHtmlBodyContent
48
70
} , true ) ;
49
71
}
72
+
73
+ private string [ ] GetUriPaths ( string [ ] filePaths )
74
+ {
75
+ return
76
+ filePaths ?
77
+ . Select ( p => {
78
+ return
79
+ new Uri (
80
+ Path . GetFullPath ( p ) ,
81
+ UriKind . Absolute ) . ToString ( ) ;
82
+ } )
83
+ . ToArray ( ) ;
84
+ }
50
85
}
51
86
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public static readonly
28
28
/// <summary>
29
29
/// Gets or sets the HTML body content to set in the view.
30
30
/// </summary>
31
- public string HtmlBodyContent { get ; set ; }
31
+ public HtmlContent HtmlContent { get ; set ; }
32
32
}
33
33
34
34
/// <summary>
Original file line number Diff line number Diff line change @@ -23,6 +23,15 @@ public interface IHtmlContentView : ICustomView
23
23
/// <returns>A Task which can be awaited for completion.</returns>
24
24
Task SetContent ( string htmlBodyContent ) ;
25
25
26
+ /// <summary>
27
+ /// Sets the HTML content of the view.
28
+ /// </summary>
29
+ /// <param name="htmlContent">
30
+ /// The HTML content that is placed inside of the page's body tag.
31
+ /// </param>
32
+ /// <returns>A Task which can be awaited for completion.</returns>
33
+ Task SetContent ( HtmlContent htmlContent ) ;
34
+
26
35
/// <summary>
27
36
/// Appends HTML body content to the view.
28
37
/// </summary>
You can’t perform that action at this time.
0 commit comments