简单的解析font标签
来源:互联网 发布:linux系统中文版 编辑:程序博客网 时间:2024/06/06 01:52
利用font标签来给某些字符设定字号、颜色、和是否加粗。
var log = console.log;var str = "abc<font color='#ffee00'>123</font>oooo<b>oo</b>ooooo<font color='#ff2300' size='26'>ppppppp<b>我擦</b>ppp<b>嗷嗷嗷</b>p</font>点点点";function Data(str, color, size, isBold) {this.str = str;this.color = color || "#ffffff";this.size = size || 30;this.isBold = isBold || false;}// 解析font标签中的属性:size、colorfunction parseFont(html) {var size = undefined;var color = undefined;if(html[0] == '<' && html[1] == 'f') {for(var i = 0; i < html.length; i++) {if(html[i] == 's') {// 目前需求只需要解析size和color所以只有判断字符是不是s就知道是不是检测到有size这个属性var j = i;while(html[j] != "'") {j++;}var start = j + 1;j = start;while(html[j] != "'") {j++;}var end = j;var num = html.substring(start, end);var size = parseInt(num);}if(html[i] == 'c') {var j = i;while(html[j] != "'") {j++;}var start = j + 1;j = start;while(html[j] != "'") {j++;}var end = j;var hex = html.substring(start, end);var color = hex;}if(html[i] == '>') {break;}}} return {"color":color, "size":size};}function parse(html) {var chList = [];var dataList = [];var size = undefined;var color = undefined;var bold = undefined;log(html)for(var i = 0; i < html.length; i++) {if(html[i] == '<') {if(chList.length > 0) {var str = chList.join("");var data = new Data(str, color, size, bold);dataList.push(data);chList = [];}if(html[i + 1] == '/') {if(html[i + 2] == 'f') {size = undefined;color = undefined;} else if(html[i + 2] == 'b') {bold = undefined;}var j = i;while(html[j] != '>') {j++;}i = j;} else if(html[i + 1] == 'f') {var d = parseFont(html.substring(i, html.length));size = d["size"];color = d["color"];} else if(html[i + 1] == 'b') {bold = true;}var j = i;while(html[j] != '>') {j++;}i = j;} else {chList.push(html[i]);}}if(chList.length > 0) {var str = chList.join("");var data = new Data(str, color, size, bold);dataList.push(data);chList = [];}return dataList;}log(parse(str));
0 0
- 简单的解析font标签
- font-size和font标签的size属性的区别
- Font标签
- font标签
- HTML的font标签的使用
- HTML <font> 标签的 color 属性
- Font Awesome Icon 只有I标签的
- 带文本的标签自动生成font标签
- 解析页面font相关的css
- HTML <font> 标签
- font标签及其属性
- HTML的font标签使用的注意的事项
- HTML的style属性(替代font等标签)
- cegui font 文件解析
- UCGUI FONT解析
- directfb font解析
- UCGUI FONT解析
- directfb font解析
- web项目关于 jquery easyui 与后台数据交互
- 关于访问相对路径问题
- linux批量ping域名的脚本
- Linux杂谈:解决配置静态ip后eth0网卡启动不了的问题
- 怎么查看ubuntu是多少位和常用信息
- 简单的解析font标签
- Photoshop学习(三)色彩与图像偏色处理
- SpriteKit:开启物理逐像素(Per-Pixel)碰撞检测后发现的问题及解决
- SELECT语句
- 判断两个字符串是否互为旋转词
- oracle 中游标和存储过程的使用
- IOS 动画设计(5)——用缓动函数实现物理动画效果
- 强迫症患者最爱的代码整理功能
- mysql索引总结