Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d4116a8f
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4116a8f
编写于
11月 09, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tweak markdown string conversion and rendering
上级
0b998674
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
24 deletion
+88
-24
src/vs/base/browser/htmlContentRenderer.ts
src/vs/base/browser/htmlContentRenderer.ts
+11
-0
src/vs/base/common/htmlContent.ts
src/vs/base/common/htmlContent.ts
+2
-0
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-0
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+0
-6
src/vs/workbench/api/node/extHostTypeConverters.ts
src/vs/workbench/api/node/extHostTypeConverters.ts
+12
-18
src/vs/workbench/test/electron-browser/api/extHostTypeConverter.test.ts
...ch/test/electron-browser/api/extHostTypeConverter.test.ts
+59
-0
未找到文件。
src/vs/base/browser/htmlContentRenderer.ts
浏览文件 @
d4116a8f
...
...
@@ -11,6 +11,7 @@ import * as marked from 'vs/base/common/marked/marked';
import
{
IMouseEvent
}
from
'
vs/base/browser/mouseEvent
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
export
interface
IContentActionHandler
{
callback
:
(
content
:
string
,
event
?:
IMouseEvent
)
=>
void
;
...
...
@@ -52,6 +53,14 @@ export function renderFormattedText(formattedText: string, options: RenderOption
export
function
renderMarkdown
(
markdown
:
IMarkdownString
,
options
:
RenderOptions
=
{}):
HTMLElement
{
const
element
=
createElement
(
options
);
const
_href
=
function
(
href
:
string
):
string
{
const
data
=
markdown
.
uris
&&
markdown
.
uris
[
href
];
if
(
data
)
{
href
=
URI
.
revive
(
data
).
toString
(
true
);
}
return
href
;
};
// signal to code-block render that the
// element has been created
let
signalInnerHTML
:
Function
;
...
...
@@ -59,6 +68,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
const
renderer
=
new
marked
.
Renderer
();
renderer
.
image
=
(
href
:
string
,
title
:
string
,
text
:
string
)
=>
{
href
=
_href
(
href
);
let
dimensions
:
string
[]
=
[];
if
(
href
)
{
const
splitted
=
href
.
split
(
'
|
'
).
map
(
s
=>
s
.
trim
());
...
...
@@ -99,6 +109,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
if
(
href
===
text
)
{
// raw link case
text
=
removeMarkdownEscapes
(
text
);
}
href
=
_href
(
href
);
title
=
removeMarkdownEscapes
(
title
);
href
=
removeMarkdownEscapes
(
href
);
if
(
...
...
src/vs/base/common/htmlContent.ts
浏览文件 @
d4116a8f
...
...
@@ -4,10 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import
{
equals
}
from
'
vs/base/common/arrays
'
;
import
{
UriComponents
}
from
'
vs/base/common/uri
'
;
export
interface
IMarkdownString
{
value
:
string
;
isTrusted
?:
boolean
;
uris
?:
{
[
href
:
string
]:
UriComponents
};
}
export
class
MarkdownString
implements
IMarkdownString
{
...
...
src/vs/monaco.d.ts
浏览文件 @
d4116a8f
...
...
@@ -392,9 +392,13 @@ declare namespace monaco {
static
readonly
WinCtrl
:
number
;
static
chord
(
firstPart
:
number
,
secondPart
:
number
):
number
;
}
export
interface
IMarkdownString
{
value
:
string
;
isTrusted
?:
boolean
;
uris
?:
{
[
href
:
string
]:
UriComponents
;
};
}
export
interface
IKeyboardEvent
{
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
d4116a8f
...
...
@@ -274,12 +274,6 @@ export interface ISerializedSignatureHelpProviderMetadata {
readonly
retriggerCharacters
:
ReadonlyArray
<
string
>
;
}
export
interface
IMarkdownStringDto
{
isTrusted
:
boolean
;
value
:
string
;
uris
:
{
[
n
:
string
]:
UriComponents
};
}
export
interface
MainThreadLanguageFeaturesShape
extends
IDisposable
{
$unregister
(
handle
:
number
):
void
;
$registerOutlineSupport
(
handle
:
number
,
selector
:
ISerializedDocumentFilter
[],
extensionId
:
string
):
void
;
...
...
src/vs/workbench/api/node/extHostTypeConverters.ts
浏览文件 @
d4116a8f
...
...
@@ -19,7 +19,7 @@ import { IRange } from 'vs/editor/common/core/range';
import
{
ISelection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
htmlContent
from
'
vs/base/common/htmlContent
'
;
import
*
as
languageSelector
from
'
vs/editor/common/modes/languageSelector
'
;
import
{
WorkspaceEditDto
,
ResourceTextEditDto
,
ResourceFileEditDto
,
IMarkdownStringDto
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
WorkspaceEditDto
,
ResourceTextEditDto
,
ResourceFileEditDto
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
MarkerSeverity
,
IRelatedInformation
,
IMarkerData
,
MarkerTag
}
from
'
vs/platform/markers/common/markers
'
;
import
{
ACTIVE_GROUP
,
SIDE_GROUP
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/node/extHostDocumentsAndEditors
'
;
...
...
@@ -210,38 +210,32 @@ export namespace MarkdownString {
}
export
function
from
(
markup
:
vscode
.
MarkdownString
|
vscode
.
MarkedString
):
htmlContent
.
IMarkdownString
{
let
res
:
htmlContent
.
IMarkdownString
;
if
(
isCodeblock
(
markup
))
{
const
{
language
,
value
}
=
markup
;
re
turn
{
value
:
'
```
'
+
language
+
'
\n
'
+
value
+
'
\n
```
\n
'
};
re
s
=
{
value
:
'
```
'
+
language
+
'
\n
'
+
value
+
'
\n
```
\n
'
};
}
else
if
(
htmlContent
.
isMarkdownString
(
markup
))
{
re
turn
markup
;
re
s
=
markup
;
}
else
if
(
typeof
markup
===
'
string
'
)
{
re
turn
{
value
:
<
string
>
markup
};
re
s
=
{
value
:
<
string
>
markup
};
}
else
{
re
turn
{
value
:
''
};
re
s
=
{
value
:
''
};
}
}
export
function
from2
(
markup
:
vscode
.
MarkedString
|
vscode
.
MarkdownString
):
IMarkdownStringDto
{
let
{
value
,
isTrusted
}
=
from
(
markup
);
let
uris
=
Object
.
create
(
null
);
// extract uris into a separate object
res
.
uris
=
Object
.
create
(
null
);
let
renderer
=
new
marked
.
Renderer
();
renderer
.
image
=
renderer
.
link
=
(
href
:
string
):
string
=>
{
try
{
uris
[
href
]
=
URI
.
parse
(
href
,
true
);
res
.
uris
[
href
]
=
URI
.
parse
(
href
,
true
);
}
catch
(
e
)
{
// ignore
}
return
''
;
};
marked
(
value
,
{
renderer
});
return
{
isTrusted
,
value
,
uris
};
marked
(
res
.
value
,
{
renderer
});
return
res
;
}
export
function
to
(
value
:
htmlContent
.
IMarkdownString
):
vscode
.
MarkdownString
{
...
...
src/vs/workbench/test/electron-browser/api/extHostTypeConverter.test.ts
0 → 100644
浏览文件 @
d4116a8f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
MarkdownString
}
from
'
vs/workbench/api/node/extHostTypeConverters
'
;
import
{
isEmptyObject
}
from
'
vs/base/common/types
'
;
import
{
size
}
from
'
vs/base/common/collections
'
;
suite
(
'
ExtHostTypeConverter
'
,
function
()
{
test
(
'
MarkdownConvert - uris
'
,
function
()
{
let
data
=
MarkdownString
.
from
(
'
Hello
'
);
assert
.
equal
(
isEmptyObject
(
data
.
uris
),
true
);
assert
.
equal
(
data
.
value
,
'
Hello
'
);
data
=
MarkdownString
.
from
(
'
Hello [link](foo)
'
);
assert
.
equal
(
data
.
value
,
'
Hello [link](foo)
'
);
assert
.
equal
(
isEmptyObject
(
data
.
uris
),
true
);
// no scheme, no uri
data
=
MarkdownString
.
from
(
'
Hello [link](www.noscheme.bad)
'
);
assert
.
equal
(
data
.
value
,
'
Hello [link](www.noscheme.bad)
'
);
assert
.
equal
(
isEmptyObject
(
data
.
uris
),
true
);
// no scheme, no uri
data
=
MarkdownString
.
from
(
'
Hello [link](foo:path)
'
);
assert
.
equal
(
data
.
value
,
'
Hello [link](foo:path)
'
);
assert
.
equal
(
size
(
data
.
uris
),
1
);
assert
.
ok
(
!!
data
.
uris
[
'
foo:path
'
]);
data
=
MarkdownString
.
from
(
'
hello@foo.bar
'
);
assert
.
equal
(
data
.
value
,
'
hello@foo.bar
'
);
assert
.
equal
(
size
(
data
.
uris
),
1
);
assert
.
ok
(
!!
data
.
uris
[
'
mailto:hello@foo.bar
'
]);
data
=
MarkdownString
.
from
(
'
*hello* [click](command:me)
'
);
assert
.
equal
(
data
.
value
,
'
*hello* [click](command:me)
'
);
assert
.
equal
(
size
(
data
.
uris
),
1
);
assert
.
ok
(
!!
data
.
uris
[
'
command:me
'
]);
data
=
MarkdownString
.
from
(
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here)
'
);
assert
.
equal
(
data
.
value
,
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here)
'
);
assert
.
equal
(
size
(
data
.
uris
),
1
);
assert
.
ok
(
!!
data
.
uris
[
'
file:///somepath/here
'
]);
data
=
MarkdownString
.
from
(
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here)
'
);
assert
.
equal
(
data
.
value
,
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here)
'
);
assert
.
equal
(
size
(
data
.
uris
),
1
);
assert
.
ok
(
!!
data
.
uris
[
'
file:///somepath/here
'
]);
data
=
MarkdownString
.
from
(
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here2)
'
);
assert
.
equal
(
data
.
value
,
'
*hello* [click](file:///somepath/here). [click](file:///somepath/here2)
'
);
assert
.
equal
(
size
(
data
.
uris
),
2
);
assert
.
ok
(
!!
data
.
uris
[
'
file:///somepath/here
'
]);
assert
.
ok
(
!!
data
.
uris
[
'
file:///somepath/here2
'
]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录