Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
344f4fa3
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
344f4fa3
编写于
1月 09, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure we update the markdown document on config changes
上级
758280cc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
16 deletion
+35
-16
extensions/markdown-language-features/src/markdownEngine.ts
extensions/markdown-language-features/src/markdownEngine.ts
+35
-16
未找到文件。
extensions/markdown-language-features/src/markdownEngine.ts
浏览文件 @
344f4fa3
...
...
@@ -14,27 +14,36 @@ import { getUriForLinkWithKnownExternalScheme } from './util/links';
const
UNICODE_NEWLINE_REGEX
=
/
\u
2028|
\u
2029/g
;
interface
MarkdownItConfig
{
readonly
breaks
:
boolean
;
readonly
linkify
:
boolean
;
}
class
TokenCache
{
private
cachedDocument
?:
{
readonly
uri
:
vscode
.
Uri
;
readonly
version
:
number
;
readonly
config
:
MarkdownItConfig
;
};
private
tokens
?:
Token
[];
public
tryGetCached
(
document
:
SkinnyTextDocument
):
Token
[]
|
undefined
{
public
tryGetCached
(
document
:
SkinnyTextDocument
,
config
:
MarkdownItConfig
):
Token
[]
|
undefined
{
if
(
this
.
cachedDocument
&&
this
.
cachedDocument
.
uri
.
toString
()
===
document
.
uri
.
toString
()
&&
this
.
cachedDocument
.
version
===
document
.
version
&&
this
.
cachedDocument
.
config
.
breaks
===
config
.
breaks
&&
this
.
cachedDocument
.
config
.
linkify
===
config
.
linkify
)
{
return
this
.
tokens
;
}
return
undefined
;
}
public
update
(
document
:
SkinnyTextDocument
,
tokens
:
Token
[])
{
public
update
(
document
:
SkinnyTextDocument
,
config
:
MarkdownItConfig
,
tokens
:
Token
[])
{
this
.
cachedDocument
=
{
uri
:
document
.
uri
,
version
:
document
.
version
version
:
document
.
version
,
config
,
};
this
.
tokens
=
tokens
;
}
...
...
@@ -52,7 +61,7 @@ export class MarkdownEngine {
private
readonly
slugifier
:
Slugifier
,
)
{
}
private
async
getEngine
(
resource
:
vscode
.
Uri
):
Promise
<
MarkdownIt
>
{
private
async
getEngine
(
config
:
MarkdownItConfig
):
Promise
<
MarkdownIt
>
{
if
(
!
this
.
md
)
{
this
.
md
=
import
(
'
markdown-it
'
).
then
(
async
markdownIt
=>
{
const
hljs
=
await
import
(
'
highlight.js
'
);
...
...
@@ -116,16 +125,16 @@ export class MarkdownEngine {
}
const
md
=
await
this
.
md
!
;
const
config
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
,
resource
);
md
.
set
({
breaks
:
config
.
get
<
boolean
>
(
'
preview.breaks
'
,
false
),
linkify
:
config
.
get
<
boolean
>
(
'
preview.linkify
'
,
true
)
});
md
.
set
(
config
);
return
md
;
}
private
tokenize
(
document
:
SkinnyTextDocument
,
engine
:
MarkdownIt
):
Token
[]
{
const
cached
=
this
.
_tokenCache
.
tryGetCached
(
document
);
private
tokenize
(
document
:
SkinnyTextDocument
,
config
:
MarkdownItConfig
,
engine
:
MarkdownIt
):
Token
[]
{
const
cached
=
this
.
_tokenCache
.
tryGetCached
(
document
,
config
);
if
(
cached
)
{
return
cached
;
}
...
...
@@ -135,18 +144,28 @@ export class MarkdownEngine {
const
text
=
document
.
getText
();
const
tokens
=
engine
.
parse
(
text
.
replace
(
UNICODE_NEWLINE_REGEX
,
''
),
{});
this
.
_tokenCache
.
update
(
document
,
tokens
);
this
.
_tokenCache
.
update
(
document
,
config
,
tokens
);
return
tokens
;
}
public
async
render
(
document
:
SkinnyTextDocument
):
Promise
<
string
>
{
const
engine
=
await
this
.
getEngine
(
document
.
uri
);
return
engine
.
renderer
.
render
(
this
.
tokenize
(
document
,
engine
),
engine
,
{});
const
config
=
this
.
getConfig
(
document
.
uri
);
const
engine
=
await
this
.
getEngine
(
config
);
return
engine
.
renderer
.
render
(
this
.
tokenize
(
document
,
config
,
engine
),
engine
,
{});
}
public
async
parse
(
document
:
SkinnyTextDocument
):
Promise
<
Token
[]
>
{
const
engine
=
await
this
.
getEngine
(
document
.
uri
);
return
this
.
tokenize
(
document
,
engine
);
const
config
=
this
.
getConfig
(
document
.
uri
);
const
engine
=
await
this
.
getEngine
(
config
);
return
this
.
tokenize
(
document
,
config
,
engine
);
}
private
getConfig
(
resource
:
vscode
.
Uri
):
MarkdownItConfig
{
const
config
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
,
resource
);
return
{
breaks
:
config
.
get
<
boolean
>
(
'
preview.breaks
'
,
false
),
linkify
:
config
.
get
<
boolean
>
(
'
preview.linkify
'
,
true
)
};
}
private
addLineNumberRenderer
(
md
:
any
,
ruleName
:
string
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录