Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/test/engine.test.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as assert from 'assert';
7
import 'mocha';
8
import * as vscode from 'vscode';
9
import { InMemoryDocument } from '../client/inMemoryDocument';
10
import { createNewMarkdownEngine } from './engine';
11
12
13
const testFileName = vscode.Uri.file('test.md');
14
15
suite('markdown.engine', () => {
16
suite('rendering', () => {
17
const input = '# hello\n\nworld!';
18
const output = '<h1 data-line="0" class="code-line" dir="auto" id="hello">hello</h1>\n'
19
+ '<p data-line="2" class="code-line" dir="auto">world!</p>\n';
20
21
test('Renders a document', async () => {
22
const doc = new InMemoryDocument(testFileName, input);
23
const engine = createNewMarkdownEngine();
24
assert.strictEqual((await engine.render(doc)).html, output);
25
});
26
27
test('Renders a string', async () => {
28
const engine = createNewMarkdownEngine();
29
assert.strictEqual((await engine.render(input)).html, output);
30
});
31
});
32
33
suite('image-caching', () => {
34
const input = '![](img.png) [](no-img.png) ![](http://example.org/img.png) ![](img.png) ![](./img2.png)';
35
36
test('Extracts all images', async () => {
37
const engine = createNewMarkdownEngine();
38
const result = await engine.render(input);
39
assert.deepStrictEqual(result.html,
40
'<p data-line="0" class="code-line" dir="auto">'
41
+ '<img src="img.png" alt="" data-src="img.png"> '
42
+ '<a href="no-img.png" data-href="no-img.png"></a> '
43
+ '<img src="http://example.org/img.png" alt="" data-src="http://example.org/img.png"> '
44
+ '<img src="img.png" alt="" data-src="img.png"> '
45
+ '<img src="./img2.png" alt="" data-src="./img2.png">'
46
+ '</p>\n'
47
);
48
49
assert.deepStrictEqual([...result.containingImages], ['img.png', 'http://example.org/img.png', './img2.png']);
50
});
51
});
52
});
53
54