Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
55942889
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,发现更多精彩内容 >>
提交
55942889
编写于
10月 27, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed more resource scope access in the markdown extension
上级
ded53f44
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
9 deletion
+44
-9
extensions/markdown/src/markdownEngine.ts
extensions/markdown/src/markdownEngine.ts
+6
-6
extensions/markdown/src/previewContentProvider.ts
extensions/markdown/src/previewContentProvider.ts
+38
-3
未找到文件。
extensions/markdown/src/markdownEngine.ts
浏览文件 @
55942889
...
...
@@ -35,7 +35,7 @@ export class MarkdownEngine {
}
}
private
async
getEngine
():
Promise
<
MarkdownIt
>
{
private
async
getEngine
(
resource
:
vscode
.
Uri
):
Promise
<
MarkdownIt
>
{
if
(
!
this
.
md
)
{
const
hljs
=
await
import
(
'
highlight.js
'
);
const
mdnh
=
await
import
(
'
markdown-it-named-headers
'
);
...
...
@@ -66,10 +66,10 @@ export class MarkdownEngine {
this
.
addLinkValidator
(
this
.
md
);
}
const
config
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
);
const
config
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
,
resource
);
this
.
md
.
set
({
breaks
:
config
.
get
(
'
preview.breaks
'
,
false
),
linkify
:
config
.
get
(
'
preview.linkify
'
,
true
)
breaks
:
config
.
get
<
boolean
>
(
'
preview.breaks
'
,
false
),
linkify
:
config
.
get
<
boolean
>
(
'
preview.linkify
'
,
true
)
});
return
this
.
md
;
}
...
...
@@ -94,14 +94,14 @@ export class MarkdownEngine {
}
this
.
currentDocument
=
document
;
this
.
firstLine
=
offset
;
const
engine
=
await
this
.
getEngine
();
const
engine
=
await
this
.
getEngine
(
document
);
return
engine
.
render
(
text
);
}
public
async
parse
(
document
:
vscode
.
Uri
,
source
:
string
):
Promise
<
Token
[]
>
{
const
{
text
,
offset
}
=
this
.
stripFrontmatter
(
source
);
this
.
currentDocument
=
document
;
const
engine
=
await
this
.
getEngine
();
const
engine
=
await
this
.
getEngine
(
document
);
return
engine
.
parse
(
text
,
{}).
map
(
token
=>
{
if
(
token
.
map
)
{
...
...
extensions/markdown/src/previewContentProvider.ts
浏览文件 @
55942889
...
...
@@ -59,7 +59,7 @@ class MarkdownPreviewConfig {
private
constructor
(
resource
:
vscode
.
Uri
)
{
const
editorConfig
=
vscode
.
workspace
.
getConfiguration
(
'
editor
'
,
resource
);
const
markdownConfig
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
,
resource
);
const
markdownEditorConfig
=
vscode
.
workspace
.
getConfiguration
(
'
[markdown]
'
,
resource
);
const
markdownEditorConfig
=
vscode
.
workspace
.
getConfiguration
(
'
[markdown]
'
);
this
.
scrollBeyondLastLine
=
editorConfig
.
get
<
boolean
>
(
'
scrollBeyondLastLine
'
,
false
);
...
...
@@ -107,9 +107,41 @@ class MarkdownPreviewConfig {
[
key
:
string
]:
any
;
}
class
PreviewConfigManager
{
private
previewConfigurationsForWorkspaces
=
new
Map
<
string
,
MarkdownPreviewConfig
>
();
public
loadAndCacheConfiguration
(
resource
:
vscode
.
Uri
)
{
const
config
=
MarkdownPreviewConfig
.
getConfigForResource
(
resource
);
this
.
previewConfigurationsForWorkspaces
.
set
(
this
.
getKey
(
resource
),
config
);
return
config
;
}
public
shouldUpdateConfiguration
(
resource
:
vscode
.
Uri
):
boolean
{
const
key
=
this
.
getKey
(
resource
);
const
currentConfig
=
this
.
previewConfigurationsForWorkspaces
.
get
(
key
);
const
newConfig
=
MarkdownPreviewConfig
.
getConfigForResource
(
resource
);
return
(
!
currentConfig
||
!
currentConfig
.
isEqualTo
(
newConfig
));
}
private
getKey
(
resource
:
vscode
.
Uri
):
string
{
const
folder
=
vscode
.
workspace
.
getWorkspaceFolder
(
resource
);
if
(
!
folder
)
{
return
''
;
}
return
folder
.
uri
.
toString
();
}
}
export
class
MDDocumentContentProvider
implements
vscode
.
TextDocumentContentProvider
{
private
_onDidChange
=
new
vscode
.
EventEmitter
<
vscode
.
Uri
>
();
private
_waiting
:
boolean
=
false
;
private
previewConfigurations
=
new
PreviewConfigManager
();
private
extraStyles
:
Array
<
vscode
.
Uri
>
=
[];
private
extraScripts
:
Array
<
vscode
.
Uri
>
=
[];
...
...
@@ -206,7 +238,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
}
const
document
=
await
vscode
.
workspace
.
openTextDocument
(
sourceUri
);
const
config
=
MarkdownPreviewConfig
.
getConfigForResource
(
sourceUri
);
const
config
=
this
.
previewConfigurations
.
loadAndCacheConfiguration
(
sourceUri
);
const
initialData
=
{
previewUri
:
uri
.
toString
(),
...
...
@@ -247,7 +279,10 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
// update all generated md documents
for
(
const
document
of
vscode
.
workspace
.
textDocuments
)
{
if
(
document
.
uri
.
scheme
===
'
markdown
'
)
{
this
.
update
(
document
.
uri
);
const
sourceUri
=
vscode
.
Uri
.
parse
(
document
.
uri
.
query
);
if
(
this
.
previewConfigurations
.
shouldUpdateConfiguration
(
sourceUri
))
{
this
.
update
(
document
.
uri
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录