@theia/preview 1.45.0 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -45
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +29 -29
- package/lib/browser/markdown/index.d.ts +1 -1
- package/lib/browser/markdown/index.js +28 -28
- package/lib/browser/markdown/markdown-preview-handler.d.ts +28 -28
- package/lib/browser/markdown/markdown-preview-handler.js +301 -301
- package/lib/browser/markdown/markdown-preview-handler.spec.d.ts +1 -1
- package/lib/browser/markdown/markdown-preview-handler.spec.js +193 -193
- package/lib/browser/preview-contribution.d.ts +50 -50
- package/lib/browser/preview-contribution.js +262 -262
- package/lib/browser/preview-frontend-module.d.ts +5 -5
- package/lib/browser/preview-frontend-module.js +52 -52
- package/lib/browser/preview-handler.d.ts +104 -104
- package/lib/browser/preview-handler.js +76 -76
- package/lib/browser/preview-link-normalizer.d.ts +7 -7
- package/lib/browser/preview-link-normalizer.js +54 -54
- package/lib/browser/preview-preferences.d.ts +11 -11
- package/lib/browser/preview-preferences.js +46 -46
- package/lib/browser/preview-uri.d.ts +8 -8
- package/lib/browser/preview-uri.js +47 -47
- package/lib/browser/preview-widget.d.ts +54 -54
- package/lib/browser/preview-widget.js +261 -261
- package/lib/package.spec.js +25 -25
- package/package.json +7 -7
- package/src/browser/index.ts +19 -19
- package/src/browser/markdown/index.ts +17 -17
- package/src/browser/markdown/markdown-preview-handler.spec.ts +228 -228
- package/src/browser/markdown/markdown-preview-handler.ts +309 -309
- package/src/browser/markdown/style/index.css +18 -18
- package/src/browser/markdown/style/markdown.css +203 -203
- package/src/browser/markdown/style/tomorrow.css +105 -105
- package/src/browser/preview-contribution.ts +276 -276
- package/src/browser/preview-frontend-module.ts +57 -57
- package/src/browser/preview-handler.ts +141 -141
- package/src/browser/preview-link-normalizer.ts +40 -40
- package/src/browser/preview-preferences.ts +58 -58
- package/src/browser/preview-uri.ts +43 -43
- package/src/browser/preview-widget.ts +277 -277
- package/src/browser/style/index.css +17 -17
- package/src/browser/style/preview-widget.css +29 -29
- package/src/package.spec.ts +29 -29
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export * from './markdown-preview-handler';
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export * from './markdown-preview-handler';
|
|
@@ -1,228 +1,228 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
/* eslint-disable no-unsanitized/property */
|
|
18
|
-
|
|
19
|
-
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
20
|
-
|
|
21
|
-
let disableJSDOM = enableJSDOM();
|
|
22
|
-
|
|
23
|
-
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
24
|
-
FrontendApplicationConfigProvider.set({});
|
|
25
|
-
|
|
26
|
-
import * as chai from 'chai';
|
|
27
|
-
import { expect } from 'chai';
|
|
28
|
-
import URI from '@theia/core/lib/common/uri';
|
|
29
|
-
import { MarkdownPreviewHandler } from './markdown-preview-handler';
|
|
30
|
-
|
|
31
|
-
disableJSDOM();
|
|
32
|
-
|
|
33
|
-
chai.use(require('chai-string'));
|
|
34
|
-
|
|
35
|
-
let previewHandler: MarkdownPreviewHandler;
|
|
36
|
-
|
|
37
|
-
before(() => {
|
|
38
|
-
previewHandler = new MarkdownPreviewHandler();
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
(previewHandler as any).linkNormalizer = {
|
|
41
|
-
normalizeLink: (documentUri: URI, link: string) =>
|
|
42
|
-
'endpoint/' + documentUri.parent.resolve(link).path.toString().substring(1)
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('markdown-preview-handler', () => {
|
|
47
|
-
|
|
48
|
-
before(() => {
|
|
49
|
-
disableJSDOM = enableJSDOM();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
after(() => {
|
|
53
|
-
disableJSDOM();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('renders html with line information', async () => {
|
|
57
|
-
await assertRenderedContent(exampleMarkdown1, exampleHtml1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renders images', async () => {
|
|
61
|
-
await assertRenderedContent(exampleMarkdown2, exampleHtml2);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('renders HTML image as block', async () => {
|
|
65
|
-
await assertRenderedContent(exampleMarkdown3, exampleHtml3);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('renders HTML images inlined', async () => {
|
|
69
|
-
await assertRenderedContent(exampleMarkdown4, exampleHtml4);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('renders multiple HTML images in a html block', async () => {
|
|
73
|
-
await assertRenderedContent(exampleMarkdown5, exampleHtml5);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('finds element for source line', () => {
|
|
77
|
-
document.body.innerHTML = exampleHtml1;
|
|
78
|
-
const element = previewHandler.findElementForSourceLine(document.body, 4);
|
|
79
|
-
expect(element).not.to.be.equal(undefined);
|
|
80
|
-
expect(element!.tagName).to.be.equal('H2');
|
|
81
|
-
expect(element!.textContent).to.be.equal('License');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('finds previous element for empty source line', () => {
|
|
85
|
-
document.body.innerHTML = exampleHtml1;
|
|
86
|
-
const element = previewHandler.findElementForSourceLine(document.body, 3);
|
|
87
|
-
expect(element).not.to.be.equal(undefined);
|
|
88
|
-
expect(element!.tagName).to.be.equal('P');
|
|
89
|
-
expect(element!.textContent).that.startWith('Shows a preview of supported resources.');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('finds source line for offset in html', () => {
|
|
93
|
-
mockOffsetProperties();
|
|
94
|
-
document.body.innerHTML = exampleHtml1;
|
|
95
|
-
for (const expectedLine of [0, 1, 4, 5]) {
|
|
96
|
-
const line = previewHandler.getSourceLineForOffset(document.body, offsetForLine(expectedLine));
|
|
97
|
-
expect(line).to.be.equal(expectedLine);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('interpolates source lines for offset in html', () => {
|
|
102
|
-
mockOffsetProperties();
|
|
103
|
-
document.body.innerHTML = exampleHtml1;
|
|
104
|
-
const expectedLines = [1, 2, 3, 4];
|
|
105
|
-
const offsets = expectedLines.map(l => offsetForLine(l));
|
|
106
|
-
for (let i = 0; i < expectedLines.length; i++) {
|
|
107
|
-
const expectedLine = expectedLines[i];
|
|
108
|
-
const offset = offsets[i];
|
|
109
|
-
const line = previewHandler.getSourceLineForOffset(document.body, offset);
|
|
110
|
-
expect(line).to.be.equal(expectedLine);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('can handle \'.md\' files', () => {
|
|
115
|
-
expect(previewHandler.canHandle(new URI('a.md'))).greaterThan(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('can handle \'.markdown\' files', () => {
|
|
119
|
-
expect(previewHandler.canHandle(new URI('a.markdown'))).greaterThan(0);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
async function assertRenderedContent(source: string, expectation: string): Promise<void> {
|
|
124
|
-
const contentElement = previewHandler.renderContent({ content: source, originUri: new URI('file:///workspace/DEMO.md') });
|
|
125
|
-
expect(contentElement.innerHTML).equals(expectation);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const exampleMarkdown1 = //
|
|
129
|
-
`# Theia - Preview Extension
|
|
130
|
-
Shows a preview of supported resources.
|
|
131
|
-
See [here](https://github.com/eclipse-theia/theia).
|
|
132
|
-
|
|
133
|
-
## License
|
|
134
|
-
[Apache-2.0](https://github.com/eclipse-theia/theia/blob/master/LICENSE)
|
|
135
|
-
`;
|
|
136
|
-
|
|
137
|
-
const exampleHtml1 = //
|
|
138
|
-
`<h1 data-line="0" class="line" id="theia---preview-extension">Theia - Preview Extension</h1>
|
|
139
|
-
<p data-line="1" class="line">Shows a preview of supported resources.
|
|
140
|
-
See <a href="https://github.com/eclipse-theia/theia">here</a>.</p>
|
|
141
|
-
<h2 data-line="4" class="line" id="license">License</h2>
|
|
142
|
-
<p data-line="5" class="line"><a href="https://github.com/eclipse-theia/theia/blob/master/LICENSE">Apache-2.0</a></p>
|
|
143
|
-
`;
|
|
144
|
-
|
|
145
|
-
const exampleMarkdown2 = //
|
|
146
|
-
`# Heading
|
|
147
|
-

|
|
148
|
-
`;
|
|
149
|
-
|
|
150
|
-
const exampleHtml2 = //
|
|
151
|
-
`<h1 data-line="0" class="line" id="heading">Heading</h1>
|
|
152
|
-
<p data-line="1" class="line"><img alt="alternativetext" src="endpoint/workspace/subfolder/image.png"></p>
|
|
153
|
-
`;
|
|
154
|
-
|
|
155
|
-
const exampleMarkdown3 = //
|
|
156
|
-
`# Block HTML Image
|
|
157
|
-
<img src="subfolder/image1.png" alt="tada"/>
|
|
158
|
-
|
|
159
|
-
# Block HTML Image
|
|
160
|
-
<img src="subfolder/image3.png" alt="tada"/>
|
|
161
|
-
`;
|
|
162
|
-
|
|
163
|
-
const exampleHtml3 = //
|
|
164
|
-
`<h1 data-line="0" class="line" id="block-html-image">Block HTML Image</h1>
|
|
165
|
-
<img alt="tada" src="endpoint/workspace/subfolder/image1.png">
|
|
166
|
-
<h1 data-line="3" class="line" id="block-html-image-2">Block HTML Image</h1>
|
|
167
|
-
<img alt="tada" src="endpoint/workspace/subfolder/image3.png">
|
|
168
|
-
`;
|
|
169
|
-
|
|
170
|
-
const exampleMarkdown4 = //
|
|
171
|
-
`# Inlined HTML Image
|
|
172
|
-
text in paragraph <img src="subfolder/image2.png" alt="tada"/>
|
|
173
|
-
`;
|
|
174
|
-
|
|
175
|
-
const exampleHtml4 = //
|
|
176
|
-
`<h1 data-line="0" class="line" id="inlined-html-image">Inlined HTML Image</h1>
|
|
177
|
-
<p data-line="1" class="line">text in paragraph <img alt="tada" src="endpoint/workspace/subfolder/image2.png"></p>
|
|
178
|
-
`;
|
|
179
|
-
|
|
180
|
-
const exampleMarkdown5 = //
|
|
181
|
-
`# Multiple HTML Images nested in blocks
|
|
182
|
-
word <p>
|
|
183
|
-
<img src="subfolder/image2.png" alt="tada"/>
|
|
184
|
-
</p>
|
|
185
|
-
|
|
186
|
-
<p>
|
|
187
|
-
<img src="subfolder/image2.png" alt="tada"/>
|
|
188
|
-
</p>
|
|
189
|
-
`;
|
|
190
|
-
|
|
191
|
-
const exampleHtml5 = //
|
|
192
|
-
`<h1 data-line="0" class="line" id="multiple-html-images-nested-in-blocks">Multiple HTML Images nested in blocks</h1>
|
|
193
|
-
<p data-line="1" class="line">word </p><p>
|
|
194
|
-
<img alt="tada" src="endpoint/workspace/subfolder/image2.png"></p>
|
|
195
|
-
<p></p>
|
|
196
|
-
<p>
|
|
197
|
-
<img alt="tada" src="endpoint/workspace/subfolder/image2.png">
|
|
198
|
-
</p>
|
|
199
|
-
`;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* `offsetTop` of elements to be `sourceLine` number times `20`.
|
|
203
|
-
*/
|
|
204
|
-
function mockOffsetProperties(): void {
|
|
205
|
-
Object.defineProperties(HTMLElement.prototype, {
|
|
206
|
-
offsetLeft: {
|
|
207
|
-
get: () => 0
|
|
208
|
-
},
|
|
209
|
-
offsetTop: {
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
211
|
-
get: function (): any {
|
|
212
|
-
const element = this as HTMLElement;
|
|
213
|
-
const line = Number.parseInt(element.getAttribute('data-line') || '0');
|
|
214
|
-
return offsetForLine(line);
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
offsetHeight: {
|
|
218
|
-
get: () => 0
|
|
219
|
-
},
|
|
220
|
-
offsetWidth: {
|
|
221
|
-
get: () => 0
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function offsetForLine(line: number): number {
|
|
227
|
-
return line * 20;
|
|
228
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/* eslint-disable no-unsanitized/property */
|
|
18
|
+
|
|
19
|
+
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
20
|
+
|
|
21
|
+
let disableJSDOM = enableJSDOM();
|
|
22
|
+
|
|
23
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
24
|
+
FrontendApplicationConfigProvider.set({});
|
|
25
|
+
|
|
26
|
+
import * as chai from 'chai';
|
|
27
|
+
import { expect } from 'chai';
|
|
28
|
+
import URI from '@theia/core/lib/common/uri';
|
|
29
|
+
import { MarkdownPreviewHandler } from './markdown-preview-handler';
|
|
30
|
+
|
|
31
|
+
disableJSDOM();
|
|
32
|
+
|
|
33
|
+
chai.use(require('chai-string'));
|
|
34
|
+
|
|
35
|
+
let previewHandler: MarkdownPreviewHandler;
|
|
36
|
+
|
|
37
|
+
before(() => {
|
|
38
|
+
previewHandler = new MarkdownPreviewHandler();
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
(previewHandler as any).linkNormalizer = {
|
|
41
|
+
normalizeLink: (documentUri: URI, link: string) =>
|
|
42
|
+
'endpoint/' + documentUri.parent.resolve(link).path.toString().substring(1)
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('markdown-preview-handler', () => {
|
|
47
|
+
|
|
48
|
+
before(() => {
|
|
49
|
+
disableJSDOM = enableJSDOM();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
after(() => {
|
|
53
|
+
disableJSDOM();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders html with line information', async () => {
|
|
57
|
+
await assertRenderedContent(exampleMarkdown1, exampleHtml1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders images', async () => {
|
|
61
|
+
await assertRenderedContent(exampleMarkdown2, exampleHtml2);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders HTML image as block', async () => {
|
|
65
|
+
await assertRenderedContent(exampleMarkdown3, exampleHtml3);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders HTML images inlined', async () => {
|
|
69
|
+
await assertRenderedContent(exampleMarkdown4, exampleHtml4);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('renders multiple HTML images in a html block', async () => {
|
|
73
|
+
await assertRenderedContent(exampleMarkdown5, exampleHtml5);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('finds element for source line', () => {
|
|
77
|
+
document.body.innerHTML = exampleHtml1;
|
|
78
|
+
const element = previewHandler.findElementForSourceLine(document.body, 4);
|
|
79
|
+
expect(element).not.to.be.equal(undefined);
|
|
80
|
+
expect(element!.tagName).to.be.equal('H2');
|
|
81
|
+
expect(element!.textContent).to.be.equal('License');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('finds previous element for empty source line', () => {
|
|
85
|
+
document.body.innerHTML = exampleHtml1;
|
|
86
|
+
const element = previewHandler.findElementForSourceLine(document.body, 3);
|
|
87
|
+
expect(element).not.to.be.equal(undefined);
|
|
88
|
+
expect(element!.tagName).to.be.equal('P');
|
|
89
|
+
expect(element!.textContent).that.startWith('Shows a preview of supported resources.');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('finds source line for offset in html', () => {
|
|
93
|
+
mockOffsetProperties();
|
|
94
|
+
document.body.innerHTML = exampleHtml1;
|
|
95
|
+
for (const expectedLine of [0, 1, 4, 5]) {
|
|
96
|
+
const line = previewHandler.getSourceLineForOffset(document.body, offsetForLine(expectedLine));
|
|
97
|
+
expect(line).to.be.equal(expectedLine);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('interpolates source lines for offset in html', () => {
|
|
102
|
+
mockOffsetProperties();
|
|
103
|
+
document.body.innerHTML = exampleHtml1;
|
|
104
|
+
const expectedLines = [1, 2, 3, 4];
|
|
105
|
+
const offsets = expectedLines.map(l => offsetForLine(l));
|
|
106
|
+
for (let i = 0; i < expectedLines.length; i++) {
|
|
107
|
+
const expectedLine = expectedLines[i];
|
|
108
|
+
const offset = offsets[i];
|
|
109
|
+
const line = previewHandler.getSourceLineForOffset(document.body, offset);
|
|
110
|
+
expect(line).to.be.equal(expectedLine);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('can handle \'.md\' files', () => {
|
|
115
|
+
expect(previewHandler.canHandle(new URI('a.md'))).greaterThan(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('can handle \'.markdown\' files', () => {
|
|
119
|
+
expect(previewHandler.canHandle(new URI('a.markdown'))).greaterThan(0);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
async function assertRenderedContent(source: string, expectation: string): Promise<void> {
|
|
124
|
+
const contentElement = previewHandler.renderContent({ content: source, originUri: new URI('file:///workspace/DEMO.md') });
|
|
125
|
+
expect(contentElement.innerHTML).equals(expectation);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const exampleMarkdown1 = //
|
|
129
|
+
`# Theia - Preview Extension
|
|
130
|
+
Shows a preview of supported resources.
|
|
131
|
+
See [here](https://github.com/eclipse-theia/theia).
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
[Apache-2.0](https://github.com/eclipse-theia/theia/blob/master/LICENSE)
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
const exampleHtml1 = //
|
|
138
|
+
`<h1 data-line="0" class="line" id="theia---preview-extension">Theia - Preview Extension</h1>
|
|
139
|
+
<p data-line="1" class="line">Shows a preview of supported resources.
|
|
140
|
+
See <a href="https://github.com/eclipse-theia/theia">here</a>.</p>
|
|
141
|
+
<h2 data-line="4" class="line" id="license">License</h2>
|
|
142
|
+
<p data-line="5" class="line"><a href="https://github.com/eclipse-theia/theia/blob/master/LICENSE">Apache-2.0</a></p>
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
const exampleMarkdown2 = //
|
|
146
|
+
`# Heading
|
|
147
|
+

|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
const exampleHtml2 = //
|
|
151
|
+
`<h1 data-line="0" class="line" id="heading">Heading</h1>
|
|
152
|
+
<p data-line="1" class="line"><img alt="alternativetext" src="endpoint/workspace/subfolder/image.png"></p>
|
|
153
|
+
`;
|
|
154
|
+
|
|
155
|
+
const exampleMarkdown3 = //
|
|
156
|
+
`# Block HTML Image
|
|
157
|
+
<img src="subfolder/image1.png" alt="tada"/>
|
|
158
|
+
|
|
159
|
+
# Block HTML Image
|
|
160
|
+
<img src="subfolder/image3.png" alt="tada"/>
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
const exampleHtml3 = //
|
|
164
|
+
`<h1 data-line="0" class="line" id="block-html-image">Block HTML Image</h1>
|
|
165
|
+
<img alt="tada" src="endpoint/workspace/subfolder/image1.png">
|
|
166
|
+
<h1 data-line="3" class="line" id="block-html-image-2">Block HTML Image</h1>
|
|
167
|
+
<img alt="tada" src="endpoint/workspace/subfolder/image3.png">
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
const exampleMarkdown4 = //
|
|
171
|
+
`# Inlined HTML Image
|
|
172
|
+
text in paragraph <img src="subfolder/image2.png" alt="tada"/>
|
|
173
|
+
`;
|
|
174
|
+
|
|
175
|
+
const exampleHtml4 = //
|
|
176
|
+
`<h1 data-line="0" class="line" id="inlined-html-image">Inlined HTML Image</h1>
|
|
177
|
+
<p data-line="1" class="line">text in paragraph <img alt="tada" src="endpoint/workspace/subfolder/image2.png"></p>
|
|
178
|
+
`;
|
|
179
|
+
|
|
180
|
+
const exampleMarkdown5 = //
|
|
181
|
+
`# Multiple HTML Images nested in blocks
|
|
182
|
+
word <p>
|
|
183
|
+
<img src="subfolder/image2.png" alt="tada"/>
|
|
184
|
+
</p>
|
|
185
|
+
|
|
186
|
+
<p>
|
|
187
|
+
<img src="subfolder/image2.png" alt="tada"/>
|
|
188
|
+
</p>
|
|
189
|
+
`;
|
|
190
|
+
|
|
191
|
+
const exampleHtml5 = //
|
|
192
|
+
`<h1 data-line="0" class="line" id="multiple-html-images-nested-in-blocks">Multiple HTML Images nested in blocks</h1>
|
|
193
|
+
<p data-line="1" class="line">word </p><p>
|
|
194
|
+
<img alt="tada" src="endpoint/workspace/subfolder/image2.png"></p>
|
|
195
|
+
<p></p>
|
|
196
|
+
<p>
|
|
197
|
+
<img alt="tada" src="endpoint/workspace/subfolder/image2.png">
|
|
198
|
+
</p>
|
|
199
|
+
`;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* `offsetTop` of elements to be `sourceLine` number times `20`.
|
|
203
|
+
*/
|
|
204
|
+
function mockOffsetProperties(): void {
|
|
205
|
+
Object.defineProperties(HTMLElement.prototype, {
|
|
206
|
+
offsetLeft: {
|
|
207
|
+
get: () => 0
|
|
208
|
+
},
|
|
209
|
+
offsetTop: {
|
|
210
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
211
|
+
get: function (): any {
|
|
212
|
+
const element = this as HTMLElement;
|
|
213
|
+
const line = Number.parseInt(element.getAttribute('data-line') || '0');
|
|
214
|
+
return offsetForLine(line);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
offsetHeight: {
|
|
218
|
+
get: () => 0
|
|
219
|
+
},
|
|
220
|
+
offsetWidth: {
|
|
221
|
+
get: () => 0
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function offsetForLine(line: number): number {
|
|
227
|
+
return line * 20;
|
|
228
|
+
}
|