Skip to content

Commit

Permalink
Added support for @charset and @namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Apr 5, 2017
1 parent 8e1f116 commit 72e862b
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 4 deletions.
9 changes: 9 additions & 0 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ function format(content, options) {
// Remove the extra new-line because of `Ident` and `Block`
outputBuffer.remove(options.newLineChar)

} else if (inputNode instanceof stylus.nodes.Charset) {
outputBuffer.append('@charset ')
outputBuffer.append(travel(inputNode, inputNode.val, indentLevel, true))

} else if (inputNode instanceof stylus.nodes.Namespace) {
outputBuffer.append('@namespace ')
outputBuffer.append(inputNode.prefix ? (inputNode.prefix + ' ') : '')
outputBuffer.append(travel(inputNode, inputNode.val, indentLevel, true))

} else if (inputNode instanceof stylus.nodes.Comment && inputNode.str.startsWith('//')) { // In case of single-line comments
if (insideExpression === false) {
outputBuffer.append(indent)
Expand Down
13 changes: 13 additions & 0 deletions spec/charset/formattingOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"insertColons": true,
"insertSemicolons": true,
"insertBraces": true,
"insertNewLineBetweenGroups": 1,
"insertNewLineBetweenSelectors": false,
"insertSpaceBeforeComments": true,
"insertSpaceAfterComments": true,
"indentChar": "\t",
"newLineChar": "\r\n",
"sortProperties": false,
"alwaysUseImport": false
}
1 change: 1 addition & 0 deletions spec/charset/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@charset 'utf-8'
1 change: 1 addition & 0 deletions spec/charset/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@charset 'utf-8'
2 changes: 2 additions & 0 deletions spec/function/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ anonymous-func=@(a,b) {

body
color mix(#000,#fff,30%)
color rgba(115,51,38,0.5)
color hsla(10deg, 50%, 30%, 0.5)

+prefix-classes('foo-')
.bar
Expand Down
2 changes: 2 additions & 0 deletions spec/function/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ anonymous-func = @(a, b) {

body {
color: mix(#000, #fff, 30%);
color: rgba(115, 51, 38, 0.5);
color: hsla(10deg, 50%, 30%, 0.5);
}

+prefix-classes('foo-') {
Expand Down
5 changes: 4 additions & 1 deletion spec/mixin/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ foo()

nested-mixin(n)
inner-mixin(m)
margin n m
margin n m

body
nested-mixin(1)
4 changes: 4 additions & 0 deletions spec/mixin/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ nested-mixin(n) {
inner-mixin(m) {
margin: n m;
}
}

body {
nested-mixin(1);
}
13 changes: 13 additions & 0 deletions spec/namespace/formattingOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"insertColons": true,
"insertSemicolons": true,
"insertBraces": true,
"insertNewLineBetweenGroups": 1,
"insertNewLineBetweenSelectors": false,
"insertSpaceBeforeComments": true,
"insertSpaceAfterComments": true,
"indentChar": "\t",
"newLineChar": "\r\n",
"sortProperties": false,
"alwaysUseImport": false
}
1 change: 1 addition & 0 deletions spec/namespace/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@namespace 'http://www.w3.org/1999/xhtml'
4 changes: 4 additions & 0 deletions spec/namespace/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
img {
src: url('fonts/geo_sans_light/GensansLight.ttf');
src: url('fonts/geo_sans_light/GensansLight.ttf');
}
6 changes: 5 additions & 1 deletion spec/property/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ body
filter unquote('progid:DXImageTransform.Microsoft.Alpha(Opacity='+round(n*100)+')')
padding 1 \+ 2
font 14px/1.4
font (14px/1.4)
font (14px/1.4)
transition .3s opacity
-webkit-user-select none
-moz-user-select none
-ms-user-select none
4 changes: 4 additions & 0 deletions spec/property/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ body {
padding: 1 \+ 2;
font: 14px / 1.4;
font: (14px / 1.4);
transition: 0.3s opacity;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
14 changes: 13 additions & 1 deletion spec/selector/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ body
/body
display none

.class2
.class2.class3
../input
display none

.\\--class4
display none

&:hover:not(.--limited)
display none

&[disabled]
display none

input[type=number]::-webkit-outer-spin-button
display none

body > a
display none
18 changes: 17 additions & 1 deletion spec/selector/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,27 @@ body {
}
}

.class2 {
.class2.class3 {
../input {
display: none;
}
}

.\\--class4 {
display: none;
}

&:hover:not(.--limited) {
display: none;
}

&[disabled] {
display: none;
}

input[type=number]::-webkit-outer-spin-button {
display: none;
}
}

body > a {
Expand Down

0 comments on commit 72e862b

Please sign in to comment.