|
6 | 6 | 'use strict'; |
7 | 7 |
|
8 | 8 | import { IDelegate, IRenderer } from 'vs/base/browser/ui/list/list'; |
9 | | -import { renderMarkdown, IContentActionHandler } from 'vs/base/browser/htmlContentRenderer'; |
10 | | -import { clearNode, addClass, removeClass, toggleClass } from 'vs/base/browser/dom'; |
| 9 | +import { clearNode, addClass, removeClass, toggleClass, addDisposableListener } from 'vs/base/browser/dom'; |
11 | 10 | import { IOpenerService } from 'vs/platform/opener/common/opener'; |
12 | 11 | import URI from 'vs/base/common/uri'; |
13 | 12 | import { onUnexpectedError } from 'vs/base/common/errors'; |
14 | 13 | import { localize } from 'vs/nls'; |
15 | 14 | import { ButtonGroup } from 'vs/base/browser/ui/button/button'; |
16 | 15 | import { attachButtonStyler, attachProgressBarStyler } from 'vs/platform/theme/common/styler'; |
17 | 16 | import { IThemeService } from 'vs/platform/theme/common/themeService'; |
18 | | -import { IMarkdownString } from 'vs/base/common/htmlContent'; |
19 | 17 | import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; |
20 | 18 | import { IAction, IActionRunner } from 'vs/base/common/actions'; |
21 | 19 | import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; |
22 | 20 | import { IDisposable, dispose } from 'vs/base/common/lifecycle'; |
23 | 21 | import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; |
24 | 22 | import { DropdownMenuActionItem } from 'vs/base/browser/ui/dropdown/dropdown'; |
25 | | -import { INotificationViewItem, NotificationViewItem, NotificationViewItemLabelKind } from 'vs/workbench/common/notifications'; |
| 23 | +import { INotificationViewItem, NotificationViewItem, NotificationViewItemLabelKind, INotificationMessage } from 'vs/workbench/common/notifications'; |
26 | 24 | import { ClearNotificationAction, ExpandNotificationAction, CollapseNotificationAction, ConfigureNotificationAction } from 'vs/workbench/browser/parts/notifications/notificationsActions'; |
27 | 25 | import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; |
28 | | -import { MarkedOptions } from 'vs/base/common/marked/marked'; |
29 | 26 | import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar'; |
30 | 27 | import { Severity } from 'vs/platform/notification/common/notification'; |
31 | 28 |
|
@@ -92,8 +89,8 @@ export class NotificationsListDelegate implements IDelegate<INotificationViewIte |
92 | 89 | } |
93 | 90 | this.offsetHelper.style.width = `calc(100% - ${10 /* padding */ + 24 /* severity icon */ + (actions * 24) /* 24px per action */}px)`; |
94 | 91 |
|
95 | | - // Render message markdown into offset helper |
96 | | - const renderedMessage = NotificationMessageMarkdownRenderer.render(notification.message); |
| 92 | + // Render message into offset helper |
| 93 | + const renderedMessage = NotificationMessageRenderer.render(notification.message); |
97 | 94 | this.offsetHelper.appendChild(renderedMessage); |
98 | 95 |
|
99 | 96 | // Compute height |
@@ -131,30 +128,49 @@ export interface INotificationTemplateData { |
131 | 128 | renderer: NotificationTemplateRenderer; |
132 | 129 | } |
133 | 130 |
|
134 | | -class NotificationMessageMarkdownRenderer { |
135 | | - |
136 | | - private static readonly MARKED_NOOP = (text?: string) => text || ''; |
137 | | - private static readonly MARKED_NOOP_TARGETS = [ |
138 | | - 'blockquote', 'br', 'code', 'codespan', 'del', 'em', 'heading', 'hr', 'html', |
139 | | - 'image', 'list', 'listitem', 'paragraph', 'strong', 'table', 'tablecell', |
140 | | - 'tablerow' |
141 | | - ]; |
142 | | - |
143 | | - public static render(markdown: IMarkdownString, actionHandler?: IContentActionHandler): HTMLElement { |
144 | | - return renderMarkdown(markdown, { |
145 | | - inline: true, |
146 | | - joinRendererConfiguration: renderer => { |
147 | | - |
148 | | - // Overwrite markdown render functions as no-ops |
149 | | - NotificationMessageMarkdownRenderer.MARKED_NOOP_TARGETS.forEach(fn => renderer[fn] = NotificationMessageMarkdownRenderer.MARKED_NOOP); |
150 | | - |
151 | | - return { |
152 | | - gfm: false, // disable GitHub style markdown, |
153 | | - smartypants: false // disable some text transformations |
154 | | - } as MarkedOptions; |
155 | | - }, |
156 | | - actionHandler |
157 | | - }); |
| 131 | +interface IMessageActionHandler { |
| 132 | + callback: (href: string) => void; |
| 133 | + disposeables: IDisposable[]; |
| 134 | +} |
| 135 | + |
| 136 | +class NotificationMessageRenderer { |
| 137 | + |
| 138 | + public static render(message: INotificationMessage, actionHandler?: IMessageActionHandler): HTMLElement { |
| 139 | + const messageContainer = document.createElement('span'); |
| 140 | + |
| 141 | + // Message has no links |
| 142 | + if (message.links.length === 0) { |
| 143 | + messageContainer.textContent = message.value; |
| 144 | + } |
| 145 | + |
| 146 | + // Message has links |
| 147 | + else { |
| 148 | + let index = 0; |
| 149 | + let textBefore: string; |
| 150 | + for (let i = 0; i < message.links.length; i++) { |
| 151 | + const link = message.links[i]; |
| 152 | + |
| 153 | + textBefore = message.value.substring(index, link.offset); |
| 154 | + if (textBefore) { |
| 155 | + messageContainer.appendChild(document.createTextNode(textBefore)); |
| 156 | + } |
| 157 | + |
| 158 | + const anchor = document.createElement('a'); |
| 159 | + anchor.textContent = link.name; |
| 160 | + anchor.title = link.href; |
| 161 | + anchor.href = link.href; |
| 162 | + |
| 163 | + if (actionHandler) { |
| 164 | + actionHandler.disposeables.push(addDisposableListener(anchor, 'click', () => actionHandler.callback(link.href))); |
| 165 | + } |
| 166 | + |
| 167 | + messageContainer.appendChild(anchor); |
| 168 | + |
| 169 | + index = link.offset + link.length; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + return messageContainer; |
158 | 174 | } |
159 | 175 | } |
160 | 176 |
|
@@ -340,8 +356,8 @@ export class NotificationTemplateRenderer { |
340 | 356 |
|
341 | 357 | private renderMessage(notification: INotificationViewItem): boolean { |
342 | 358 | clearNode(this.template.message); |
343 | | - this.template.message.appendChild(NotificationMessageMarkdownRenderer.render(notification.message, { |
344 | | - callback: (content: string) => this.openerService.open(URI.parse(content)).then(void 0, onUnexpectedError), |
| 359 | + this.template.message.appendChild(NotificationMessageRenderer.render(notification.message, { |
| 360 | + callback: link => this.openerService.open(URI.parse(link)).then(void 0, onUnexpectedError), |
345 | 361 | disposeables: this.inputDisposeables |
346 | 362 | })); |
347 | 363 |
|
|
0 commit comments