Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
038e8d39
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,发现更多精彩内容 >>
提交
038e8d39
编写于
2月 05, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make markdown extension points dynamic
For #67574 Blocked by #67958
上级
8f10101d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
11 deletion
+72
-11
extensions/markdown-language-features/src/features/preview.ts
...nsions/markdown-language-features/src/features/preview.ts
+4
-0
extensions/markdown-language-features/src/markdownEngine.ts
extensions/markdown-language-features/src/markdownEngine.ts
+7
-2
extensions/markdown-language-features/src/markdownExtensions.ts
...ions/markdown-language-features/src/markdownExtensions.ts
+41
-9
extensions/markdown-language-features/src/test/engine.ts
extensions/markdown-language-features/src/test/engine.ts
+2
-0
extensions/markdown-language-features/src/util/arrays.ts
extensions/markdown-language-features/src/util/arrays.ts
+18
-0
未找到文件。
extensions/markdown-language-features/src/features/preview.ts
浏览文件 @
038e8d39
...
...
@@ -161,6 +161,10 @@ export class MarkdownPreview extends Disposable {
this
.
_onDidChangeViewStateEmitter
.
fire
(
e
);
},
null
,
this
.
_disposables
);
_contributionProvider
.
onContributionsChanged
(()
=>
{
setImmediate
(()
=>
this
.
refresh
());
},
null
,
this
.
_disposables
);
this
.
editor
.
webview
.
onDidReceiveMessage
((
e
:
CacheImageSizesMessage
|
RevealLineMessage
|
DidClickMessage
|
ClickLinkMessage
|
ShowPreviewSecuritySelectorMessage
|
PreviewStyleLoadErrorMessage
)
=>
{
if
(
e
.
source
!==
this
.
_resource
.
toString
())
{
return
;
...
...
extensions/markdown-language-features/src/markdownEngine.ts
浏览文件 @
038e8d39
...
...
@@ -59,14 +59,19 @@ export class MarkdownEngine {
public
constructor
(
private
readonly
contributionProvider
:
MarkdownContributionProvider
,
private
readonly
slugifier
:
Slugifier
,
)
{
}
)
{
contributionProvider
.
onContributionsChanged
(()
=>
{
// Markdown plugin contributions may have changed
this
.
md
=
undefined
;
});
}
private
async
getEngine
(
config
:
MarkdownItConfig
):
Promise
<
MarkdownIt
>
{
if
(
!
this
.
md
)
{
this
.
md
=
import
(
'
markdown-it
'
).
then
(
async
markdownIt
=>
{
let
md
:
MarkdownIt
=
markdownIt
(
await
getMarkdownOptions
(()
=>
md
));
for
(
const
plugin
of
this
.
contributionProvider
.
contributions
.
markdownItPlugins
)
{
for
(
const
plugin
of
this
.
contributionProvider
.
contributions
.
markdownItPlugins
.
values
()
)
{
try
{
md
=
(
await
plugin
)(
md
);
}
catch
{
...
...
extensions/markdown-language-features/src/markdownExtensions.ts
浏览文件 @
038e8d39
...
...
@@ -5,6 +5,8 @@
import
*
as
vscode
from
'
vscode
'
;
import
*
as
path
from
'
path
'
;
import
{
Disposable
}
from
'
./util/dispose
'
;
import
*
as
arrays
from
'
./util/arrays
'
;
const
resolveExtensionResource
=
(
extension
:
vscode
.
Extension
<
any
>
,
resourcePath
:
string
):
vscode
.
Uri
=>
{
return
vscode
.
Uri
.
file
(
path
.
join
(
extension
.
extensionPath
,
resourcePath
))
...
...
@@ -29,7 +31,7 @@ export interface MarkdownContributions {
readonly
previewScripts
:
ReadonlyArray
<
vscode
.
Uri
>
;
readonly
previewStyles
:
ReadonlyArray
<
vscode
.
Uri
>
;
readonly
previewResourceRoots
:
ReadonlyArray
<
vscode
.
Uri
>
;
readonly
markdownItPlugins
:
ReadonlyArray
<
Thenable
<
(
md
:
any
)
=>
any
>>
;
readonly
markdownItPlugins
:
Map
<
string
,
Thenable
<
(
md
:
any
)
=>
any
>>
;
}
export
namespace
MarkdownContributions
{
...
...
@@ -37,7 +39,7 @@ export namespace MarkdownContributions {
previewScripts
:
[],
previewStyles
:
[],
previewResourceRoots
:
[],
markdownItPlugins
:
[]
markdownItPlugins
:
new
Map
()
};
export
function
merge
(
a
:
MarkdownContributions
,
b
:
MarkdownContributions
):
MarkdownContributions
{
...
...
@@ -45,10 +47,21 @@ export namespace MarkdownContributions {
previewScripts
:
[...
a
.
previewScripts
,
...
b
.
previewScripts
],
previewStyles
:
[...
a
.
previewStyles
,
...
b
.
previewStyles
],
previewResourceRoots
:
[...
a
.
previewResourceRoots
,
...
b
.
previewResourceRoots
],
markdownItPlugins
:
[...
a
.
markdownItPlugins
,
...
b
.
markdownItPlugins
]
,
markdownItPlugins
:
new
Map
([...
a
.
markdownItPlugins
.
entries
(),
...
b
.
markdownItPlugins
.
entries
()])
,
};
}
function
uriEqual
(
a
:
vscode
.
Uri
,
b
:
vscode
.
Uri
):
boolean
{
return
a
.
toString
()
===
b
.
toString
();
}
export
function
equal
(
a
:
MarkdownContributions
,
b
:
MarkdownContributions
):
boolean
{
return
arrays
.
equals
(
a
.
previewScripts
,
b
.
previewScripts
,
uriEqual
)
&&
arrays
.
equals
(
a
.
previewStyles
,
b
.
previewStyles
,
uriEqual
)
&&
arrays
.
equals
(
a
.
previewResourceRoots
,
b
.
previewResourceRoots
,
uriEqual
)
&&
arrays
.
equals
(
Array
.
from
(
a
.
markdownItPlugins
.
keys
()),
Array
.
from
(
b
.
markdownItPlugins
.
keys
()));
}
export
function
fromExtension
(
extension
:
vscode
.
Extension
<
any
>
):
MarkdownContributions
{
...
...
@@ -69,7 +82,7 @@ export namespace MarkdownContributions {
previewScripts
:
scripts
,
previewStyles
:
styles
,
previewResourceRoots
,
markdownItPlugins
:
plugins
?
[
plugins
]
:
[]
markdownItPlugins
:
plugins
?
new
Map
([[
extension
.
id
,
plugins
]])
:
new
Map
()
};
}
...
...
@@ -106,23 +119,42 @@ export namespace MarkdownContributions {
export
interface
MarkdownContributionProvider
{
readonly
extensionPath
:
string
;
readonly
contributions
:
MarkdownContributions
;
readonly
onContributionsChanged
:
vscode
.
Event
<
this
>
;
}
class
VSCodeExtensionMarkdownContributionProvider
implements
MarkdownContributionProvider
{
class
VSCodeExtensionMarkdownContributionProvider
extends
Disposable
implements
MarkdownContributionProvider
{
private
_contributions
?:
MarkdownContributions
;
public
constructor
(
public
readonly
extensionPath
:
string
,
)
{
}
)
{
super
();
vscode
.
extensions
.
onDidChange
(()
=>
{
const
currentContributions
=
this
.
getCurrentContributions
();
const
existingContributions
=
this
.
_contributions
||
MarkdownContributions
.
Empty
;
if
(
!
MarkdownContributions
.
equal
(
existingContributions
,
currentContributions
))
{
this
.
_contributions
=
currentContributions
;
this
.
_onContributionsChanged
.
fire
(
this
);
}
},
undefined
,
this
.
_disposables
);
}
private
readonly
_onContributionsChanged
=
new
vscode
.
EventEmitter
<
this
>
();
public
readonly
onContributionsChanged
=
this
.
_onContributionsChanged
.
event
;
public
get
contributions
():
MarkdownContributions
{
if
(
!
this
.
_contributions
)
{
this
.
_contributions
=
vscode
.
extensions
.
all
.
reduce
(
(
contributions
,
extension
)
=>
MarkdownContributions
.
merge
(
contributions
,
MarkdownContributions
.
fromExtension
(
extension
)),
MarkdownContributions
.
Empty
);
this
.
_contributions
=
this
.
getCurrentContributions
();
}
return
this
.
_contributions
;
}
private
getCurrentContributions
():
MarkdownContributions
{
return
vscode
.
extensions
.
all
.
map
(
MarkdownContributions
.
fromExtension
)
.
reduce
(
MarkdownContributions
.
merge
,
MarkdownContributions
.
Empty
);
}
}
export
function
getMarkdownExtensionContributions
(
context
:
vscode
.
ExtensionContext
):
MarkdownContributionProvider
{
...
...
extensions/markdown-language-features/src/test/engine.ts
浏览文件 @
038e8d39
...
...
@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
MarkdownEngine
}
from
'
../markdownEngine
'
;
import
{
MarkdownContributionProvider
,
MarkdownContributions
}
from
'
../markdownExtensions
'
;
import
{
githubSlugifier
}
from
'
../slugify
'
;
...
...
@@ -10,6 +11,7 @@ import { githubSlugifier } from '../slugify';
const
emptyContributions
=
new
class
implements
MarkdownContributionProvider
{
readonly
extensionPath
=
''
;
readonly
contributions
=
MarkdownContributions
.
Empty
;
readonly
onContributionsChanged
=
new
vscode
.
EventEmitter
<
this
>
().
event
;
};
export
function
createNewMarkdownEngine
():
MarkdownEngine
{
...
...
extensions/markdown-language-features/src/util/arrays.ts
0 → 100644
浏览文件 @
038e8d39
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export
function
equals
<
T
>
(
one
:
ReadonlyArray
<
T
>
,
other
:
ReadonlyArray
<
T
>
,
itemEquals
:
(
a
:
T
,
b
:
T
)
=>
boolean
=
(
a
,
b
)
=>
a
===
b
):
boolean
{
if
(
one
.
length
!==
other
.
length
)
{
return
false
;
}
for
(
let
i
=
0
,
len
=
one
.
length
;
i
<
len
;
i
++
)
{
if
(
!
itemEquals
(
one
[
i
],
other
[
i
]))
{
return
false
;
}
}
return
true
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录