如何使用javascript编译嵌套的css规则
我需要一些帮助来用JavaScript制作我自己的css编译器 如何制作编译此嵌套规则的编译器示例:如何使用javascript编译嵌套的css规则,javascript,compiler-construction,stylesheet,Javascript,Compiler Construction,Stylesheet,我需要一些帮助来用JavaScript制作我自己的css编译器 如何制作编译此嵌套规则的编译器示例: html{ background: #2E2E2E; body{ height: 200px; width: 100%; background: #fff; a{ color: rgb(0, 0, 255); &:hover{ c
html{
background: #2E2E2E;
body{
height: 200px;
width: 100%;
background: #fff;
a{
color: rgb(0, 0, 255);
&:hover{
color: rgb(200, 0, 255);
}
}
}
}
html{
background: #2E2E2E;
}
html body{
height: 200px;
width: 100%;
background: #fff;
}
html body a{
color: rgb(0, 0, 255);
}
html body a:hover{
color: rgb(200, 0, 255);
}
进入这个:
html{
background: #2E2E2E;
body{
height: 200px;
width: 100%;
background: #fff;
a{
color: rgb(0, 0, 255);
&:hover{
color: rgb(200, 0, 255);
}
}
}
}
html{
background: #2E2E2E;
}
html body{
height: 200px;
width: 100%;
background: #fff;
}
html body a{
color: rgb(0, 0, 255);
}
html body a:hover{
color: rgb(200, 0, 255);
}
谢谢你的帮助
如果你投了反对票,请告诉我原因。我首先要提到的是,构建自己的css编译器绝非玩笑。这是一件严肃的事情。您应该使用Sass、Less或手写笔之类的工具。如果他们缺少您需要的功能,您应该为他们构建一个插件,而不是尝试实现您自己的引擎
话虽如此,你的问题的答案可能是。这是一个人们将用来制作自己的CSS编译器的项目 你在使用编译器吗?也许你看,我没有使用编译器,我正在制作编译器。到目前为止你做了什么。你是如何“制作”它的?您只需编写规则来重新格式化样式表。。。所有Sass Less或SCS都是不同格式的文本文件,预编译器只需读取格式并输出预期的css。如果要编写编译器,必须编写规则。。读取一个文件,确定返回输出的规则和模式。简单但很长的过程。我不知道你为什么要重新发明轮子。@MathewFoscarini我用RegExp做了一些尝试……但都没有成功。这就是我在这里问的原因。我不想要任何涉及节点js的东西。你希望你的CSS编译器使用什么语言?那么,你希望它在浏览器中编译吗?是的…我知道有一些缺点,但我想试试这个。