Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4f8e68b8
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,体验更适合开发者的 AI 搜索 >>
提交
4f8e68b8
编写于
3月 20, 2017
作者:
M
Matt Bierner
提交者:
GitHub
3月 20, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Second prototype of markdown extensions (#22836)
上级
188ef21a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
20 deletion
+48
-20
extensions/markdown/src/extension.ts
extensions/markdown/src/extension.ts
+41
-15
extensions/markdown/src/markdownEngine.ts
extensions/markdown/src/markdownEngine.ts
+0
-2
extensions/markdown/src/previewContentProvider.ts
extensions/markdown/src/previewContentProvider.ts
+7
-3
未找到文件。
extensions/markdown/src/extension.ts
浏览文件 @
4f8e68b8
...
...
@@ -40,7 +40,7 @@ interface PreviewSecurityPickItem extends vscode.QuickPickItem {
id
:
PreviewSecuritySelection
;
}
class
ExtensionContentSecurityP
r
olicyArbiter
implements
ContentSecurityPolicyArbiter
{
class
ExtensionContentSecurityPolicyArbiter
implements
ContentSecurityPolicyArbiter
{
private
readonly
key
=
'
trusted_preview_workspace:
'
;
constructor
(
...
...
@@ -58,9 +58,16 @@ class ExtensionContentSecurityProlicyArbiter implements ContentSecurityPolicyArb
public
removeTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
{
return
this
.
globalState
.
update
(
this
.
key
+
rootPath
,
false
);
}
}
const
resolveExtensionResources
=
(
extension
:
vscode
.
Extension
<
any
>
,
stylePath
:
string
):
vscode
.
Uri
=>
{
const
resource
=
vscode
.
Uri
.
parse
(
stylePath
);
if
(
resource
.
scheme
)
{
return
resource
;
}
return
vscode
.
Uri
.
file
(
path
.
join
(
extension
.
extensionPath
,
stylePath
));
};
var
telemetryReporter
:
TelemetryReporter
|
null
;
export
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
...
...
@@ -70,12 +77,43 @@ export function activate(context: vscode.ExtensionContext) {
context
.
subscriptions
.
push
(
telemetryReporter
);
}
const
cspArbiter
=
new
ExtensionContentSecurityP
r
olicyArbiter
(
context
.
globalState
);
const
cspArbiter
=
new
ExtensionContentSecurityPolicyArbiter
(
context
.
globalState
);
const
engine
=
new
MarkdownEngine
();
const
contentProvider
=
new
MDDocumentContentProvider
(
engine
,
context
,
cspArbiter
);
const
contentProviderRegistration
=
vscode
.
workspace
.
registerTextDocumentContentProvider
(
'
markdown
'
,
contentProvider
);
if
(
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
).
get
(
'
enableExperimentalExtensionApi
'
,
false
))
{
for
(
const
extension
of
vscode
.
extensions
.
all
)
{
const
contributes
=
extension
.
packageJSON
&&
extension
.
packageJSON
.
contributes
;
if
(
!
contributes
)
{
continue
;
}
let
styles
=
contributes
[
'
markdown.preview
'
]
&&
contributes
[
'
markdown.preview
'
].
styles
;
if
(
styles
)
{
if
(
!
Array
.
isArray
(
styles
))
{
styles
=
[
styles
];
}
for
(
const
style
of
styles
)
{
try
{
contentProvider
.
addStyle
(
resolveExtensionResources
(
extension
,
style
));
}
catch
(
e
)
{
// noop
}
}
}
if
(
contributes
[
'
markdownit.plugins
'
])
{
extension
.
activate
().
then
(()
=>
{
if
(
extension
.
exports
&&
extension
.
exports
.
extendMarkdownIt
)
{
engine
.
addPlugin
((
md
:
any
)
=>
extension
.
exports
.
extendMarkdownIt
(
md
));
}
});
}
}
}
const
symbolsProvider
=
new
MDDocumentSymbolProvider
(
engine
);
const
symbolsProviderRegistration
=
vscode
.
languages
.
registerDocumentSymbolProvider
({
language
:
'
markdown
'
},
symbolsProvider
);
context
.
subscriptions
.
push
(
contentProviderRegistration
,
symbolsProviderRegistration
);
...
...
@@ -231,18 +269,6 @@ export function activate(context: vscode.ExtensionContext) {
});
}
}));
if
(
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
).
get
(
'
enableExperimentalExtensionApi
'
,
false
))
{
vscode
.
commands
.
executeCommand
(
'
_markdown.onActivateExtensions
'
)
.
then
(()
=>
void
0
,
()
=>
void
0
);
return
{
addPlugin
(
factory
:
(
md
:
any
)
=>
any
)
{
engine
.
addPlugin
(
factory
);
}
};
}
return
undefined
;
}
...
...
extensions/markdown/src/markdownEngine.ts
浏览文件 @
4f8e68b8
...
...
@@ -33,8 +33,6 @@ export class MarkdownEngine {
private
plugins
:
Array
<
(
md
:
any
)
=>
any
>
=
[];
constructor
()
{
}
public
addPlugin
(
factory
:
(
md
:
any
)
=>
any
):
void
{
if
(
this
.
md
)
{
this
.
usePlugin
(
factory
);
...
...
extensions/markdown/src/previewContentProvider.ts
浏览文件 @
4f8e68b8
...
...
@@ -28,6 +28,7 @@ export function getMarkdownUri(uri: vscode.Uri) {
export
class
MDDocumentContentProvider
implements
vscode
.
TextDocumentContentProvider
{
private
_onDidChange
=
new
vscode
.
EventEmitter
<
vscode
.
Uri
>
();
private
_waiting
:
boolean
=
false
;
private
extraStyles
:
Array
<
vscode
.
Uri
>
=
[];
constructor
(
private
engine
:
MarkdownEngine
,
...
...
@@ -35,6 +36,10 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
private
cspArbiter
:
ContentSecurityPolicyArbiter
)
{
}
public
addStyle
(
resource
:
vscode
.
Uri
):
void
{
this
.
extraStyles
.
push
(
resource
);
}
private
getMediaPath
(
mediaFile
:
string
):
string
{
return
vscode
.
Uri
.
file
(
this
.
context
.
asAbsolutePath
(
path
.
join
(
'
media
'
,
mediaFile
))).
toString
();
}
...
...
@@ -97,7 +102,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
const
baseStyles
=
[
this
.
getMediaPath
(
'
markdown.css
'
),
this
.
getMediaPath
(
'
tomorrow.css
'
)
];
]
.
concat
(
this
.
extraStyles
.
map
(
resource
=>
resource
.
toString
()))
;
return
`
${
baseStyles
.
map
(
href
=>
`<link rel="stylesheet" type="text/css" href="
${
href
}
">`
).
join
(
'
\n
'
)}
${
this
.
getSettingsOverrideStyles
(
nonce
)}
...
...
@@ -105,8 +110,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
}
private
getScripts
(
nonce
:
string
):
string
{
const
scripts
=
[
this
.
getMediaPath
(
'
main.js
'
)];
return
scripts
return
[
this
.
getMediaPath
(
'
main.js
'
)]
.
map
(
source
=>
`<script src="
${
source
}
" nonce="
${
nonce
}
"></script>`
)
.
join
(
'
\n
'
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录