Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e325cce9
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,发现更多精彩内容 >>
提交
e325cce9
编写于
1月 09, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixing markdown unit tests
上级
91402850
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
31 deletion
+35
-31
extensions/markdown-language-features/src/markdownEngine.ts
extensions/markdown-language-features/src/markdownEngine.ts
+30
-27
extensions/markdown-language-features/src/tableOfContentsProvider.ts
...markdown-language-features/src/tableOfContentsProvider.ts
+1
-0
extensions/markdown-language-features/src/test/inMemoryDocument.ts
...s/markdown-language-features/src/test/inMemoryDocument.ts
+2
-2
extensions/markdown-language-features/src/test/workspaceSymbolProvider.test.ts
...anguage-features/src/test/workspaceSymbolProvider.test.ts
+2
-2
未找到文件。
extensions/markdown-language-features/src/markdownEngine.ts
浏览文件 @
e325cce9
...
...
@@ -13,16 +13,19 @@ import { SkinnyTextDocument } from './tableOfContentsProvider';
import
{
getUriForLinkWithKnownExternalScheme
}
from
'
./util/links
'
;
const
FrontMatterRegex
=
/^---
\s
*
[^]
*
?(
-
{3}
|
\.{3})\s
*/
;
const
UNICODE_NEWLINE_REGEX
=
/
\u
2028|
\u
2029/g
;
export
class
MarkdownEngine
{
private
md
?:
MarkdownIt
;
private
firstLine
?:
number
;
private
currentDocument
?:
vscode
.
Uri
;
private
_slugCount
=
new
Map
<
string
,
number
>
();
private
cachedTokens
=
new
Map
<
vscode
.
Uri
,
Token
[]
>
();
private
_cache
?:
{
readonly
document
:
vscode
.
Uri
;
readonly
version
:
number
;
readonly
tokens
:
Token
[]
};
public
constructor
(
private
readonly
extensionPreviewResourceProvider
:
MarkdownContributions
,
...
...
@@ -86,24 +89,32 @@ export class MarkdownEngine {
return
this
.
md
;
}
private
stripFrontmatter
(
text
:
string
):
{
text
:
string
,
o
ffset
:
number
}
{
private
stripFrontmatter
(
text
:
string
):
{
frontMatter
?:
string
,
body
:
string
,
lineO
ffset
:
number
}
{
let
offset
=
0
;
const
frontMatterMatch
=
FrontMatterRegex
.
exec
(
text
);
let
frontMatter
:
string
|
undefined
;
if
(
frontMatterMatch
)
{
const
frontMatter
=
frontMatterMatch
[
0
];
frontMatter
=
frontMatterMatch
[
0
];
offset
=
frontMatter
.
split
(
/
\r\n
|
\n
|
\r
/g
).
length
-
1
;
text
=
text
.
substr
(
frontMatter
.
length
);
}
return
{
text
,
offset
};
return
{
frontMatter
,
body
:
text
,
lineOffset
:
offset
};
}
private
tokenize
(
document
:
SkinnyTextDocument
,
engine
:
MarkdownIt
):
Token
[]
{
const
UNICODE_NEWLINE_REGEX
=
/
\u
2028|
\u
2029/g
;
const
{
text
,
offset
}
=
this
.
stripFrontmatter
(
document
.
getText
());
const
{
body
:
text
,
lineOffset
:
offset
}
=
this
.
stripFrontmatter
(
document
.
getText
());
const
uri
=
document
.
uri
;
if
(
this
.
cachedTokens
.
has
(
uri
))
{
return
this
.
cachedTokens
.
get
(
uri
)
!
;
if
(
this
.
_cache
&&
this
.
_cache
.
document
.
toString
()
===
uri
.
toString
()
&&
this
.
_cache
.
version
===
document
.
version
)
{
return
this
.
_cache
.
tokens
;
}
this
.
currentDocument
=
document
.
uri
;
this
.
_slugCount
=
new
Map
<
string
,
number
>
();
this
.
firstLine
=
offset
;
const
tokens
=
engine
.
parse
(
text
.
replace
(
UNICODE_NEWLINE_REGEX
,
''
),
{}).
map
(
token
=>
{
if
(
token
.
map
)
{
token
.
map
[
0
]
+=
offset
;
...
...
@@ -111,29 +122,21 @@ export class MarkdownEngine {
}
return
token
;
});
this
.
cachedTokens
.
set
(
uri
,
tokens
);
this
.
_cache
=
{
tokens
,
document
:
uri
,
version
:
document
.
version
};
return
tokens
;
}
public
async
render
(
document
:
SkinnyTextDocument
,
stripFrontmatter
:
boolean
):
Promise
<
string
>
{
let
offset
=
0
;
let
text
=
document
.
getText
();
if
(
stripFrontmatter
)
{
const
markdownContent
=
this
.
stripFrontmatter
(
text
);
offset
=
markdownContent
.
offset
;
text
=
markdownContent
.
text
;
}
this
.
currentDocument
=
document
.
uri
;
this
.
firstLine
=
offset
;
this
.
_slugCount
=
new
Map
<
string
,
number
>
();
public
async
render
(
document
:
SkinnyTextDocument
,
_stripFrontmatter
:
boolean
):
Promise
<
string
>
{
const
engine
=
await
this
.
getEngine
(
document
.
uri
);
return
engine
.
renderer
.
render
(
this
.
tokenize
(
document
,
engine
),
this
.
md
,
{});
const
html
=
engine
.
renderer
.
render
(
this
.
tokenize
(
document
,
engine
),
this
.
md
,
{});
return
html
;
}
public
async
parse
(
document
:
SkinnyTextDocument
):
Promise
<
Token
[]
>
{
this
.
currentDocument
=
document
.
uri
;
this
.
_slugCount
=
new
Map
<
string
,
number
>
();
const
engine
=
await
this
.
getEngine
(
document
.
uri
);
return
this
.
tokenize
(
document
,
engine
);
}
...
...
extensions/markdown-language-features/src/tableOfContentsProvider.ts
浏览文件 @
e325cce9
...
...
@@ -17,6 +17,7 @@ export interface TocEntry {
export
interface
SkinnyTextDocument
{
readonly
uri
:
vscode
.
Uri
;
readonly
version
:
number
;
readonly
lineCount
:
number
;
getText
():
string
;
lineAt
(
line
:
number
):
vscode
.
TextLine
;
...
...
extensions/markdown-language-features/src/test/inMemoryDocument.ts
浏览文件 @
e325cce9
...
...
@@ -10,7 +10,8 @@ export class InMemoryDocument implements vscode.TextDocument {
constructor
(
public
readonly
uri
:
vscode
.
Uri
,
private
readonly
_contents
:
string
private
readonly
_contents
:
string
,
public
readonly
version
=
1
,
)
{
this
.
_lines
=
this
.
_contents
.
split
(
/
\n
/g
);
}
...
...
@@ -18,7 +19,6 @@ export class InMemoryDocument implements vscode.TextDocument {
isUntitled
:
boolean
=
false
;
languageId
:
string
=
''
;
version
:
number
=
1
;
isDirty
:
boolean
=
false
;
isClosed
:
boolean
=
false
;
eol
:
vscode
.
EndOfLine
=
vscode
.
EndOfLine
.
LF
;
...
...
extensions/markdown-language-features/src/test/workspaceSymbolProvider.test.ts
浏览文件 @
e325cce9
...
...
@@ -52,7 +52,7 @@ suite('markdown.WorkspaceSymbolProvider', () => {
const
testFileName
=
vscode
.
Uri
.
file
(
'
test.md
'
);
const
workspaceFileProvider
=
new
InMemoryWorkspaceMarkdownDocumentProvider
([
new
InMemoryDocument
(
testFileName
,
`# header1`
)
new
InMemoryDocument
(
testFileName
,
`# header1`
,
1
/* version */
)
]);
const
provider
=
new
MarkdownWorkspaceSymbolProvider
(
symbolProvider
,
workspaceFileProvider
);
...
...
@@ -60,7 +60,7 @@ suite('markdown.WorkspaceSymbolProvider', () => {
assert
.
strictEqual
((
await
provider
.
provideWorkspaceSymbols
(
''
)).
length
,
1
);
// Update file
workspaceFileProvider
.
updateDocument
(
new
InMemoryDocument
(
testFileName
,
`# new header\nabc\n## header2`
));
workspaceFileProvider
.
updateDocument
(
new
InMemoryDocument
(
testFileName
,
`# new header\nabc\n## header2`
,
2
/* version */
));
const
newSymbols
=
await
provider
.
provideWorkspaceSymbols
(
''
);
assert
.
strictEqual
(
newSymbols
.
length
,
2
);
assert
.
strictEqual
(
newSymbols
[
0
].
name
,
'
# new header
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录