Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ded53f44
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,发现更多精彩内容 >>
提交
ded53f44
编写于
10月 27, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Marking markdown settings scopes
上级
07c6d4cf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
51 deletion
+54
-51
extensions/markdown/package.json
extensions/markdown/package.json
+25
-14
extensions/markdown/src/previewContentProvider.ts
extensions/markdown/src/previewContentProvider.ts
+29
-37
未找到文件。
extensions/markdown/package.json
浏览文件 @
ded53f44
...
...
@@ -47,7 +47,6 @@
"source.js"
:
"javascript"
,
"source.css"
:
"css"
,
"meta.embedded.block.frontmatter"
:
"yaml"
,
"meta.embedded.block.css"
:
"css"
,
"meta.embedded.block.ini"
:
"ini"
,
"meta.embedded.block.java"
:
"java"
,
...
...
@@ -212,7 +211,8 @@
"markdown.styles"
:
{
"type"
:
"array"
,
"default"
:
[],
"description"
:
"%markdown.styles.dec%"
"description"
:
"%markdown.styles.dec%"
,
"scope"
:
"resource"
},
"markdown.previewFrontMatter"
:
{
"type"
:
"string"
,
...
...
@@ -221,52 +221,62 @@
"show"
],
"default"
:
"hide"
,
"description"
:
"%markdown.previewFrontMatter.dec%"
"description"
:
"%markdown.previewFrontMatter.dec%"
,
"scope"
:
"resource"
},
"markdown.preview.breaks"
:
{
"type"
:
"boolean"
,
"default"
:
false
,
"description"
:
"%markdown.preview.breaks.desc%"
"description"
:
"%markdown.preview.breaks.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.linkify"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%markdown.preview.linkify%"
"description"
:
"%markdown.preview.linkify%"
,
"scope"
:
"resource"
},
"markdown.preview.fontFamily"
:
{
"type"
:
"string"
,
"default"
:
"-apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'HelveticaNeue-Light', 'Ubuntu', 'Droid Sans', sans-serif"
,
"description"
:
"%markdown.preview.fontFamily.desc%"
"description"
:
"%markdown.preview.fontFamily.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.fontSize"
:
{
"type"
:
"number"
,
"default"
:
14
,
"description"
:
"%markdown.preview.fontSize.desc%"
"description"
:
"%markdown.preview.fontSize.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.lineHeight"
:
{
"type"
:
"number"
,
"default"
:
1.6
,
"description"
:
"%markdown.preview.lineHeight.desc%"
"description"
:
"%markdown.preview.lineHeight.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.scrollPreviewWithEditorSelection"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%markdown.preview.scrollPreviewWithEditorSelection.desc%"
"description"
:
"%markdown.preview.scrollPreviewWithEditorSelection.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.markEditorSelection"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%markdown.preview.markEditorSelection.desc%"
"description"
:
"%markdown.preview.markEditorSelection.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.scrollEditorWithPreview"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%markdown.preview.scrollEditorWithPreview.desc%"
"description"
:
"%markdown.preview.scrollEditorWithPreview.desc%"
,
"scope"
:
"resource"
},
"markdown.preview.doubleClickToSwitchToEditor"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%markdown.preview.doubleClickToSwitchToEditor.desc%"
"description"
:
"%markdown.preview.doubleClickToSwitchToEditor.desc%"
,
"scope"
:
"resource"
},
"markdown.trace"
:
{
"type"
:
"string"
,
...
...
@@ -275,7 +285,8 @@
"verbose"
],
"default"
:
"off"
,
"description"
:
"%markdown.trace.desc%"
"description"
:
"%markdown.trace.desc%"
,
"scope"
:
"window"
}
}
},
...
...
@@ -310,4 +321,4 @@
"gulp-rename"
:
"^1.2.2"
,
"gulp-replace"
:
"^0.5.4"
}
}
\ No newline at end of file
}
extensions/markdown/src/previewContentProvider.ts
浏览文件 @
ded53f44
...
...
@@ -38,8 +38,8 @@ export function getMarkdownUri(uri: vscode.Uri) {
}
class
MarkdownPreviewConfig
{
public
static
getC
urrentConfig
(
)
{
return
new
MarkdownPreviewConfig
();
public
static
getC
onfigForResource
(
resource
:
vscode
.
Uri
)
{
return
new
MarkdownPreviewConfig
(
resource
);
}
public
readonly
scrollBeyondLastLine
:
boolean
;
...
...
@@ -56,10 +56,10 @@ class MarkdownPreviewConfig {
public
readonly
fontFamily
:
string
|
undefined
;
public
readonly
styles
:
string
[];
private
constructor
()
{
const
editorConfig
=
vscode
.
workspace
.
getConfiguration
(
'
editor
'
);
const
markdownConfig
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
);
const
markdownEditorConfig
=
vscode
.
workspace
.
getConfiguration
(
'
[markdown]
'
);
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
);
this
.
scrollBeyondLastLine
=
editorConfig
.
get
<
boolean
>
(
'
scrollBeyondLastLine
'
,
false
);
...
...
@@ -111,8 +111,6 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
private
_onDidChange
=
new
vscode
.
EventEmitter
<
vscode
.
Uri
>
();
private
_waiting
:
boolean
=
false
;
private
config
:
MarkdownPreviewConfig
;
private
extraStyles
:
Array
<
vscode
.
Uri
>
=
[];
private
extraScripts
:
Array
<
vscode
.
Uri
>
=
[];
...
...
@@ -121,9 +119,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
private
context
:
vscode
.
ExtensionContext
,
private
cspArbiter
:
ContentSecurityPolicyArbiter
,
private
logger
:
Logger
)
{
this
.
config
=
MarkdownPreviewConfig
.
getCurrentConfig
();
}
)
{
}
public
addScript
(
resource
:
vscode
.
Uri
):
void
{
this
.
extraScripts
.
push
(
resource
);
...
...
@@ -163,34 +159,34 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
return
vscode
.
Uri
.
file
(
path
.
join
(
path
.
dirname
(
resource
.
fsPath
),
href
)).
toString
();
}
private
computeCustomStyleSheetIncludes
(
uri
:
vscode
.
Uri
):
string
{
if
(
this
.
config
.
styles
&&
Array
.
isArray
(
this
.
config
.
styles
))
{
return
this
.
config
.
styles
.
map
((
style
)
=>
{
return
`<link rel="stylesheet" class="code-user-style" data-source="
${
style
.
replace
(
/"/g
,
'
"
'
)}
" href="
${
this
.
fixHref
(
uri
,
style
)}
" type="text/css" media="screen">`
;
private
computeCustomStyleSheetIncludes
(
resource
:
vscode
.
Uri
,
config
:
MarkdownPreviewConfig
):
string
{
if
(
config
.
styles
&&
Array
.
isArray
(
config
.
styles
))
{
return
config
.
styles
.
map
(
style
=>
{
return
`<link rel="stylesheet" class="code-user-style" data-source="
${
style
.
replace
(
/"/g
,
'
"
'
)}
" href="
${
this
.
fixHref
(
resource
,
style
)}
" type="text/css" media="screen">`
;
}).
join
(
'
\n
'
);
}
return
''
;
}
private
getSettingsOverrideStyles
(
nonce
:
string
):
string
{
private
getSettingsOverrideStyles
(
nonce
:
string
,
config
:
MarkdownPreviewConfig
):
string
{
return
`<style nonce="
${
nonce
}
">
body {
${
this
.
config
.
fontFamily
?
`font-family:
${
this
.
config
.
fontFamily
}
;`
:
''
}
${
isNaN
(
this
.
config
.
fontSize
)
?
''
:
`font-size:
${
this
.
config
.
fontSize
}
px;`
}
${
isNaN
(
this
.
config
.
lineHeight
)
?
''
:
`line-height:
${
this
.
config
.
lineHeight
}
;`
}
${
config
.
fontFamily
?
`font-family:
${
config
.
fontFamily
}
;`
:
''
}
${
isNaN
(
config
.
fontSize
)
?
''
:
`font-size:
${
config
.
fontSize
}
px;`
}
${
isNaN
(
config
.
lineHeight
)
?
''
:
`line-height:
${
config
.
lineHeight
}
;`
}
}
</style>`
;
}
private
getStyles
(
resource
:
vscode
.
Uri
,
nonce
:
string
):
string
{
private
getStyles
(
resource
:
vscode
.
Uri
,
nonce
:
string
,
config
:
MarkdownPreviewConfig
):
string
{
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
)}
${
this
.
computeCustomStyleSheetIncludes
(
resource
)}
`
;
${
this
.
getSettingsOverrideStyles
(
nonce
,
config
)}
${
this
.
computeCustomStyleSheetIncludes
(
resource
,
config
)}
`
;
}
private
getScripts
(
nonce
:
string
):
string
{
...
...
@@ -210,15 +206,15 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
}
const
document
=
await
vscode
.
workspace
.
openTextDocument
(
sourceUri
);
this
.
config
=
MarkdownPreviewConfig
.
getCurrentConfig
(
);
const
config
=
MarkdownPreviewConfig
.
getConfigForResource
(
sourceUri
);
const
initialData
=
{
previewUri
:
uri
.
toString
(),
source
:
sourceUri
.
toString
(),
line
:
initialLine
,
scrollPreviewWithEditorSelection
:
this
.
config
.
scrollPreviewWithEditorSelection
,
scrollEditorWithPreview
:
this
.
config
.
scrollEditorWithPreview
,
doubleClickToSwitchToEditor
:
this
.
config
.
doubleClickToSwitchToEditor
scrollPreviewWithEditorSelection
:
config
.
scrollPreviewWithEditorSelection
,
scrollEditorWithPreview
:
config
.
scrollEditorWithPreview
,
doubleClickToSwitchToEditor
:
config
.
doubleClickToSwitchToEditor
};
this
.
logger
.
log
(
'
provideTextDocumentContent
'
,
initialData
);
...
...
@@ -227,7 +223,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
const
nonce
=
new
Date
().
getTime
()
+
''
+
new
Date
().
getMilliseconds
();
const
csp
=
this
.
getCspForResource
(
sourceUri
,
nonce
);
const
body
=
await
this
.
engine
.
render
(
sourceUri
,
this
.
config
.
previewFrontMatter
===
'
hide
'
,
document
.
getText
());
const
body
=
await
this
.
engine
.
render
(
sourceUri
,
config
.
previewFrontMatter
===
'
hide
'
,
document
.
getText
());
return
`<!DOCTYPE html>
<html>
<head>
...
...
@@ -236,10 +232,10 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
<meta id="vscode-markdown-preview-data" data-settings="
${
JSON
.
stringify
(
initialData
).
replace
(
/"/g
,
'
"
'
)}
" data-strings="
${
JSON
.
stringify
(
previewStrings
).
replace
(
/"/g
,
'
"
'
)}
">
<script src="
${
this
.
getMediaPath
(
'
csp.js
'
)}
" nonce="
${
nonce
}
"></script>
<script src="
${
this
.
getMediaPath
(
'
loading.js
'
)}
" nonce="
${
nonce
}
"></script>
${
this
.
getStyles
(
sourceUri
,
nonce
)}
${
this
.
getStyles
(
sourceUri
,
nonce
,
config
)}
<base href="
${
document
.
uri
.
toString
(
true
)}
">
</head>
<body class="vscode-body
${
this
.
config
.
scrollBeyondLastLine
?
'
scrollBeyondLastLine
'
:
''
}
${
this
.
config
.
wordWrap
?
'
wordWrap
'
:
''
}
${
this
.
config
.
markEditorSelection
?
'
showEditorSelection
'
:
''
}
">
<body class="vscode-body
${
config
.
scrollBeyondLastLine
?
'
scrollBeyondLastLine
'
:
''
}
${
config
.
wordWrap
?
'
wordWrap
'
:
''
}
${
config
.
markEditorSelection
?
'
showEditorSelection
'
:
''
}
">
${
body
}
<div class="code-line" data-line="
${
document
.
lineCount
}
"></div>
${
this
.
getScripts
(
nonce
)}
...
...
@@ -248,14 +244,10 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
}
public
updateConfiguration
()
{
const
newConfig
=
MarkdownPreviewConfig
.
getCurrentConfig
();
if
(
!
this
.
config
.
isEqualTo
(
newConfig
))
{
this
.
config
=
newConfig
;
// update all generated md documents
for
(
const
document
of
vscode
.
workspace
.
textDocuments
)
{
if
(
document
.
uri
.
scheme
===
'
markdown
'
)
{
this
.
update
(
document
.
uri
);
}
// update all generated md documents
for
(
const
document
of
vscode
.
workspace
.
textDocuments
)
{
if
(
document
.
uri
.
scheme
===
'
markdown
'
)
{
this
.
update
(
document
.
uri
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录