Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
81f06c86
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 搜索 >>
提交
81f06c86
编写于
4月 04, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split markdown security selector into own file
上级
183dfbc2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
122 addition
and
97 deletion
+122
-97
extensions/markdown/src/extension.ts
extensions/markdown/src/extension.ts
+4
-96
extensions/markdown/src/previewContentProvider.ts
extensions/markdown/src/previewContentProvider.ts
+4
-0
extensions/markdown/src/security.ts
extensions/markdown/src/security.ts
+113
-0
extensions/typescript/syntaxes/TypeScript.tmLanguage.json
extensions/typescript/syntaxes/TypeScript.tmLanguage.json
+1
-1
未找到文件。
extensions/markdown/src/extension.ts
浏览文件 @
81f06c86
...
...
@@ -11,14 +11,10 @@ import TelemetryReporter from 'vscode-extension-telemetry';
import
{
MarkdownEngine
}
from
'
./markdownEngine
'
;
import
DocumentLinkProvider
from
'
./documentLinkProvider
'
;
import
MDDocumentSymbolProvider
from
'
./documentSymbolProvider
'
;
import
{
MDDocumentContentProvider
,
getMarkdownUri
,
isMarkdownFile
,
ContentSecurityPolicyArbiter
}
from
'
./previewContentProvider
'
;
import
{
ExtensionContentSecurityPolicyArbiter
,
PreviewSecuritySelector
}
from
'
./security
'
;
import
{
MDDocumentContentProvider
,
getMarkdownUri
,
isMarkdownFile
}
from
'
./previewContentProvider
'
;
import
{
TableOfContentsProvider
}
from
'
./tableOfContentsProvider
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
interface
IPackageInfo
{
name
:
string
;
version
:
string
;
...
...
@@ -30,36 +26,6 @@ interface OpenDocumentLinkArgs {
fragment
:
string
;
}
enum
PreviewSecuritySelection
{
None
,
DisableEnhancedSecurityForWorkspace
,
EnableEnhancedSecurityForWorkspace
}
interface
PreviewSecurityPickItem
extends
vscode
.
QuickPickItem
{
id
:
PreviewSecuritySelection
;
}
class
ExtensionContentSecurityPolicyArbiter
implements
ContentSecurityPolicyArbiter
{
private
readonly
key
=
'
trusted_preview_workspace:
'
;
constructor
(
private
globalState
:
vscode
.
Memento
)
{
}
public
isEnhancedSecurityDisableForWorkspace
():
boolean
{
return
this
.
globalState
.
get
<
boolean
>
(
this
.
key
+
vscode
.
workspace
.
rootPath
,
false
);
}
public
addTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
{
return
this
.
globalState
.
update
(
this
.
key
+
rootPath
,
true
);
}
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
)
{
...
...
@@ -82,7 +48,7 @@ export function activate(context: vscode.ExtensionContext) {
const
contentProvider
=
new
MDDocumentContentProvider
(
engine
,
context
,
cspArbiter
);
const
contentProviderRegistration
=
vscode
.
workspace
.
registerTextDocumentContentProvider
(
'
markdown
'
,
contentProvider
);
const
previewSecuritySelector
=
new
PreviewSecuritySelector
(
cspArbiter
,
contentProvider
);
if
(
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
).
get
(
'
enableExperimentalExtensionApi
'
,
false
))
{
for
(
const
extension
of
vscode
.
extensions
.
all
)
{
const
contributes
=
extension
.
packageJSON
&&
extension
.
packageJSON
.
contributes
;
...
...
@@ -192,65 +158,7 @@ export function activate(context: vscode.ExtensionContext) {
}));
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
markdown.showPreviewSecuritySelector
'
,
(
resource
:
string
|
undefined
)
=>
{
const
workspacePath
=
vscode
.
workspace
.
rootPath
||
resource
;
if
(
!
workspacePath
)
{
return
;
}
let
sourceUri
:
vscode
.
Uri
|
null
=
null
;
if
(
resource
)
{
sourceUri
=
vscode
.
Uri
.
parse
(
decodeURIComponent
(
resource
));
}
if
(
!
sourceUri
&&
vscode
.
window
.
activeTextEditor
)
{
const
activeDocument
=
vscode
.
window
.
activeTextEditor
.
document
;
if
(
activeDocument
.
uri
.
scheme
===
'
markdown
'
)
{
sourceUri
=
activeDocument
.
uri
;
}
else
{
sourceUri
=
getMarkdownUri
(
activeDocument
.
uri
);
}
}
vscode
.
window
.
showQuickPick
<
PreviewSecurityPickItem
>
(
[
{
id
:
PreviewSecuritySelection
.
EnableEnhancedSecurityForWorkspace
,
label
:
localize
(
'
preview.showPreviewSecuritySelector.disallowScriptsForWorkspaceTitle
'
,
'
Disable script execution in markdown previews for this workspace
'
),
description
:
''
,
detail
:
cspArbiter
.
isEnhancedSecurityDisableForWorkspace
()
?
''
:
localize
(
'
preview.showPreviewSecuritySelector.currentSelection
'
,
'
Current setting
'
)
},
{
id
:
PreviewSecuritySelection
.
DisableEnhancedSecurityForWorkspace
,
label
:
localize
(
'
preview.showPreviewSecuritySelector.allowScriptsForWorkspaceTitle
'
,
'
Enable script execution in markdown previews for this workspace
'
),
description
:
''
,
detail
:
cspArbiter
.
isEnhancedSecurityDisableForWorkspace
()
?
localize
(
'
preview.showPreviewSecuritySelector.currentSelection
'
,
'
Current setting
'
)
:
''
},
],
{
placeHolder
:
localize
(
'
preview.showPreviewSecuritySelector.title
'
,
'
Change security settings for the Markdown preview
'
),
}).
then
(
selection
=>
{
if
(
!
workspacePath
)
{
return
false
;
}
switch
(
selection
&&
selection
.
id
)
{
case
PreviewSecuritySelection
.
DisableEnhancedSecurityForWorkspace
:
return
cspArbiter
.
addTrustedWorkspace
(
workspacePath
).
then
(()
=>
true
);
case
PreviewSecuritySelection
.
EnableEnhancedSecurityForWorkspace
:
return
cspArbiter
.
removeTrustedWorkspace
(
workspacePath
).
then
(()
=>
true
);
}
return
false
;
}).
then
(
shouldUpdate
=>
{
if
(
shouldUpdate
&&
sourceUri
)
{
contentProvider
.
update
(
sourceUri
);
}
});
previewSecuritySelector
.
showSecutitySelectorForWorkspace
(
resource
);
}));
context
.
subscriptions
.
push
(
vscode
.
workspace
.
onDidSaveTextDocument
(
document
=>
{
...
...
extensions/markdown/src/previewContentProvider.ts
浏览文件 @
81f06c86
...
...
@@ -14,6 +14,10 @@ const localize = nls.loadMessageBundle();
export
interface
ContentSecurityPolicyArbiter
{
isEnhancedSecurityDisableForWorkspace
():
boolean
;
addTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
;
removeTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
;
}
const
previewStrings
=
{
...
...
extensions/markdown/src/security.ts
0 → 100644
浏览文件 @
81f06c86
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
ContentSecurityPolicyArbiter
,
getMarkdownUri
,
MDDocumentContentProvider
}
from
'
./previewContentProvider
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
export
class
ExtensionContentSecurityPolicyArbiter
implements
ContentSecurityPolicyArbiter
{
private
readonly
key
=
'
trusted_preview_workspace:
'
;
constructor
(
private
globalState
:
vscode
.
Memento
)
{
}
public
isEnhancedSecurityDisableForWorkspace
():
boolean
{
return
this
.
globalState
.
get
<
boolean
>
(
this
.
key
+
vscode
.
workspace
.
rootPath
,
false
);
}
public
addTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
{
return
this
.
globalState
.
update
(
this
.
key
+
rootPath
,
true
);
}
public
removeTrustedWorkspace
(
rootPath
:
string
):
Thenable
<
void
>
{
return
this
.
globalState
.
update
(
this
.
key
+
rootPath
,
false
);
}
}
enum
PreviewSecuritySelection
{
None
,
DisableEnhancedSecurityForWorkspace
,
EnableEnhancedSecurityForWorkspace
}
interface
PreviewSecurityPickItem
extends
vscode
.
QuickPickItem
{
id
:
PreviewSecuritySelection
;
}
export
class
PreviewSecuritySelector
{
public
constructor
(
private
cspArbiter
:
ContentSecurityPolicyArbiter
,
private
contentProvider
:
MDDocumentContentProvider
)
{
}
public
showSecutitySelectorForWorkspace
(
resource
:
string
|
undefined
):
void
{
const
workspacePath
=
vscode
.
workspace
.
rootPath
||
resource
;
if
(
!
workspacePath
)
{
return
;
}
let
sourceUri
:
vscode
.
Uri
|
null
=
null
;
if
(
resource
)
{
sourceUri
=
vscode
.
Uri
.
parse
(
decodeURIComponent
(
resource
));
}
if
(
!
sourceUri
&&
vscode
.
window
.
activeTextEditor
)
{
const
activeDocument
=
vscode
.
window
.
activeTextEditor
.
document
;
if
(
activeDocument
.
uri
.
scheme
===
'
markdown
'
)
{
sourceUri
=
activeDocument
.
uri
;
}
else
{
sourceUri
=
getMarkdownUri
(
activeDocument
.
uri
);
}
}
vscode
.
window
.
showQuickPick
<
PreviewSecurityPickItem
>
(
[
{
id
:
PreviewSecuritySelection
.
EnableEnhancedSecurityForWorkspace
,
label
:
localize
(
'
preview.showPreviewSecuritySelector.disallowScriptsForWorkspaceTitle
'
,
'
Disable script execution in markdown previews for this workspace
'
),
description
:
''
,
detail
:
this
.
cspArbiter
.
isEnhancedSecurityDisableForWorkspace
()
?
''
:
localize
(
'
preview.showPreviewSecuritySelector.currentSelection
'
,
'
Current setting
'
)
},
{
id
:
PreviewSecuritySelection
.
DisableEnhancedSecurityForWorkspace
,
label
:
localize
(
'
preview.showPreviewSecuritySelector.allowScriptsForWorkspaceTitle
'
,
'
Enable script execution in markdown previews for this workspace
'
),
description
:
''
,
detail
:
this
.
cspArbiter
.
isEnhancedSecurityDisableForWorkspace
()
?
localize
(
'
preview.showPreviewSecuritySelector.currentSelection
'
,
'
Current setting
'
)
:
''
},
],
{
placeHolder
:
localize
(
'
preview.showPreviewSecuritySelector.title
'
,
'
Change security settings for the Markdown preview
'
),
}).
then
(
selection
=>
{
if
(
!
workspacePath
)
{
return
false
;
}
switch
(
selection
&&
selection
.
id
)
{
case
PreviewSecuritySelection
.
DisableEnhancedSecurityForWorkspace
:
return
this
.
cspArbiter
.
addTrustedWorkspace
(
workspacePath
).
then
(()
=>
true
);
case
PreviewSecuritySelection
.
EnableEnhancedSecurityForWorkspace
:
return
this
.
cspArbiter
.
removeTrustedWorkspace
(
workspacePath
).
then
(()
=>
true
);
}
return
false
;
}).
then
(
shouldUpdate
=>
{
if
(
shouldUpdate
&&
sourceUri
)
{
this
.
contentProvider
.
update
(
sourceUri
);
}
});
}
}
extensions/typescript/syntaxes/TypeScript.tmLanguage.json
浏览文件 @
81f06c86
...
...
@@ -2720,7 +2720,7 @@
},
{
"name"
:
"meta.arrow.ts"
,
"begin"
:
"(?x) (?:
\n
(?<!
\\
.|
\\
$)(
\\
basync)(?=
\\
s*[<(])
\n
) | ((?<![})
\\
]])
\\
s*
\n
(?=
\n
# sure shot arrow functions even if => is on new line
\n
(
\n
[(]
\\
s*
\n
(
\n
([)]
\\
s*:) | # ():
\n
([_$[:alpha:]][_$[:alnum:]]*
\\
s*:)
| # [(]param:
\n
(
\\
.
\\
.
\\
.)
# [(]...
\n
)
\n
) |
\n
(
\n
[<]
\\
s*[_$[:alpha:]][_$[:alnum:]]*
\\
s+extends
\\
s*[^=>] # < typeparam extends
\n
) |
\n
# arrow function possible to detect only with => on same line
\n
(
\n
(<([^<>]|
\\
<[^<>]+
\\
>)+>
\\
s*)? # typeparameters
\n
\\
(([^()]|
\\
([^()]*
\\
))*
\\
) # parameteres
\n
(
\\
s*:
\\
s*(.)*)? # return type
\n
\\
s*=> # arrow operator
\n
)
\n
)
\n
)"
,
"begin"
:
"(?x) (?:
\n
(?<!
\\
.|
\\
$)(
\\
basync)(?=
\\
s*[<(])
\n
) | ((?<![})
\\
]])
\\
s*
\n
(?=
\n
# sure shot arrow functions even if => is on new line
\n
(
\n
[(]
\\
s*
\n
(
\n
([)]
\\
s*:) | # ():
\n
([_$[:alpha:]][_$[:alnum:]]*
\\
s*:) # [(]...
\n
)
\n
) |
\n
(
\n
[<]
\\
s*[_$[:alpha:]][_$[:alnum:]]*
\\
s+extends
\\
s*[^=>] # < typeparam extends
\n
) |
\n
# arrow function possible to detect only with => on same line
\n
(
\n
(<([^<>]|
\\
<[^<>]+
\\
>)+>
\\
s*)? # typeparameters
\n
\\
(([^()]|
\\
([^()]*
\\
))*
\\
) # parameteres
\n
(
\\
s*:
\\
s*(.)*)? # return type
\n
\\
s*=> # arrow operator
\n
)
\n
)
\n
)"
,
"beginCaptures"
:
{
"1"
:
{
"name"
:
"storage.modifier.async.ts"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录