This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
markdown.ts
90 lines (80 loc) · 2.13 KB
/
markdown.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* This file is part of the vscode-powertools distribution.
* Copyright (c) Next.e.GO Mobile SE, Aachen, Germany (https://www.e-go-mobile.com/)
*
* vscode-powertools is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* vscode-powertools is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as ego_helpers from './helpers';
import * as ego_webview from './webview';
/**
* Options for the constructor of ''MarkdownWebView class.
*/
export interface MarkdownWebViewOptions {
/**
* Display in full page with or not.
*/
fullWidth?: boolean;
/**
* The markdown content.
*/
markdown: any;
/**
* The optional title.
*/
title?: any;
}
/**
* A web view showing a markdown document.
*/
export class MarkdownWebView extends ego_webview.WebViewBase {
/**
* Initializes a new instance of that class.
*
* @param {MarkdownWebViewOptions} options The options.
*/
public constructor(
public readonly options: MarkdownWebViewOptions,
) {
super();
}
/**
* @inheritdoc
*/
protected generateHtmlBody(): string {
return `
<script type="text/javascript">
const EGO_FULL_WIDTH = ${ JSON.stringify(
ego_helpers.toBooleanSafe(this.options.fullWidth)
) };
const EGO_MARKDOWN_CONTENT = ${ JSON.stringify(
ego_helpers.toStringSafe(this.options.markdown)
) };
</script>
`;
}
/**
* @inheritdoc
*/
protected getTitle(): string {
return ego_helpers.toStringSafe(
this.options
.title
);
}
/**
* @inheritdoc
*/
protected getType(): string {
return 'MarkdownDocument';
}
}