http://www.ibm.com/developerworks/cn/web/wa-lo-firefox-ext/index.html
<html>
<head>
<style>
textarea{
width:800px;
height:250px;
}
</style>
<script>
function trans(){
var content = document.getElementById("content");
//去除注释
content = removeComment(content.value);
//去除换行
content = removeLine(content);
content = removeSpace(content);
//转换成css数组
var cssList = cssConvert(content);
for(var i=0;i<cssList.length;i++){
alert(cssList[i].attrName + " " +cssList[i].attrValue+ " " +cssList[i].cssNum);
}
document.getElementById("result").value = content;
}
//转换成css数组
function cssConvert(txt){
var cssList = [];
var isOpen = false;
var attrName="";
var attrValue = "";
var cssNum = 1;
for(var i=0;i<txt.length;i++){
if(txt[i] == '{') {
isOpen = true;
continue;
}
if(txt[i] == '}') {
isOpen = false;
cssList.push({attrName:attrName,attrValue:attrValue,cssNum:cssNum});
cssNum ++;
attrValue = "";
attrValue = "";
continue;
}
if(isOpen){
attrValue += txt[i];
} else {
attrName += txt[i];
}
}
return cssList;
}
//去除换行
function removeLine(txt){
txt = txt.replace(/<\/?.+?>/g,"");
txt = txt.replace(/[\r\n]/g, "");
return txt;
}
function removeSpace(txt){
var isOpen =false;
for(var i=0;i<txt.length;i++){
if(txt[i]=='{'){
isOpen = true;
if(i-1>=0&&txt[i-1] == ' ') {
txt = removeAt(txt,i-1);
i--;
}
}
if(txt[i]=='}') isOpen = false;
//符合条件的去空格
if((i-1>=0&&i+1<txt.length&&txt[i]==' '&&isOpen ==true&&(txt[i-1]==':'||txt[i+1]==':'||txt[i-1]==' '||txt[i+1]==' '||txt[i-1]==';'||txt[i+1]==';'||txt[i-1]=='{'||txt[i-1]=='}'))||(i-1>=0&&txt[i]==' '&&txt[i-1]==' ')||(i-1>=0&&txt[i]==' '&&txt[i-1]=='}')){
txt = removeAt(txt,i);
i--;
} else if(i-1>=0&&i+1<txt.length&&isOpen ==false&&txt[i]==' '&&(txt[i-1]==','||txt[i+1]==','||txt[i-1]==' '||txt[i+1]==' ') ){
txt = removeAt(txt,i);
i--;
}
}
return txt;
//return txt.replace(/\s+/g, "");//.replace(/\s+/g, "");
}
function removeAt(txt,i){
temp = txt.substr(0,i);
temp += txt.substring(i+1);
return temp;
}
//去除注释
function removeComment(txt){
while(true){
var start = txt.indexOf("/*");
var end = txt.indexOf("*/");
var temp = "";
if(start >= 0 && end >= 0){
temp = txt.substring(0,start);
temp += txt.substring(end+2);
txt = temp;
} else {
return txt;
}
}
}
</script>
</head>
<body>
<textarea id="content"></textarea>
<input type="button" value="转换" onclick="trans()"/>
<textarea id="result"></textarea>
</body>
</html>
http://www.ibm.com/developerworks/cn/web/wa-lo-firefox-ext/index.html的更多相关文章
- http://www.ibm.com/developerworks/cn/web/wa-aj-jsonp1/index.html
http://www.ibm.com/developerworks/cn/web/wa-aj-jsonp1/index.html
- http://www.ibm.com/developerworks/cn/java/j-lo-junit-src/
http://www.ibm.com/developerworks/cn/java/j-lo-junit-src/
- http://www.ibm.com/developerworks/cn/java/j-lo-hotswapcls/
http://www.ibm.com/developerworks/cn/java/j-lo-hotswapcls/
- http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
- Infrastructure as Code 行为驱动开发指南 https://www.ibm.com/developerworks/cn/devops/d-bbd-guide-iac/index.html
Infrastructure as Code 行为驱动开发指南 https://www.ibm.com/developerworks/cn/devops/d-bbd-guide-iac/index.h ...
- 使用 CAS 在 Tomcat 中实现单点登录 http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
developerWorks 中国 技术主题 Open source 文档库 使用 CAS 在 Tomcat 中实现单点登录 单点登录(Single Sign On , 简称 SSO )是目前比较流行 ...
- Java Content Repository API 简介 转自(https://www.ibm.com/developerworks/cn/java/j-jcr/)
Java Content Repository API 简介 1 如果曾经试过开发内容管理应用程序,那么您应当非常清楚在实现内容系统时所遇到的固有难题.这个领地有点支离破碎,许多供应商都有自己的私有仓 ...
- robotframework安装和配置【转IBM:https://www.ibm.com/developerworks/cn/opensource/os-cn-robot-framework/index.html】
内容 概览 Robot Framework 介绍 Robot Framework 的安装和配置 RIDE 编辑器介绍 创建测试项目 简单的测试用例的编写 总结 相关主题 评论 Robot Fr ...
- CDH5X 安装oozie报错To enable Oozie web console install the Ext JS library.
最近在CDH5.X 安装oozie 服务,服务安装完毕,访问oozie server ui,报如下错误: 页面提示: Oozie web console is disabled.To enable O ...
随机推荐
- DB2 Error Messages (Sorted by SQLCODE)
DB2 Error Messages (Sorted by SQLCODE) DB2 Error Messages (Sorted by SQLCODE) SQLCODE SQLSTATE Descr ...
- jQuery 验证 Validation
jQuery Validation 目录 简介: Form validation made easy. Validate a simple comment form with inline rules ...
- Day06:迭代器,生成器,生成表达式,面向过程编程,包及常用模块
今日内容:1.迭代器(****)2.生成器(***)3.生成器表达式(*****)4.面向过程编程(*****)5.包的使用(***)6.常用模块 logging (*****) re ( ...
- java 获取 HttpServletRequest 值 demo
private void getHttpServletRequestInfo(HttpServletRequest request){ try { StringBuilder stringBuilde ...
- css使图片变成黑白效果
-webkit-filter: grayscale(%); -moz-filter: grayscale(%); -ms-filter: grayscale(%); -o-filter: graysc ...
- Apache2.2安装图解
Apache2.2安装图解 2010-12-14 15:32:44| 分类: 不学无术之杂 | 标签:安装 端口 httpd apache2.2 服务器 |字号 订阅 Apache音译 ...
- 微软 Remote App
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wangchunhai.blog.51cto.com/225186/201073 ...
- cshtml 获取session值
在 cshtml 中,我们如何获取 session 的呢? 首先我们先设置 session 值,我们一般都会在 Controller 设置 session. Session["isAdmin ...
- 洛谷P1044 栈(Catalan数)
P1044 栈 题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要 ...
- openinstall的免费服务对App推广有哪些帮助?
想在微信中下载 App,需要“点击右上角打开浏览器”,太麻烦: 想深入查看微信分享内容,需要手动打开 App 搜索,不方便: 想给 App 做推广,Android 需要多个渠道人工打包,效率低: .. ...