Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
067ed91b
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,发现更多精彩内容 >>
提交
067ed91b
编写于
9月 14, 2018
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow emmet inside script tag with js mime if js is mapped to html Fixes #58562
上级
e6ef901b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
5 deletion
+63
-5
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+13
-2
extensions/emmet/src/test/abbreviationAction.test.ts
extensions/emmet/src/test/abbreviationAction.test.ts
+49
-2
extensions/emmet/src/util.ts
extensions/emmet/src/util.ts
+1
-1
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
067ed91b
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
Node
,
HtmlNode
,
Rule
,
Property
,
Stylesheet
}
from
'
EmmetNode
'
;
import
{
Node
,
HtmlNode
,
Rule
,
Property
,
Stylesheet
}
from
'
EmmetNode
'
;
import
{
getEmmetHelper
,
getNode
,
getInnerRange
,
getMappingForIncludedLanguages
,
parseDocument
,
validate
,
getEmmetConfiguration
,
isStyleSheet
,
getEmmetMode
,
parsePartialStylesheet
,
isStyleAttribute
,
getEmbeddedCssNodeIfAny
,
isTemplateScript
}
from
'
./util
'
;
import
{
getEmmetHelper
,
getNode
,
getInnerRange
,
getMappingForIncludedLanguages
,
parseDocument
,
validate
,
getEmmetConfiguration
,
isStyleSheet
,
getEmmetMode
,
parsePartialStylesheet
,
isStyleAttribute
,
getEmbeddedCssNodeIfAny
,
allowedMimeTypesInScriptTag
}
from
'
./util
'
;
const
trimRegex
=
/
[\u
00a0
]
*
[\d
|#|
\-
|
\*
|
\u
2022
]
+
\.?
/
;
const
trimRegex
=
/
[\u
00a0
]
*
[\d
|#|
\-
|
\*
|
\u
2022
]
+
\.?
/
;
const
hexColorRegex
=
/^#
[\d
,a-f,A-F
]{0,6}
$/
;
const
hexColorRegex
=
/^#
[\d
,a-f,A-F
]{0,6}
$/
;
...
@@ -442,7 +442,18 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
...
@@ -442,7 +442,18 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
if
(
currentHtmlNode
)
{
if
(
currentHtmlNode
)
{
if
(
currentHtmlNode
.
name
===
'
script
'
)
{
if
(
currentHtmlNode
.
name
===
'
script
'
)
{
return
isTemplateScript
(
currentHtmlNode
);
const
typeAttribute
=
(
currentHtmlNode
.
attributes
||
[]).
filter
(
x
=>
x
.
name
.
toString
()
===
'
type
'
)[
0
];
const
typeValue
=
typeAttribute
?
typeAttribute
.
value
.
toString
()
:
''
;
if
(
allowedMimeTypesInScriptTag
.
indexOf
(
typeValue
)
>
-
1
)
{
return
true
;
}
const
isScriptJavascriptType
=
!
typeValue
||
typeValue
===
'
application/javascript
'
||
typeValue
===
'
text/javascript
'
;
if
(
isScriptJavascriptType
)
{
return
!!
getSyntaxFromArgs
({
language
:
'
javascript
'
});
}
return
false
;
}
}
const
innerRange
=
getInnerRange
(
currentHtmlNode
);
const
innerRange
=
getInnerRange
(
currentHtmlNode
);
...
...
extensions/emmet/src/test/abbreviationAction.test.ts
浏览文件 @
067ed91b
...
@@ -36,13 +36,14 @@ const htmlContents = `
...
@@ -36,13 +36,14 @@ const htmlContents = `
span.hello
span.hello
</script>
</script>
<script type="text/javascript">
<script type="text/javascript">
span.
hello
span.
bye
</script>
</script>
</body>
</body>
`
;
`
;
suite
(
'
Tests for Expand Abbreviations (HTML)
'
,
()
=>
{
suite
(
'
Tests for Expand Abbreviations (HTML)
'
,
()
=>
{
const
oldValueForExcludeLanguages
=
workspace
.
getConfiguration
(
'
emmet
'
).
inspect
(
'
excludeLanguages
'
);
const
oldValueForExcludeLanguages
=
workspace
.
getConfiguration
(
'
emmet
'
).
inspect
(
'
excludeLanguages
'
);
const
oldValueForInlcudeLanguages
=
workspace
.
getConfiguration
(
'
emmet
'
).
inspect
(
'
includeLanguages
'
);
teardown
(()
=>
{
teardown
(()
=>
{
// close all editors
// close all editors
return
closeAllEditors
;
return
closeAllEditors
;
...
@@ -337,7 +338,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
...
@@ -337,7 +338,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
});
});
});
});
test
(
'
Expand html when inside script tag with html type (HTML)
'
,
()
=>
{
test
(
'
Expand html
in completion list
when inside script tag with html type (HTML)
'
,
()
=>
{
const
abbreviation
=
'
span.hello
'
;
const
abbreviation
=
'
span.hello
'
;
const
expandedText
=
'
<span class="hello"></span>
'
;
const
expandedText
=
'
<span class="hello"></span>
'
;
...
@@ -383,6 +384,52 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
...
@@ -383,6 +384,52 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
});
});
});
});
test
(
'
Expand html when inside script tag with javascript type if js is mapped to html (HTML)
'
,
()
=>
{
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
{
"
javascript
"
:
"
html
"
},
ConfigurationTarget
.
Global
).
then
(()
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
24
,
10
,
24
,
10
);
let
expandPromise
=
expandEmmetAbbreviation
(
null
);
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
return
expandPromise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
span.bye
'
,
'
<span class="bye"></span>
'
));
});
}).
then
(()
=>
{
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
oldValueForInlcudeLanguages
||
{},
ConfigurationTarget
.
Global
);
});
});
});
test
(
'
Expand html in completion list when inside script tag with javascript type if js is mapped to html (HTML)
'
,
()
=>
{
const
abbreviation
=
'
span.bye
'
;
const
expandedText
=
'
<span class="bye"></span>
'
;
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
{
"
javascript
"
:
"
html
"
},
ConfigurationTarget
.
Global
).
then
(()
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
24
,
10
,
24
,
10
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding span.bye`
);
return
Promise
.
resolve
();
}
return
completionPromise
.
then
((
completionList
:
CompletionList
)
=>
{
if
(
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding span.bye`
);
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
equal
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item (
${
emmetCompletionItem
.
label
}
) doesnt match.`
);
assert
.
equal
((
<
string
>
emmetCompletionItem
.
documentation
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
}).
then
(()
=>
{
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
oldValueForInlcudeLanguages
||
{},
ConfigurationTarget
.
Global
);
});
});
});
// test('No expanding when html is excluded in the settings', () => {
// test('No expanding when html is excluded in the settings', () => {
// return workspace.getConfiguration('emmet').update('excludeLanguages', ['html'], ConfigurationTarget.Global).then(() => {
// return workspace.getConfiguration('emmet').update('excludeLanguages', ['html'], ConfigurationTarget.Global).then(() => {
// return testExpandAbbreviation('html', new Selection(9, 6, 9, 6), '', '', true).then(() => {
// return testExpandAbbreviation('html', new Selection(9, 6, 9, 6), '', '', true).then(() => {
...
...
extensions/emmet/src/util.ts
浏览文件 @
067ed91b
...
@@ -47,7 +47,7 @@ export const LANGUAGE_MODES: any = {
...
@@ -47,7 +47,7 @@ export const LANGUAGE_MODES: any = {
'
typescriptreact
'
:
[
'
!
'
,
'
.
'
,
'
}
'
,
'
*
'
,
'
$
'
,
'
]
'
,
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
]
'
typescriptreact
'
:
[
'
!
'
,
'
.
'
,
'
}
'
,
'
*
'
,
'
$
'
,
'
]
'
,
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
]
};
};
const
allowedMimeTypesInScriptTag
=
[
'
text/html
'
,
'
text/plain
'
,
'
text/x-template
'
,
'
text/template
'
,
'
text/ng-template
'
];
export
const
allowedMimeTypesInScriptTag
=
[
'
text/html
'
,
'
text/plain
'
,
'
text/x-template
'
,
'
text/template
'
,
'
text/ng-template
'
];
const
emmetModes
=
[
'
html
'
,
'
pug
'
,
'
slim
'
,
'
haml
'
,
'
xml
'
,
'
xsl
'
,
'
jsx
'
,
'
css
'
,
'
scss
'
,
'
sass
'
,
'
less
'
,
'
stylus
'
];
const
emmetModes
=
[
'
html
'
,
'
pug
'
,
'
slim
'
,
'
haml
'
,
'
xml
'
,
'
xsl
'
,
'
jsx
'
,
'
css
'
,
'
scss
'
,
'
sass
'
,
'
less
'
,
'
stylus
'
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录