Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
281f242c
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,发现更多精彩内容 >>
提交
281f242c
编写于
5月 25, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't strip special characters in slugify
Fixes #48482
上级
feeefd10
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
26 deletion
+22
-26
extensions/markdown-language-features/src/extension.ts
extensions/markdown-language-features/src/extension.ts
+2
-2
extensions/markdown-language-features/src/slugify.ts
extensions/markdown-language-features/src/slugify.ts
+10
-13
extensions/markdown-language-features/src/tableOfContentsProvider.ts
...markdown-language-features/src/tableOfContentsProvider.ts
+3
-3
extensions/markdown-language-features/src/test/engine.ts
extensions/markdown-language-features/src/test/engine.ts
+2
-2
extensions/markdown-language-features/src/test/tableOfContentsProvider.test.ts
...anguage-features/src/test/tableOfContentsProvider.test.ts
+5
-6
未找到文件。
extensions/markdown-language-features/src/extension.ts
浏览文件 @
281f242c
...
...
@@ -17,7 +17,7 @@ import { MarkdownEngine } from './markdownEngine';
import
{
getMarkdownExtensionContributions
}
from
'
./markdownExtensions
'
;
import
{
ExtensionContentSecurityPolicyArbiter
,
PreviewSecuritySelector
}
from
'
./security
'
;
import
{
loadDefaultTelemetryReporter
}
from
'
./telemetryReporter
'
;
import
{
strip
Slugifier
}
from
'
./slugify
'
;
import
{
github
Slugifier
}
from
'
./slugify
'
;
export
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
...
...
@@ -27,7 +27,7 @@ export function activate(context: vscode.ExtensionContext) {
const
contributions
=
getMarkdownExtensionContributions
();
const
cspArbiter
=
new
ExtensionContentSecurityPolicyArbiter
(
context
.
globalState
,
context
.
workspaceState
);
const
engine
=
new
MarkdownEngine
(
contributions
,
strip
Slugifier
);
const
engine
=
new
MarkdownEngine
(
contributions
,
github
Slugifier
);
const
logger
=
new
Logger
();
const
selector
:
vscode
.
DocumentSelector
=
[
...
...
extensions/markdown-language-features/src/slugify.ts
浏览文件 @
281f242c
...
...
@@ -17,19 +17,16 @@ 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 -
export
const
githubSlugifier
:
Slugifier
=
new
class
implements
Slugifier
{
fromHeading
(
heading
:
string
):
Slug
{
const
slugifiedHeading
=
encodeURI
(
heading
.
trim
()
.
toLowerCase
()
.
replace
(
/
\s
+/g
,
'
-
'
)
// Replace whitespace with -
.
replace
(
/
[^\w\-]
+/gu
,
''
)
// Remove 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
浏览文件 @
281f242c
...
...
@@ -5,7 +5,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
{
MarkdownEngine
}
from
'
./markdownEngine
'
;
import
{
Slug
,
strip
Slugifier
}
from
'
./slugify
'
;
import
{
Slug
,
github
Slugifier
}
from
'
./slugify
'
;
export
interface
TocEntry
{
readonly
slug
:
Slug
;
...
...
@@ -36,7 +36,7 @@ export class TableOfContentsProvider {
public
async
lookup
(
fragment
:
string
):
Promise
<
TocEntry
|
undefined
>
{
const
toc
=
await
this
.
getToc
();
const
slug
=
strip
Slugifier
.
fromHeading
(
fragment
);
const
slug
=
github
Slugifier
.
fromHeading
(
fragment
);
return
toc
.
find
(
entry
=>
entry
.
slug
.
equals
(
slug
));
}
...
...
@@ -48,7 +48,7 @@ export class TableOfContentsProvider {
const
lineNumber
=
heading
.
map
[
0
];
const
line
=
document
.
lineAt
(
lineNumber
);
toc
.
push
({
slug
:
strip
Slugifier
.
fromHeading
(
line
.
text
),
slug
:
github
Slugifier
.
fromHeading
(
line
.
text
),
text
:
TableOfContentsProvider
.
getHeaderText
(
line
.
text
),
level
:
TableOfContentsProvider
.
getHeaderLevel
(
heading
.
markup
),
line
:
lineNumber
,
...
...
extensions/markdown-language-features/src/test/engine.ts
浏览文件 @
281f242c
...
...
@@ -6,7 +6,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
{
MarkdownEngine
}
from
'
../markdownEngine
'
;
import
{
MarkdownContributions
}
from
'
../markdownExtensions
'
;
import
{
strip
Slugifier
}
from
'
../slugify
'
;
import
{
github
Slugifier
}
from
'
../slugify
'
;
const
emptyContributions
=
new
class
implements
MarkdownContributions
{
readonly
previewScripts
:
vscode
.
Uri
[]
=
[];
...
...
@@ -16,5 +16,5 @@ const emptyContributions = new class implements MarkdownContributions {
};
export
function
createNewMarkdownEngine
():
MarkdownEngine
{
return
new
MarkdownEngine
(
emptyContributions
,
strip
Slugifier
);
return
new
MarkdownEngine
(
emptyContributions
,
github
Slugifier
);
}
extensions/markdown-language-features/src/test/tableOfContentsProvider.test.ts
浏览文件 @
281f242c
...
...
@@ -75,18 +75,17 @@ suite('markdown.TableOfContentsProvider', () => {
assert
.
strictEqual
(
await
provider
.
lookup
(
'
fo o
'
),
undefined
);
});
test
(
'
should
normaliz
e special characters #44779
'
,
async
()
=>
{
test
(
'
should
handl
e special characters #44779
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`# Indentação\n`
);
const
provider
=
new
TableOfContentsProvider
(
createNewMarkdownEngine
(),
doc
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
indenta
ca
o
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
indenta
çã
o
'
))
!
.
line
,
0
);
});
test
(
'
should
map special З, #37079
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`#
## Заголовок Header 3
`
);
test
(
'
should
handle special characters 2, #48482
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`#
Инструкция - Делай Раз, Делай Два\n
`
);
const
provider
=
new
TableOfContentsProvider
(
createNewMarkdownEngine
(),
doc
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
Заголовок-header-3
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
3аголовок-header-3
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
инструкция---делай-раз-делай-два
'
))
!
.
line
,
0
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录