Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
176a27a5
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,发现更多精彩内容 >>
提交
176a27a5
编写于
5月 23, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Start encapsulating slugifier
上级
189f560f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
35 deletion
+44
-35
extensions/markdown-language-features/src/markdownEngine.ts
extensions/markdown-language-features/src/markdownEngine.ts
+6
-6
extensions/markdown-language-features/src/slugify.ts
extensions/markdown-language-features/src/slugify.ts
+35
-0
extensions/markdown-language-features/src/tableOfContentsProvider.ts
...markdown-language-features/src/tableOfContentsProvider.ts
+3
-29
未找到文件。
extensions/markdown-language-features/src/markdownEngine.ts
浏览文件 @
176a27a5
...
...
@@ -3,11 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
path
from
'
path
'
;
import
{
Slug
}
from
'
./tableOfContentsProvider
'
;
import
{
MarkdownIt
,
Token
}
from
'
markdown-it
'
;
import
*
as
path
from
'
path
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
MarkdownContributions
}
from
'
./markdownExtensions
'
;
import
{
stripSlugifier
}
from
'
./slugify
'
;
const
FrontMatterRegex
=
/^---
\s
*
[^]
*
?(
-
{3}
|
\.{3})\s
*/
;
...
...
@@ -49,7 +49,7 @@ export class MarkdownEngine {
return
`<pre class="hljs"><code><div>
${
this
.
md
!
.
utils
.
escapeHtml
(
str
)}
</div></code></pre>`
;
}
}).
use
(
mdnh
,
{
slugify
:
(
header
:
string
)
=>
Slug
.
fromHeading
(
header
).
value
slugify
:
(
header
:
string
)
=>
stripSlugifier
.
fromHeading
(
header
).
value
});
for
(
const
plugin
of
this
.
extensionPreviewResourceProvider
.
markdownItPlugins
)
{
...
...
@@ -145,13 +145,13 @@ export class MarkdownEngine {
if
(
fragment
)
{
uri
=
uri
.
with
({
fragment
:
Slug
.
fromHeading
(
fragment
).
value
fragment
:
stripSlugifier
.
fromHeading
(
fragment
).
value
});
}
return
normalizeLink
(
uri
.
with
({
scheme
:
'
vscode-resource
'
}).
toString
(
true
));
}
else
if
(
!
uri
.
scheme
&&
!
uri
.
path
&&
uri
.
fragment
)
{
return
normalizeLink
(
uri
.
with
({
fragment
:
Slug
.
fromHeading
(
uri
.
fragment
).
value
fragment
:
stripSlugifier
.
fromHeading
(
uri
.
fragment
).
value
}).
toString
(
true
));
}
}
catch
(
e
)
{
...
...
extensions/markdown-language-features/src/slugify.ts
0 → 100644
浏览文件 @
176a27a5
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export
class
Slug
{
public
constructor
(
public
readonly
value
:
string
)
{
}
public
equals
(
other
:
Slug
):
boolean
{
return
this
.
value
===
other
.
value
;
}
}
export
interface
Slugifier
{
fromHeading
(
heading
:
string
):
Slug
;
}
export
const
stripSlugifier
:
Slugifier
=
new
class
implements
Slugifier
{
private
readonly
specialChars
:
any
=
{
'
à
'
:
'
a
'
,
'
ä
'
:
'
a
'
,
'
ã
'
:
'
a
'
,
'
á
'
:
'
a
'
,
'
â
'
:
'
a
'
,
'
æ
'
:
'
a
'
,
'
å
'
:
'
a
'
,
'
ë
'
:
'
e
'
,
'
è
'
:
'
e
'
,
'
é
'
:
'
e
'
,
'
ê
'
:
'
e
'
,
'
î
'
:
'
i
'
,
'
ï
'
:
'
i
'
,
'
ì
'
:
'
i
'
,
'
í
'
:
'
i
'
,
'
ò
'
:
'
o
'
,
'
ó
'
:
'
o
'
,
'
ö
'
:
'
o
'
,
'
ô
'
:
'
o
'
,
'
ø
'
:
'
o
'
,
'
ù
'
:
'
o
'
,
'
ú
'
:
'
u
'
,
'
ü
'
:
'
u
'
,
'
û
'
:
'
u
'
,
'
ñ
'
:
'
n
'
,
'
ç
'
:
'
c
'
,
'
ß
'
:
'
s
'
,
'
ÿ
'
:
'
y
'
,
'
œ
'
:
'
o
'
,
'
ŕ
'
:
'
r
'
,
'
ś
'
:
'
s
'
,
'
ń
'
:
'
n
'
,
'
ṕ
'
:
'
p
'
,
'
ẃ
'
:
'
w
'
,
'
ǵ
'
:
'
g
'
,
'
ǹ
'
:
'
n
'
,
'
ḿ
'
:
'
m
'
,
'
ǘ
'
:
'
u
'
,
'
ẍ
'
:
'
x
'
,
'
ź
'
:
'
z
'
,
'
ḧ
'
:
'
h
'
,
'
·
'
:
'
-
'
,
'
/
'
:
'
-
'
,
'
_
'
:
'
-
'
,
'
,
'
:
'
-
'
,
'
:
'
:
'
-
'
,
'
;
'
:
'
-
'
,
'
З
'
:
'
3
'
,
'
з
'
:
'
3
'
};
public
fromHeading
(
heading
:
string
):
Slug
{
const
slugifiedHeading
=
encodeURI
(
heading
.
trim
()
.
toLowerCase
()
.
replace
(
/./g
,
c
=>
this
.
specialChars
[
c
]
||
c
)
.
replace
(
/
[\]\[\!\'\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~\`]
/g
,
''
)
.
replace
(
/
\s
+/g
,
'
-
'
)
// Replace whitespace with -
.
replace
(
/
[^\w\-]
+/g
,
''
)
// Remove remaining non-word chars
.
replace
(
/^
\-
+/
,
''
)
// Remove leading -
.
replace
(
/
\-
+$/
,
''
)
// Remove trailing -
);
return
new
Slug
(
slugifiedHeading
);
}
};
\ No newline at end of file
extensions/markdown-language-features/src/tableOfContentsProvider.ts
浏览文件 @
176a27a5
...
...
@@ -4,34 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
MarkdownEngine
}
from
'
./markdownEngine
'
;
export
class
Slug
{
private
static
specialChars
:
any
=
{
'
à
'
:
'
a
'
,
'
ä
'
:
'
a
'
,
'
ã
'
:
'
a
'
,
'
á
'
:
'
a
'
,
'
â
'
:
'
a
'
,
'
æ
'
:
'
a
'
,
'
å
'
:
'
a
'
,
'
ë
'
:
'
e
'
,
'
è
'
:
'
e
'
,
'
é
'
:
'
e
'
,
'
ê
'
:
'
e
'
,
'
î
'
:
'
i
'
,
'
ï
'
:
'
i
'
,
'
ì
'
:
'
i
'
,
'
í
'
:
'
i
'
,
'
ò
'
:
'
o
'
,
'
ó
'
:
'
o
'
,
'
ö
'
:
'
o
'
,
'
ô
'
:
'
o
'
,
'
ø
'
:
'
o
'
,
'
ù
'
:
'
o
'
,
'
ú
'
:
'
u
'
,
'
ü
'
:
'
u
'
,
'
û
'
:
'
u
'
,
'
ñ
'
:
'
n
'
,
'
ç
'
:
'
c
'
,
'
ß
'
:
'
s
'
,
'
ÿ
'
:
'
y
'
,
'
œ
'
:
'
o
'
,
'
ŕ
'
:
'
r
'
,
'
ś
'
:
'
s
'
,
'
ń
'
:
'
n
'
,
'
ṕ
'
:
'
p
'
,
'
ẃ
'
:
'
w
'
,
'
ǵ
'
:
'
g
'
,
'
ǹ
'
:
'
n
'
,
'
ḿ
'
:
'
m
'
,
'
ǘ
'
:
'
u
'
,
'
ẍ
'
:
'
x
'
,
'
ź
'
:
'
z
'
,
'
ḧ
'
:
'
h
'
,
'
·
'
:
'
-
'
,
'
/
'
:
'
-
'
,
'
_
'
:
'
-
'
,
'
,
'
:
'
-
'
,
'
:
'
:
'
-
'
,
'
;
'
:
'
-
'
,
'
З
'
:
'
3
'
,
'
з
'
:
'
3
'
};
public
static
fromHeading
(
heading
:
string
):
Slug
{
const
slugifiedHeading
=
encodeURI
(
heading
.
trim
()
.
toLowerCase
()
.
replace
(
/./g
,
c
=>
Slug
.
specialChars
[
c
]
||
c
)
.
replace
(
/
[\]\[\!\'\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~\`]
/g
,
''
)
.
replace
(
/
\s
+/g
,
'
-
'
)
// Replace whitespace with -
.
replace
(
/
[^\w\-]
+/g
,
''
)
// Remove remaining non-word chars
.
replace
(
/^
\-
+/
,
''
)
// Remove leading -
.
replace
(
/
\-
+$/
,
''
)
// Remove trailing -
);
return
new
Slug
(
slugifiedHeading
);
}
private
constructor
(
public
readonly
value
:
string
)
{
}
public
equals
(
other
:
Slug
):
boolean
{
return
this
.
value
===
other
.
value
;
}
}
import
{
Slug
,
stripSlugifier
}
from
'
./slugify
'
;
export
interface
TocEntry
{
readonly
slug
:
Slug
;
...
...
@@ -62,7 +36,7 @@ export class TableOfContentsProvider {
public
async
lookup
(
fragment
:
string
):
Promise
<
TocEntry
|
undefined
>
{
const
toc
=
await
this
.
getToc
();
const
slug
=
Slug
.
fromHeading
(
fragment
);
const
slug
=
stripSlugifier
.
fromHeading
(
fragment
);
return
toc
.
find
(
entry
=>
entry
.
slug
.
equals
(
slug
));
}
...
...
@@ -74,7 +48,7 @@ export class TableOfContentsProvider {
const
lineNumber
=
heading
.
map
[
0
];
const
line
=
document
.
lineAt
(
lineNumber
);
toc
.
push
({
slug
:
Slug
.
fromHeading
(
line
.
text
),
slug
:
stripSlugifier
.
fromHeading
(
line
.
text
),
text
:
TableOfContentsProvider
.
getHeaderText
(
line
.
text
),
level
:
TableOfContentsProvider
.
getHeaderLevel
(
heading
.
markup
),
line
:
lineNumber
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录