Accept sass interpolation syntax in most places.
This commit is contained in:
parent
a1a3854975
commit
4513433fb1
|
@ -58,6 +58,16 @@ fn block_comment<'s>(input: &mut &'s str) -> PResult<&'s str> {
|
|||
.parse_next(input)
|
||||
}
|
||||
|
||||
// matches a sass interpolation of the form #{...}
|
||||
fn sass_interpolation<'s>(input: &mut &'s str) -> PResult<&'s str> {
|
||||
(
|
||||
"#{",
|
||||
cut_err(terminated(take_till(1.., ('{', '}', '\n')), '}')),
|
||||
)
|
||||
.recognize()
|
||||
.parse_next(input)
|
||||
}
|
||||
|
||||
fn identifier<'s>(input: &mut &'s str) -> PResult<&'s str> {
|
||||
(
|
||||
one_of(('_', '-', AsChar::is_alpha)),
|
||||
|
@ -114,8 +124,10 @@ pub fn stuff_till<'s>(
|
|||
string.void(),
|
||||
block_comment.void(),
|
||||
line_comment.void(),
|
||||
sass_interpolation.void(),
|
||||
'/'.void(),
|
||||
take_till(1.., ('\'', '"', '/', list)).void(),
|
||||
'#'.void(),
|
||||
take_till(1.., ('\'', '"', '/', '#', list)).void(),
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
@ -462,4 +474,27 @@ mod tests {
|
|||
println!("{input}");
|
||||
assert!(input.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sass_interpolation() {
|
||||
let mut input = "#{$test-test}END";
|
||||
|
||||
let r = sass_interpolation.parse_next(&mut input);
|
||||
assert_eq!(r, Ok("#{$test-test}"));
|
||||
|
||||
assert_eq!(input, "END");
|
||||
|
||||
let mut input = "#{$test-test
|
||||
}END";
|
||||
let r = sass_interpolation.parse_next(&mut input);
|
||||
assert!(r.is_err());
|
||||
|
||||
let mut input = "#{$test-test";
|
||||
let r = sass_interpolation.parse_next(&mut input);
|
||||
assert!(r.is_err());
|
||||
|
||||
let mut input = "#{$test-te{st}";
|
||||
let r = sass_interpolation.parse_next(&mut input);
|
||||
assert!(r.is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ $some-scss-variable: 10px; // Scss variable declarations in top scope.
|
|||
|
||||
@layer;
|
||||
|
||||
@container (width > 400px) {
|
||||
@container (min-width: #{$screen-md}) {
|
||||
h2 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue