@theia/core 1.22.0-next.3 → 1.22.0-next.7

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 CHANGED
@@ -78,9 +78,9 @@ export class SomeClass {
78
78
  - [`@phosphor/signaling@1`](https://www.npmjs.com/package/@phosphor/signaling)
79
79
  - [`@phosphor/virtualdom@1`](https://www.npmjs.com/package/@phosphor/virtualdom)
80
80
  - [`@phosphor/widgets@1`](https://www.npmjs.com/package/@phosphor/widgets)
81
- - [`@theia/application-package@1.22.0-next.3+a59118db63d`](https://www.npmjs.com/package/@theia/application-package)
82
- - [`@theia/application-package/lib/api@1.22.0-next.3+a59118db63d`](https://www.npmjs.com/package/@theia/application-package)
83
- - [`@theia/application-package/lib/environment@1.22.0-next.3+a59118db63d`](https://www.npmjs.com/package/@theia/application-package)
81
+ - [`@theia/application-package@1.22.0-next.7+ff1121f7f2b`](https://www.npmjs.com/package/@theia/application-package)
82
+ - [`@theia/application-package/lib/api@1.22.0-next.7+ff1121f7f2b`](https://www.npmjs.com/package/@theia/application-package)
83
+ - [`@theia/application-package/lib/environment@1.22.0-next.7+ff1121f7f2b`](https://www.npmjs.com/package/@theia/application-package)
84
84
  - [`dompurify@^2.2.9`](https://www.npmjs.com/package/dompurify)
85
85
  - [`electron@^9.0.2`](https://www.npmjs.com/package/electron)
86
86
  - [`express@^4.16.3`](https://www.npmjs.com/package/express)
@@ -40,6 +40,5 @@ export * from './core-preferences';
40
40
  export * from './view-container';
41
41
  export * from './breadcrumbs';
42
42
  export * from './tooltip-service';
43
- export * from './markdown-renderer';
44
43
  export * from './decoration-style';
45
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,C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c,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
@@ -52,6 +52,5 @@ __exportStar(require("./core-preferences"), exports);
52
52
  __exportStar(require("./view-container"), exports);
53
53
  __exportStar(require("./breadcrumbs"), exports);
54
54
  __exportStar(require("./tooltip-service"), exports);
55
- __exportStar(require("./markdown-renderer"), exports);
56
55
  __exportStar(require("./decoration-style"), exports);
57
56
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,0CAAwB;AACxB,yDAAuC;AACvC,6CAA2B;AAC3B,mDAAiC;AACjC,4CAA0B;AAC1B,0DAAwC;AACxC,4CAA0B;AAC1B,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,6CAA2B;AAC3B,iEAA+C;AAC/C,gDAA8B;AAC9B,mDAAiC;AACjC,6CAA2B;AAC3B,oDAAkC;AAClC,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,mDAAiC;AACjC,wDAAsC;AACtC,gDAA8B;AAC9B,8CAA4B;AAC5B,qDAAmC;AACnC,mDAAiC;AACjC,gDAA8B;AAC9B,oDAAkC;AAClC,sDAAoC;AACpC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,0CAAwB;AACxB,yDAAuC;AACvC,6CAA2B;AAC3B,mDAAiC;AACjC,4CAA0B;AAC1B,0DAAwC;AACxC,4CAA0B;AAC1B,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,6CAA2B;AAC3B,iEAA+C;AAC/C,gDAA8B;AAC9B,mDAAiC;AACjC,6CAA2B;AAC3B,oDAAkC;AAClC,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,mDAAiC;AACjC,wDAAsC;AACtC,gDAA8B;AAC9B,8CAA4B;AAC5B,qDAAmC;AACnC,mDAAiC;AACjC,gDAA8B;AAC9B,oDAAkC;AAClC,qDAAmC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/core",
3
- "version": "1.22.0-next.3+a59118db63d",
3
+ "version": "1.22.0-next.7+ff1121f7f2b",
4
4
  "description": "Theia is a cloud & desktop IDE framework implemented in TypeScript.",
5
5
  "main": "lib/common/index.js",
6
6
  "typings": "lib/common/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "@phosphor/virtualdom": "1",
18
18
  "@phosphor/widgets": "1",
19
19
  "@primer/octicons-react": "^9.0.0",
20
- "@theia/application-package": "1.22.0-next.3+a59118db63d",
20
+ "@theia/application-package": "1.22.0-next.7+ff1121f7f2b",
21
21
  "@types/body-parser": "^1.16.4",
22
22
  "@types/cookie": "^0.3.3",
23
23
  "@types/dompurify": "^2.2.2",
@@ -178,5 +178,5 @@
178
178
  "nyc": {
179
179
  "extends": "../../configs/nyc.json"
180
180
  },
181
- "gitHead": "a59118db63d9de9765b4e5ce6264f9eb1bd6904e"
181
+ "gitHead": "ff1121f7f2b42324ded29d8ef70838cb0941083d"
182
182
  }
@@ -41,5 +41,4 @@ export * from './core-preferences';
41
41
  export * from './view-container';
42
42
  export * from './breadcrumbs';
43
43
  export * from './tooltip-service';
44
- export * from './markdown-renderer';
45
44
  export * from './decoration-style';
@@ -1,33 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2021 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import * as markdownit from 'markdown-it';
17
- export declare class MarkdownRenderer {
18
- protected engine: markdownit;
19
- protected callbacks: Map<string, ((element: Element) => Element | void)[]>;
20
- constructor(engine?: markdownit);
21
- /**
22
- * Adds a modification callback that is applied to every element with the specified tag after rendering to HTML.
23
- *
24
- * @param tag The tag that this modification applies to.
25
- * @param callback The modification to apply on every selected rendered element. Can either modify the element in place or return a new element.
26
- */
27
- modify<K extends keyof HTMLElementTagNameMap>(tag: K, callback: (element: HTMLElementTagNameMap[K]) => Element | void): MarkdownRenderer;
28
- render(markdown: string): HTMLElement;
29
- renderInline(markdown: string): HTMLElement;
30
- protected renderInternal(renderedHtml: string): HTMLElement;
31
- protected sanitizeHtml(html: string): HTMLElement;
32
- }
33
- //# sourceMappingURL=markdown-renderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-renderer.d.ts","sourceRoot":"","sources":["../../src/browser/markdown-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAGlF,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAE1C,qBAAa,gBAAgB;IAEzB,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,SAAS,yBAA8B,OAAO,KAAK,OAAO,GAAG,IAAI,KAAO;gBAEtE,MAAM,CAAC,EAAE,UAAU;IAI/B;;;;;OAKG;IACH,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI,GAAG,gBAAgB;IASxI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW;IAIrC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW;IAI3C,SAAS,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW;IAmB3D,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;CAKpD"}
@@ -1,72 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (C) 2021 TypeFox and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.MarkdownRenderer = void 0;
19
- const DOMPurify = require("dompurify");
20
- const markdownit = require("markdown-it");
21
- class MarkdownRenderer {
22
- constructor(engine) {
23
- this.callbacks = new Map();
24
- this.engine = engine !== null && engine !== void 0 ? engine : markdownit();
25
- }
26
- /**
27
- * Adds a modification callback that is applied to every element with the specified tag after rendering to HTML.
28
- *
29
- * @param tag The tag that this modification applies to.
30
- * @param callback The modification to apply on every selected rendered element. Can either modify the element in place or return a new element.
31
- */
32
- modify(tag, callback) {
33
- if (this.callbacks.has(tag)) {
34
- this.callbacks.get(tag).push(callback);
35
- }
36
- else {
37
- this.callbacks.set(tag, [callback]);
38
- }
39
- return this;
40
- }
41
- render(markdown) {
42
- return this.renderInternal(this.engine.render(markdown));
43
- }
44
- renderInline(markdown) {
45
- return this.renderInternal(this.engine.renderInline(markdown));
46
- }
47
- renderInternal(renderedHtml) {
48
- const div = this.sanitizeHtml(renderedHtml);
49
- for (const [tag, calls] of this.callbacks) {
50
- for (const callback of calls) {
51
- const elements = Array.from(div.getElementsByTagName(tag));
52
- for (const element of elements) {
53
- const result = callback(element);
54
- if (result) {
55
- const parent = element.parentElement;
56
- if (parent) {
57
- parent.replaceChild(result, element);
58
- }
59
- }
60
- }
61
- }
62
- }
63
- return div;
64
- }
65
- sanitizeHtml(html) {
66
- const div = document.createElement('div');
67
- div.innerHTML = DOMPurify.sanitize(html);
68
- return div;
69
- }
70
- }
71
- exports.MarkdownRenderer = MarkdownRenderer;
72
- //# sourceMappingURL=markdown-renderer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-renderer.js","sourceRoot":"","sources":["../../src/browser/markdown-renderer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,uCAAuC;AACvC,0CAA0C;AAE1C,MAAa,gBAAgB;IAKzB,YAAY,MAAmB;QAFrB,cAAS,GAAG,IAAI,GAAG,EAAoD,CAAC;QAG9E,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,UAAU,EAAE,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAwC,GAAM,EAAE,QAA+D;QACjH,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACzB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC3C;aAAM;YACH,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;SACvC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,QAAgB;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,YAAY,CAAC,QAAgB;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnE,CAAC;IAES,cAAc,CAAC,YAAoB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE;YACvC,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;gBAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC3D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;oBAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;oBACjC,IAAI,MAAM,EAAE;wBACR,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;wBACrC,IAAI,MAAM,EAAE;4BACR,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;yBACxC;qBACJ;iBACJ;aACJ;SACJ;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAES,YAAY,CAAC,IAAY;QAC/B,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAxDD,4CAwDC"}
@@ -1,17 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2021 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- export {};
17
- //# sourceMappingURL=markdown-renderer.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-renderer.spec.d.ts","sourceRoot":"","sources":["../../src/browser/markdown-renderer.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF"}
@@ -1,71 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (C) 2021 TypeFox and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const jsdom_1 = require("../browser/test/jsdom");
19
- let disableJSDOM = jsdom_1.enableJSDOM();
20
- const chai_1 = require("chai");
21
- const markdownit = require("markdown-it");
22
- const markdown_renderer_1 = require("./markdown-renderer");
23
- disableJSDOM();
24
- describe('MarkdownRenderer', () => {
25
- before(() => disableJSDOM = jsdom_1.enableJSDOM());
26
- after(() => disableJSDOM());
27
- it('Should render markdown', () => {
28
- const markdownRenderer = new markdown_renderer_1.MarkdownRenderer();
29
- const result = markdownRenderer.renderInline('[title](link)').innerHTML;
30
- chai_1.expect(result).to.be.equal('<a href="link">title</a>');
31
- });
32
- it('Should accept and use custom engine', () => {
33
- const engine = markdownit();
34
- const originalTextRenderer = engine.renderer.rules.text;
35
- engine.renderer.rules.text = (tokens, idx, options, env, self) => `[${originalTextRenderer(tokens, idx, options, env, self)}]`;
36
- const markdownRenderer = new markdown_renderer_1.MarkdownRenderer(engine);
37
- const result = markdownRenderer.renderInline('text').innerHTML;
38
- chai_1.expect(result).to.be.equal('[text]');
39
- });
40
- it('Should modify rendered markdown in place', () => {
41
- const markdownRenderer = new markdown_renderer_1.MarkdownRenderer().modify('a', a => {
42
- a.href = 'something-else';
43
- });
44
- const result = markdownRenderer.renderInline('[title](link)').innerHTML;
45
- chai_1.expect(result).to.be.equal('<a href="something-else">title</a>');
46
- });
47
- it('Should modify descendants of children', () => {
48
- const markdownRenderer = new markdown_renderer_1.MarkdownRenderer().modify('em', em => {
49
- const strong = document.createElement('strong');
50
- // eslint-disable-next-line no-unsanitized/property
51
- strong.innerHTML = em.innerHTML;
52
- return strong;
53
- });
54
- const result = markdownRenderer.render('**bold *bold and italic***').innerHTML;
55
- chai_1.expect(result).to.be.equal('<p><strong>bold <strong>bold and italic</strong></strong></p>\n');
56
- });
57
- it('Should modify descendants of children after previous modification', () => {
58
- const markdownRenderer = new markdown_renderer_1.MarkdownRenderer().modify('em', em => {
59
- const strong = document.createElement('strong');
60
- // eslint-disable-next-line no-unsanitized/property
61
- strong.innerHTML = em.innerHTML;
62
- return strong;
63
- }).modify('strong', strong => {
64
- const textNode = strong.childNodes.item(0);
65
- textNode.textContent = `changed_${textNode.textContent}`;
66
- });
67
- const result = markdownRenderer.render('**bold *bold and italic***').innerHTML;
68
- chai_1.expect(result).to.be.equal('<p><strong>changed_bold <strong>changed_bold and italic</strong></strong></p>\n');
69
- });
70
- });
71
- //# sourceMappingURL=markdown-renderer.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-renderer.spec.js","sourceRoot":"","sources":["../../src/browser/markdown-renderer.spec.ts"],"names":[],"mapp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AM,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;YAChC,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3C,QAAQ,CAAC,WAAW,GAAG,WAAW,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC7D,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,SAAS,CAAC;QAC/E,aAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,iFAAiF,CAAC,CAAC;IAClH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,78 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2021 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import { enableJSDOM } from '../browser/test/jsdom';
18
- let disableJSDOM = enableJSDOM();
19
-
20
- import { expect } from 'chai';
21
- import * as markdownit from 'markdown-it';
22
- import { MarkdownRenderer } from './markdown-renderer';
23
-
24
- disableJSDOM();
25
-
26
- describe('MarkdownRenderer', () => {
27
-
28
- before(() => disableJSDOM = enableJSDOM());
29
- after(() => disableJSDOM());
30
-
31
- it('Should render markdown', () => {
32
- const markdownRenderer = new MarkdownRenderer();
33
- const result = markdownRenderer.renderInline('[title](link)').innerHTML;
34
- expect(result).to.be.equal('<a href="link">title</a>');
35
- });
36
-
37
- it('Should accept and use custom engine', () => {
38
- const engine = markdownit();
39
- const originalTextRenderer = engine.renderer.rules.text!;
40
- engine.renderer.rules.text = (tokens, idx, options, env, self) => `[${originalTextRenderer(tokens, idx, options, env, self)}]`;
41
- const markdownRenderer = new MarkdownRenderer(engine);
42
- const result = markdownRenderer.renderInline('text').innerHTML;
43
- expect(result).to.be.equal('[text]');
44
- });
45
-
46
- it('Should modify rendered markdown in place', () => {
47
- const markdownRenderer = new MarkdownRenderer().modify('a', a => {
48
- a.href = 'something-else';
49
- });
50
- const result = markdownRenderer.renderInline('[title](link)').innerHTML;
51
- expect(result).to.be.equal('<a href="something-else">title</a>');
52
- });
53
-
54
- it('Should modify descendants of children', () => {
55
- const markdownRenderer = new MarkdownRenderer().modify('em', em => {
56
- const strong = document.createElement('strong');
57
- // eslint-disable-next-line no-unsanitized/property
58
- strong.innerHTML = em.innerHTML;
59
- return strong;
60
- });
61
- const result = markdownRenderer.render('**bold *bold and italic***').innerHTML;
62
- expect(result).to.be.equal('<p><strong>bold <strong>bold and italic</strong></strong></p>\n');
63
- });
64
-
65
- it('Should modify descendants of children after previous modification', () => {
66
- const markdownRenderer = new MarkdownRenderer().modify('em', em => {
67
- const strong = document.createElement('strong');
68
- // eslint-disable-next-line no-unsanitized/property
69
- strong.innerHTML = em.innerHTML;
70
- return strong;
71
- }).modify('strong', strong => { // Will pick up both the original and modified strong element
72
- const textNode = strong.childNodes.item(0);
73
- textNode.textContent = `changed_${textNode.textContent}`;
74
- });
75
- const result = markdownRenderer.render('**bold *bold and italic***').innerHTML;
76
- expect(result).to.be.equal('<p><strong>changed_bold <strong>changed_bold and italic</strong></strong></p>\n');
77
- });
78
- });
@@ -1,76 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2021 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import * as DOMPurify from 'dompurify';
18
- import * as markdownit from 'markdown-it';
19
-
20
- export class MarkdownRenderer {
21
-
22
- protected engine: markdownit;
23
- protected callbacks = new Map<string, ((element: Element) => Element | void)[]>();
24
-
25
- constructor(engine?: markdownit) {
26
- this.engine = engine ?? markdownit();
27
- }
28
-
29
- /**
30
- * Adds a modification callback that is applied to every element with the specified tag after rendering to HTML.
31
- *
32
- * @param tag The tag that this modification applies to.
33
- * @param callback The modification to apply on every selected rendered element. Can either modify the element in place or return a new element.
34
- */
35
- modify<K extends keyof HTMLElementTagNameMap>(tag: K, callback: (element: HTMLElementTagNameMap[K]) => Element | void): MarkdownRenderer {
36
- if (this.callbacks.has(tag)) {
37
- this.callbacks.get(tag)!.push(callback);
38
- } else {
39
- this.callbacks.set(tag, [callback]);
40
- }
41
- return this;
42
- }
43
-
44
- render(markdown: string): HTMLElement {
45
- return this.renderInternal(this.engine.render(markdown));
46
- }
47
-
48
- renderInline(markdown: string): HTMLElement {
49
- return this.renderInternal(this.engine.renderInline(markdown));
50
- }
51
-
52
- protected renderInternal(renderedHtml: string): HTMLElement {
53
- const div = this.sanitizeHtml(renderedHtml);
54
- for (const [tag, calls] of this.callbacks) {
55
- for (const callback of calls) {
56
- const elements = Array.from(div.getElementsByTagName(tag));
57
- for (const element of elements) {
58
- const result = callback(element);
59
- if (result) {
60
- const parent = element.parentElement;
61
- if (parent) {
62
- parent.replaceChild(result, element);
63
- }
64
- }
65
- }
66
- }
67
- }
68
- return div;
69
- }
70
-
71
- protected sanitizeHtml(html: string): HTMLElement {
72
- const div = document.createElement('div');
73
- div.innerHTML = DOMPurify.sanitize(html);
74
- return div;
75
- }
76
- }