@theia/core 1.21.0 → 1.22.0-next.12
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 +3 -3
- package/lib/browser/common-frontend-contribution.d.ts +8 -0
- package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/common-frontend-contribution.js +48 -11
- package/lib/browser/common-frontend-contribution.js.map +1 -1
- package/lib/browser/context-key-service.d.ts +46 -3
- package/lib/browser/context-key-service.d.ts.map +1 -1
- package/lib/browser/context-key-service.js +24 -5
- package/lib/browser/context-key-service.js.map +1 -1
- package/lib/browser/frontend-application-module.js +1 -1
- package/lib/browser/frontend-application-module.js.map +1 -1
- package/lib/browser/index.d.ts +0 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +0 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/keybinding.js +1 -1
- package/lib/browser/keybinding.js.map +1 -1
- package/lib/browser/keybinding.spec.js +1 -1
- package/lib/browser/keybinding.spec.js.map +1 -1
- package/lib/browser/menu/browser-menu-plugin.js +1 -1
- package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
- package/lib/browser/quick-input/quick-command-service.js +1 -1
- package/lib/browser/quick-input/quick-command-service.js.map +1 -1
- package/lib/browser/quick-input/quick-view-service.js +1 -1
- package/lib/browser/quick-input/quick-view-service.js.map +1 -1
- package/lib/browser/resource-context-key.js +1 -1
- package/lib/browser/resource-context-key.js.map +1 -1
- package/lib/browser/shell/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +14 -11
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar.js +1 -1
- package/lib/browser/shell/tab-bar-toolbar.js.map +1 -1
- package/lib/browser/tree/tree-view-welcome-widget.js +1 -1
- package/lib/browser/tree/tree-view-welcome-widget.js.map +1 -1
- package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-menu-contribution.js +6 -1
- package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
- package/package.json +3 -3
- package/src/browser/common-frontend-contribution.ts +47 -12
- package/src/browser/context-key-service.ts +60 -2
- package/src/browser/frontend-application-module.ts +2 -2
- package/src/browser/index.ts +0 -1
- package/src/browser/keybinding.spec.ts +2 -2
- package/src/browser/shell/application-shell.ts +13 -10
- package/src/electron-browser/menu/electron-menu-contribution.ts +6 -1
- package/lib/browser/markdown-renderer.d.ts +0 -33
- package/lib/browser/markdown-renderer.d.ts.map +0 -1
- package/lib/browser/markdown-renderer.js +0 -72
- package/lib/browser/markdown-renderer.js.map +0 -1
- package/lib/browser/markdown-renderer.spec.d.ts +0 -17
- package/lib/browser/markdown-renderer.spec.d.ts.map +0 -1
- package/lib/browser/markdown-renderer.spec.js +0 -71
- package/lib/browser/markdown-renderer.spec.js.map +0 -1
- package/src/browser/markdown-renderer.spec.ts +0 -78
- package/src/browser/markdown-renderer.ts +0 -76
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
|
|
17
17
|
import { injectable } from 'inversify';
|
|
18
|
-
import {
|
|
18
|
+
import { Disposable } from '../common';
|
|
19
|
+
import { Emitter, Event } from '../common/event';
|
|
19
20
|
|
|
20
21
|
export interface ContextKey<T> {
|
|
21
22
|
set(value: T | undefined): void;
|
|
@@ -36,8 +37,44 @@ export interface ContextKeyChangeEvent {
|
|
|
36
37
|
affects(keys: Set<string>): boolean;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
export const ContextKeyService = Symbol('ContextKeyService');
|
|
41
|
+
export interface ContextKeyService extends Disposable {
|
|
42
|
+
readonly onDidChange: Event<ContextKeyChangeEvent>;
|
|
43
|
+
|
|
44
|
+
createKey<T>(key: string, defaultValue: T | undefined): ContextKey<T>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether the expression is satisfied. If `context` provided, the service will attempt to retrieve a context object associated with that element.
|
|
48
|
+
*/
|
|
49
|
+
match(expression: string, context?: HTMLElement): boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @returns a Set of the keys used by the given `expression` or `undefined` if none are used or the expression cannot be parsed.
|
|
53
|
+
*/
|
|
54
|
+
parseKeys(expression: string): Set<string> | undefined;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a temporary context that will use the `values` passed in when evaluating `callback`
|
|
58
|
+
* `callback` must be synchronous.
|
|
59
|
+
*/
|
|
60
|
+
with<T>(values: Record<string, unknown>, callback: () => T): T;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a child service with a separate context scoped to the HTML element passed in.
|
|
64
|
+
* Useful for e.g. setting the {view} context value for particular widgets.
|
|
65
|
+
*/
|
|
66
|
+
createScoped(target?: HTMLElement): ScopedValueStore;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set or modify a value in the service's context.
|
|
70
|
+
*/
|
|
71
|
+
setContext(key: string, value: unknown): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type ScopedValueStore = Omit<ContextKeyService, 'onDidChange' | 'match' | 'parseKeys' | 'with'>;
|
|
75
|
+
|
|
39
76
|
@injectable()
|
|
40
|
-
export class ContextKeyService {
|
|
77
|
+
export class ContextKeyServiceDummyImpl implements ContextKeyService {
|
|
41
78
|
|
|
42
79
|
protected readonly onDidChangeEmitter = new Emitter<ContextKeyChangeEvent>();
|
|
43
80
|
readonly onDidChange = this.onDidChangeEmitter.event;
|
|
@@ -62,4 +99,25 @@ export class ContextKeyService {
|
|
|
62
99
|
return new Set<string>();
|
|
63
100
|
}
|
|
64
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Details should be implemented by an extension, e.g. by the monaco extension.
|
|
104
|
+
* Callback must be synchronous.
|
|
105
|
+
*/
|
|
106
|
+
with<T>(values: Record<string, unknown>, callback: () => T): T {
|
|
107
|
+
return callback();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Details should implemented by an extension, e.g. by the monaco extension.
|
|
112
|
+
*/
|
|
113
|
+
createScoped(target?: HTMLElement): ContextKeyService {
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Details should be implemented by an extension, e.g. by the monaco extension.
|
|
119
|
+
*/
|
|
120
|
+
setContext(key: string, value: unknown): void { }
|
|
121
|
+
|
|
122
|
+
dispose(): void { }
|
|
65
123
|
}
|
|
@@ -62,7 +62,7 @@ import { FrontendApplicationStateService } from './frontend-application-state';
|
|
|
62
62
|
import { JsonSchemaStore, JsonSchemaContribution, DefaultJsonSchemaContribution } from './json-schema-store';
|
|
63
63
|
import { TabBarToolbarRegistry, TabBarToolbarContribution, TabBarToolbarFactory, TabBarToolbar } from './shell/tab-bar-toolbar';
|
|
64
64
|
import { bindCorePreferences } from './core-preferences';
|
|
65
|
-
import { ContextKeyService } from './context-key-service';
|
|
65
|
+
import { ContextKeyService, ContextKeyServiceDummyImpl } from './context-key-service';
|
|
66
66
|
import { ResourceContextKey } from './resource-context-key';
|
|
67
67
|
import { KeyboardLayoutService } from './keyboard/keyboard-layout-service';
|
|
68
68
|
import { MimeService } from './mime-service';
|
|
@@ -221,7 +221,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
|
|
|
221
221
|
bind(CommandService).toService(CommandRegistry);
|
|
222
222
|
bindContributionProvider(bind, CommandContribution);
|
|
223
223
|
|
|
224
|
-
bind(ContextKeyService).
|
|
224
|
+
bind(ContextKeyService).to(ContextKeyServiceDummyImpl).inSingletonScope();
|
|
225
225
|
|
|
226
226
|
bind(MenuModelRegistry).toSelf().inSingletonScope();
|
|
227
227
|
bindContributionProvider(bind, MenuContribution);
|
package/src/browser/index.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { LabelParser } from './label-parser';
|
|
|
30
30
|
import { MockLogger } from '../common/test/mock-logger';
|
|
31
31
|
import { StatusBar, StatusBarImpl } from './status-bar/status-bar';
|
|
32
32
|
import { FrontendApplicationStateService } from './frontend-application-state';
|
|
33
|
-
import { ContextKeyService } from './context-key-service';
|
|
33
|
+
import { ContextKeyService, ContextKeyServiceDummyImpl } from './context-key-service';
|
|
34
34
|
import { CorePreferences } from './core-preferences';
|
|
35
35
|
import * as os from '../common/os';
|
|
36
36
|
import * as chai from 'chai';
|
|
@@ -87,7 +87,7 @@ before(async () => {
|
|
|
87
87
|
bind(StatusBar).toService(StatusBarImpl);
|
|
88
88
|
bind(CommandService).toService(CommandRegistry);
|
|
89
89
|
bind(LabelParser).toSelf().inSingletonScope();
|
|
90
|
-
bind(ContextKeyService).
|
|
90
|
+
bind(ContextKeyService).to(ContextKeyServiceDummyImpl).inSingletonScope();
|
|
91
91
|
bind(FrontendApplicationStateService).toSelf().inSingletonScope();
|
|
92
92
|
bind(CorePreferences).toConstantValue(<CorePreferences>{});
|
|
93
93
|
bindPreferenceService(bind);
|
|
@@ -37,6 +37,7 @@ import { Emitter } from '../../common/event';
|
|
|
37
37
|
import { waitForRevealed, waitForClosed } from '../widgets';
|
|
38
38
|
import { CorePreferences } from '../core-preferences';
|
|
39
39
|
import { BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer';
|
|
40
|
+
import { Deferred } from '../../common/promise-util';
|
|
40
41
|
|
|
41
42
|
/** The class name added to ApplicationShell instances. */
|
|
42
43
|
const APPLICATION_SHELL_CLASS = 'theia-ApplicationShell';
|
|
@@ -1076,25 +1077,27 @@ export class ApplicationShell extends Widget {
|
|
|
1076
1077
|
if (!current) {
|
|
1077
1078
|
return undefined;
|
|
1078
1079
|
}
|
|
1079
|
-
|
|
1080
|
+
return Promise.all([
|
|
1080
1081
|
this.waitForActivation(current.id),
|
|
1081
1082
|
waitForRevealed(current),
|
|
1082
1083
|
this.pendingUpdates
|
|
1083
|
-
]);
|
|
1084
|
-
return current;
|
|
1084
|
+
]).then(() => current, () => undefined);
|
|
1085
1085
|
}
|
|
1086
1086
|
|
|
1087
1087
|
waitForActivation(id: string): Promise<void> {
|
|
1088
1088
|
if (this.activeWidget && this.activeWidget.id === id) {
|
|
1089
1089
|
return Promise.resolve();
|
|
1090
1090
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1091
|
+
const activation = new Deferred();
|
|
1092
|
+
const success = this.onDidChangeActiveWidget(() => {
|
|
1093
|
+
if (this.activeWidget && this.activeWidget.id === id) {
|
|
1094
|
+
activation.resolve();
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
const failure = setTimeout(() => activation.reject(new Error(`Widget with id '${id}' failed to activate.`)), this.activationTimeout + 250);
|
|
1098
|
+
return activation.promise.finally(() => {
|
|
1099
|
+
success.dispose();
|
|
1100
|
+
clearTimeout(failure);
|
|
1098
1101
|
});
|
|
1099
1102
|
}
|
|
1100
1103
|
|
|
@@ -68,7 +68,7 @@ export namespace ElectronCommands {
|
|
|
68
68
|
|
|
69
69
|
export namespace ElectronMenus {
|
|
70
70
|
export const VIEW_WINDOW = [...CommonMenus.VIEW, 'window'];
|
|
71
|
-
export const VIEW_ZOOM = [...CommonMenus.
|
|
71
|
+
export const VIEW_ZOOM = [...CommonMenus.VIEW_APPEARANCE_SUBMENU, '4_appearance_submenu_zoom'];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export namespace ElectronMenus {
|
|
@@ -364,5 +364,10 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
|
|
|
364
364
|
registry.registerMenuAction(ElectronMenus.FILE_CLOSE, {
|
|
365
365
|
commandId: ElectronCommands.CLOSE_WINDOW.id,
|
|
366
366
|
});
|
|
367
|
+
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_SCREEN, {
|
|
368
|
+
commandId: ElectronCommands.TOGGLE_FULL_SCREEN.id,
|
|
369
|
+
label: nls.localizeByDefault('Full Screen'),
|
|
370
|
+
order: '0'
|
|
371
|
+
});
|
|
367
372
|
}
|
|
368
373
|
}
|
|
@@ -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":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,iDAAoD;AACpD,IAAI,YAAY,GAAG,mBAAW,EAAE,CAAC;AAEjC,+BAA8B;AAC9B,0CAA0C;AAC1C,2DAAuD;AAEvD,YAAY,EAAE,CAAC;AAEf,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAE9B,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,GAAG,mBAAW,EAAE,CAAC,CAAC;IAC3C,KAAK,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;IAE5B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAC9B,MAAM,gBAAgB,GAAG,IAAI,oCAAgB,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,gBAAgB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,SAAS,CAAC;QACxE,aAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,0BAA0B,CAAC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 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
|
-
}
|