From 31a0a6591b9fca0c3d0cbd3722adf9189ab2a517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Fri, 7 Aug 2015 10:28:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 326aa8c..6e79dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +## 0.3.8 + +* 修复 CSS `@charset` 可能导致无法解析的 BUG + ## 0.3.7 * 完善伪类选择器支持 From 73994410b9c9e7cd08b51bbc366e56cee89e18f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Fri, 7 Aug 2015 10:28:18 +0800 Subject: [PATCH 2/4] v0.3.8 --- package.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/package.json b/package.json index 993a329..d872776 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "font-spider", "description": "Webfont optimizer", - "version": "0.3.7", + "version": "0.3.8", "homepage": "https://github.com/aui/font-spider", "author": { "name": "aui", @@ -14,12 +14,6 @@ "bugs": { "url": "https://github.com/aui/font-spider/issues" }, - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/aui/font-spider/blob/master/LICENSE-MIT" - } - ], "bin": { "fs": "bin/font-spider", "font-spider": "bin/font-spider" From 87868abec606ac9788ae3187a2f4455ecbc863b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Fri, 7 Aug 2015 10:28:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5fd10b2..2a2a6d4 100644 --- a/README.md +++ b/README.md @@ -56,19 +56,19 @@ font-spider [options] #### 示例 -1. 使用通配符压缩多个 HTML 文件关联的 WebFont: +1\. 使用通配符压缩多个 HTML 文件关联的 WebFont: ``` shell font-spider dest/*.html ``` -2. 使用 `--map ` 参数将线上的页面的 WebFont 映射到本地来进行压缩: +2\. 使用 `--map ` 参数将线上的页面的 WebFont 映射到本地来进行压缩: ``` shell font-spider --map http://font-spider.org/font,./font http://font-spider.org/index.html ``` -3. 使用 `--ignore ` 忽略文件: +3\. 使用 `--ignore ` 忽略文件: ``` shell font-spider --ignore *-icon.css,*.eot dest/*.html From 645bcdaac41789e7c16c3ac680a63255028c9437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Fri, 7 Aug 2015 10:29:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D@charset=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spider/css-parser.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/spider/css-parser.js b/src/spider/css-parser.js index 024ab7c..16eaf39 100644 --- a/src/spider/css-parser.js +++ b/src/spider/css-parser.js @@ -47,9 +47,7 @@ function CssParser (resource /*,importLength*/) { } - // CSSOM BUG? - content = content.replace(/@charset\b.+;/g, ''); - + content = getContent(content); try { ast = CSSOM.parse(content); @@ -342,6 +340,8 @@ CssParser.Parser.prototype = { id: [], family: [], files: [], + // TODO [data-name="ss,ss"] + // /((?:[^,"']|"[^"]*"|'[^']*')+)/ selectors: utils.commaToArray(selectorText), chars: content.split(''), options: {} @@ -457,7 +457,13 @@ getFontId.alias = { - +function getContent (content) { + // 去掉 @charset,因为它可能触发 cssom 库的 bug + // 使用空格占位避免改动代码位置 + return content.replace(/^(\@charset\b.+?;)(.*?)/i, function ($0, $1, $2) { + return Array($1.length).join(' ') + $2 + }); +}