Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
075ec045
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
075ec045
编写于
2月 21, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notifications - dispose markdown callbacks as needed
上级
094f5ee8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
35 deletion
+47
-35
src/vs/base/browser/htmlContentRenderer.ts
src/vs/base/browser/htmlContentRenderer.ts
+18
-15
src/vs/base/test/browser/htmlContent.test.ts
src/vs/base/test/browser/htmlContent.test.ts
+12
-6
src/vs/editor/contrib/markdown/markdownRenderer.ts
src/vs/editor/contrib/markdown/markdownRenderer.ts
+10
-10
src/vs/workbench/browser/parts/notifications/notificationsViewer.ts
...kbench/browser/parts/notifications/notificationsViewer.ts
+7
-4
未找到文件。
src/vs/base/browser/htmlContentRenderer.ts
浏览文件 @
075ec045
...
...
@@ -12,11 +12,17 @@ import { removeMarkdownEscapes, IMarkdownString } from 'vs/base/common/htmlConte
import
{
marked
,
MarkedRenderer
,
MarkedOptions
}
from
'
vs/base/common/marked/marked
'
;
import
{
IMouseEvent
}
from
'
vs/base/browser/mouseEvent
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
export
interface
IContentActionHandler
{
callback
:
(
content
:
string
,
event
?:
IMouseEvent
)
=>
void
;
disposeables
:
IDisposable
[];
}
export
interface
RenderOptions
{
className
?:
string
;
inline
?:
boolean
;
action
Callback
?:
(
content
:
string
,
event
?:
IMouseEvent
)
=>
void
;
action
Handler
?:
IContentActionHandler
;
codeBlockRenderer
?:
(
modeId
:
string
,
value
:
string
)
=>
Thenable
<
string
>
;
codeBlockRenderCallback
?:
()
=>
void
;
joinRendererConfiguration
?:
(
renderer
:
MarkedRenderer
)
=>
MarkedOptions
;
...
...
@@ -39,15 +45,12 @@ export function renderText(text: string, options: RenderOptions = {}): HTMLEleme
export
function
renderFormattedText
(
formattedText
:
string
,
options
:
RenderOptions
=
{}):
HTMLElement
{
const
element
=
createElement
(
options
);
_renderFormattedText
(
element
,
parseFormattedText
(
formattedText
),
options
.
action
Callback
);
_renderFormattedText
(
element
,
parseFormattedText
(
formattedText
),
options
.
action
Handler
);
return
element
;
}
/**
* Create html nodes for the given content element.
*
* @param content a html element description
* @param actionCallback a callback function for any action links in the string. Argument is the zero-based index of the clicked action.
*/
export
function
renderMarkdown
(
markdown
:
IMarkdownString
,
options
:
RenderOptions
=
{}):
HTMLElement
{
const
element
=
createElement
(
options
);
...
...
@@ -141,8 +144,8 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
};
}
if
(
options
.
action
Callback
)
{
DOM
.
addStandardDisposableListener
(
element
,
'
click
'
,
event
=>
{
if
(
options
.
action
Handler
)
{
options
.
actionHandler
.
disposeables
.
push
(
DOM
.
addStandardDisposableListener
(
element
,
'
click
'
,
event
=>
{
let
target
=
event
.
target
;
if
(
target
.
tagName
!==
'
A
'
)
{
target
=
target
.
parentElement
;
...
...
@@ -153,9 +156,9 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
const
href
=
target
.
dataset
[
'
href
'
];
if
(
href
)
{
options
.
action
C
allback
(
href
,
event
);
options
.
action
Handler
.
c
allback
(
href
,
event
);
}
});
})
)
;
}
const
markedOptions
:
MarkedOptions
=
{
...
...
@@ -224,7 +227,7 @@ interface IFormatParseTree {
children
?:
IFormatParseTree
[];
}
function
_renderFormattedText
(
element
:
Node
,
treeNode
:
IFormatParseTree
,
action
Callback
?:
(
content
:
string
,
event
?:
IMouseEvent
)
=>
void
)
{
function
_renderFormattedText
(
element
:
Node
,
treeNode
:
IFormatParseTree
,
action
Handler
?:
IContentActionHandler
)
{
let
child
:
Node
;
if
(
treeNode
.
type
===
FormatType
.
Text
)
{
...
...
@@ -236,12 +239,12 @@ function _renderFormattedText(element: Node, treeNode: IFormatParseTree, actionC
else
if
(
treeNode
.
type
===
FormatType
.
Italics
)
{
child
=
document
.
createElement
(
'
i
'
);
}
else
if
(
treeNode
.
type
===
FormatType
.
Action
)
{
else
if
(
treeNode
.
type
===
FormatType
.
Action
&&
actionHandler
)
{
const
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
'
#
'
;
DOM
.
addStandardDisposableListener
(
a
,
'
click
'
,
(
event
)
=>
{
action
C
allback
(
String
(
treeNode
.
index
),
event
);
});
actionHandler
.
disposeables
.
push
(
DOM
.
addStandardDisposableListener
(
a
,
'
click
'
,
(
event
)
=>
{
action
Handler
.
c
allback
(
String
(
treeNode
.
index
),
event
);
})
)
;
child
=
a
;
}
...
...
@@ -258,7 +261,7 @@ function _renderFormattedText(element: Node, treeNode: IFormatParseTree, actionC
if
(
Array
.
isArray
(
treeNode
.
children
))
{
treeNode
.
children
.
forEach
((
nodeChild
)
=>
{
_renderFormattedText
(
child
,
nodeChild
,
action
Callback
);
_renderFormattedText
(
child
,
nodeChild
,
action
Handler
);
});
}
}
...
...
src/vs/base/test/browser/htmlContent.test.ts
浏览文件 @
075ec045
...
...
@@ -52,9 +52,12 @@ suite('HtmlContent', () => {
test
(
'
action
'
,
()
=>
{
var
callbackCalled
=
false
;
var
result
:
HTMLElement
=
renderFormattedText
(
'
[[action]]
'
,
{
actionCallback
(
content
)
{
assert
.
strictEqual
(
content
,
'
0
'
);
callbackCalled
=
true
;
actionHandler
:
{
callback
(
content
)
{
assert
.
strictEqual
(
content
,
'
0
'
);
callbackCalled
=
true
;
},
disposeables
:
[]
}
});
assert
.
strictEqual
(
result
.
innerHTML
,
'
<a href="#">action</a>
'
);
...
...
@@ -68,9 +71,12 @@ suite('HtmlContent', () => {
test
(
'
fancy action
'
,
()
=>
{
var
callbackCalled
=
false
;
var
result
:
HTMLElement
=
renderFormattedText
(
'
__**[[action]]**__
'
,
{
actionCallback
(
content
)
{
assert
.
strictEqual
(
content
,
'
0
'
);
callbackCalled
=
true
;
actionHandler
:
{
callback
(
content
)
{
assert
.
strictEqual
(
content
,
'
0
'
);
callbackCalled
=
true
;
},
disposeables
:
[]
}
});
assert
.
strictEqual
(
result
.
innerHTML
,
'
<i><b><a href="#">action</a></b></i>
'
);
...
...
src/vs/editor/contrib/markdown/markdownRenderer.ts
浏览文件 @
075ec045
...
...
@@ -30,9 +30,6 @@ export class MarkdownRenderer {
@
optional
(
IOpenerService
)
private
readonly
_openerService
:
IOpenerService
=
NullOpenerService
,
)
{
this
.
_options
=
{
actionCallback
:
(
content
)
=>
{
this
.
_openerService
.
open
(
URI
.
parse
(
content
)).
then
(
void
0
,
onUnexpectedError
);
},
codeBlockRenderer
:
(
languageAlias
,
value
):
TPromise
<
string
>
=>
{
// In markdown,
// it is possible that we stumble upon language aliases (e.g.js instead of javascript)
...
...
@@ -47,18 +44,21 @@ export class MarkdownRenderer {
return
`<span style="font-family:
${
editor
.
getConfiguration
().
fontInfo
.
fontFamily
}
">
${
code
}
</span>`
;
});
},
codeBlockRenderCallback
:
()
=>
this
.
_onDidRenderCodeBlock
.
fire
()
codeBlockRenderCallback
:
()
=>
this
.
_onDidRenderCodeBlock
.
fire
(),
actionHandler
:
{
callback
:
(
content
)
=>
{
this
.
_openerService
.
open
(
URI
.
parse
(
content
)).
then
(
void
0
,
onUnexpectedError
);
},
disposeables
:
[]
// TODO
}
};
}
render
(
markdown
:
IMarkdownString
,
options
?:
RenderOptions
):
HTMLElement
{
render
(
markdown
:
IMarkdownString
):
HTMLElement
{
if
(
!
markdown
)
{
return
document
.
createElement
(
'
span
'
);
}
if
(
options
)
{
return
renderMarkdown
(
markdown
,
{
...
options
,
...
this
.
_options
});
}
else
{
return
renderMarkdown
(
markdown
,
this
.
_options
);
}
return
renderMarkdown
(
markdown
,
this
.
_options
);
}
}
src/vs/workbench/browser/parts/notifications/notificationsViewer.ts
浏览文件 @
075ec045
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
{
IDelegate
,
IRenderer
}
from
'
vs/base/browser/ui/list/list
'
;
import
{
renderMarkdown
}
from
'
vs/base/browser/htmlContentRenderer
'
;
import
{
renderMarkdown
,
IContentActionHandler
}
from
'
vs/base/browser/htmlContentRenderer
'
;
import
{
clearNode
,
addClass
,
removeClass
,
toggleClass
}
from
'
vs/base/browser/dom
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
import
URI
from
'
vs/base/common/uri
'
;
...
...
@@ -132,7 +132,7 @@ class NotificationMessageMarkdownRenderer {
'
tablerow
'
];
public
static
render
(
markdown
:
IMarkdownString
,
action
Callback
?:
(
content
:
string
)
=>
void
):
HTMLElement
{
public
static
render
(
markdown
:
IMarkdownString
,
action
Handler
?:
IContentActionHandler
):
HTMLElement
{
return
renderMarkdown
(
markdown
,
{
inline
:
true
,
joinRendererConfiguration
:
renderer
=>
{
...
...
@@ -145,7 +145,7 @@ class NotificationMessageMarkdownRenderer {
smartypants
:
false
// disable some text transformations
}
as
MarkedOptions
;
},
action
Callback
action
Handler
});
}
}
...
...
@@ -331,7 +331,10 @@ export class NotificationTemplateRenderer {
private
renderMessage
(
notification
:
INotificationViewItem
):
boolean
{
clearNode
(
this
.
template
.
message
);
this
.
template
.
message
.
appendChild
(
NotificationMessageMarkdownRenderer
.
render
(
notification
.
message
,
(
content
:
string
)
=>
this
.
openerService
.
open
(
URI
.
parse
(
content
)).
then
(
void
0
,
onUnexpectedError
)));
this
.
template
.
message
.
appendChild
(
NotificationMessageMarkdownRenderer
.
render
(
notification
.
message
,
{
callback
:
(
content
:
string
)
=>
this
.
openerService
.
open
(
URI
.
parse
(
content
)).
then
(
void
0
,
onUnexpectedError
),
disposeables
:
this
.
inputDisposeables
}));
const
messageOverflows
=
notification
.
canCollapse
&&
!
notification
.
expanded
&&
this
.
template
.
message
.
scrollWidth
>
this
.
template
.
message
.
clientWidth
;
if
(
messageOverflows
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录