{"action":"created","comment":{"url":"https://api.github.com/repos/svg/svgo/pulls/comments/83221324","pull_request_review_id":4077669,"id":83221324,"diff_hunk":"@@ -0,0 +1,124 @@\n+'use strict';\n+\n+exports.type   = 'full';\n+\n+exports.active = true;\n+\n+exports.params = {\n+  onlyMatchedOnce: true\n+};\n+\n+exports.description = 'inline styles (optionally skip selectors that match more than once)';\n+\n+\n+var cheerioSupport = require('../lib/svgo/cheerio-support'),\n+    SPECIFICITY    = require('specificity'),\n+    stable         = require('stable'),\n+    csso           = require('csso');\n+\n+\n+/**\n+  * Moves styles from <style> to element styles\n+  *\n+  * @author strarsis <strarsis@gmail.com>\n+  */\n+exports.fn = function(data, opts) {\n+\n+  // svgo ast to cheerio ast\n+  var $ = cheerioSupport.svgoAst2CheerioAst(data);\n+\n+  var $styles       = $('style');\n+  var styleItems    = [];\n+  var selectorItems = [];\n+  $styles.each(function(si, $style) {\n+    if($style.children.length == 0) {\n+      return;\n+    }\n+\n+    var cssStr = $style.children[0].data;\n+    if(cssStr.length == 0) {\n+      return;\n+    }\n+\n+    var cssAst = csso.parse(cssStr, {\n+                   context: 'stylesheet'\n+                 });\n+    styleItems.push({\n+      $style: $style,\n+      cssAst: cssAst\n+    });\n+\n+    csso.walk(cssAst, function(node, item) {\n+      // single selector\n+      if(node.type === 'SimpleSelector') {\n+        var selectorStr  = csso.translate(node);\n+        var selectorItem = {\n+          selectorStr:        selectorStr,\n+          simpleSelectorItem: item,\n+          rulesetNode:        this.ruleset\n+        };\n+        selectorItems.push(selectorItem);\n+      }\n+    });\n+  });\n+\n+  // stable sort selectors by specificity\n+  var selectorItemsSorted = stable(selectorItems, function(item1, item2) {\n+    return SPECIFICITY.compare(item1.selectorStr, item2.selectorStr);\n+  });\n+\n+  for(var selectorItem of selectorItemsSorted) {","path":"plugins/inlineStyles.js","position":70,"original_position":70,"commit_id":"ebcd712bb982801fe9d841241ae90bea6e120e1b","original_commit_id":"ebcd712bb982801fe9d841241ae90bea6e120e1b","user":{"login":"GreLI","id":1467392,"avatar_url":"https://avatars.githubusercontent.com/u/1467392?v=3","gravatar_id":"","url":"https://api.github.com/users/GreLI","html_url":"https://github.com/GreLI","followers_url":"https://api.github.com/users/GreLI/followers","following_url":"https://api.github.com/users/GreLI/following{/other_user}","gists_url":"https://api.github.com/users/GreLI/gists{/gist_id}","starred_url":"https://api.github.com/users/GreLI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GreLI/subscriptions","organizations_url":"https://api.github.com/users/GreLI/orgs","repos_url":"https://api.github.com/users/GreLI/repos","events_url":"https://api.github.com/users/GreLI/events{/privacy}","received_events_url":"https://api.github.com/users/GreLI/received_events","type":"User","site_admin":false},"body":"Unfortunatetly, `for-of` loops aren't supported in Node 0.10 which is still supported. However, probably not for a long time.","created_at":"2016-10-13T13:56:05Z","updated_at":"2016-10-13T13:56:05Z","html_url":"https://github.com/svg/svgo/pull/592#discussion_r83221324","pull_request_url":"https://api.github.com/repos/svg/svgo/pulls/592","_links":{"self":{"href":"https://api.github.com/repos/svg/svgo/pulls/comments/83221324"},"html":{"href":"https://github.com/svg/svgo/pull/592#discussion_r83221324"},"pull_request":{"href":"https://api.github.com/repos/svg/svgo/pulls/592"}}},"pull_request":{"url":"https://api.github.com/repos/svg/svgo/pulls/592","id":84124106,"html_url":"https://github.com/svg/svgo/pull/592","diff_url":"https://github.com/svg/svgo/pull/592.diff","patch_url":"https://github.com/svg/svgo/pull/592.patch","issue_url":"https://api.github.com/repos/svg/svgo/issues/592","number":592,"state":"open","locked":false,"title":"Add inlineStyles plugin (rewrite of localStyles plugin)","user":{"login":"strarsis","id":9271436,"avatar_url":"https://avatars.githubusercontent.com/u/9271436?v=3","gravatar_id":"","url":"https://api.github.com/users/strarsis","html_url":"https://github.com/strarsis","followers_url":"https://api.github.com/users/strarsis/followers","following_url":"https://api.github.com/users/strarsis/following{/other_user}","gists_url":"https://api.github.com/users/strarsis/gists{/gist_id}","starred_url":"https://api.github.com/users/strarsis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strarsis/subscriptions","organizations_url":"https://api.github.com/users/strarsis/orgs","repos_url":"https://api.github.com/users/strarsis/repos","events_url":"https://api.github.com/users/strarsis/events{/privacy}","received_events_url":"https://api.github.com/users/strarsis/received_events","type":"User","site_admin":false},"body":"This pull request adds the inlineStyles plugin, a rewrite of the localStyles plugin.\r\nIt uses [cheerio](https://github.com/cheeriojs/cheerio) with [juice](https://github.com/Automattic/juice) on top of it for inlining styles which \r\nhandles complicated cascading, selector specificity, etc.\r\nFor making this possible, the svgo AST is converted to cheerio AST and back again.","created_at":"2016-09-06T13:40:36Z","updated_at":"2016-10-13T13:56:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2327c399e0a5d715f778a0d90e612bdc8d7cae4c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/svg/svgo/pulls/592/commits","review_comments_url":"https://api.github.com/repos/svg/svgo/pulls/592/comments","review_comment_url":"https://api.github.com/repos/svg/svgo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/svg/svgo/issues/592/comments","statuses_url":"https://api.github.com/repos/svg/svgo/statuses/ebcd712bb982801fe9d841241ae90bea6e120e1b","head":{"label":"strarsis:inlineStyles","ref":"inlineStyles","sha":"ebcd712bb982801fe9d841241ae90bea6e120e1b","user":{"login":"strarsis","id":9271436,"avatar_url":"https://avatars.githubusercontent.com/u/9271436?v=3","gravatar_id":"","url":"https://api.github.com/users/strarsis","html_url":"https://github.com/strarsis","followers_url":"https://api.github.com/users/strarsis/followers","following_url":"https://api.github.com/users/strarsis/following{/other_user}","gists_url":"https://api.github.com/users/strarsis/gists{/gist_id}","starred_url":"https://api.github.com/users/strarsis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strarsis/subscriptions","organizations_url":"https://api.github.com/users/strarsis/orgs","repos_url":"https://api.github.com/users/strarsis/repos","events_url":"https://api.github.com/users/strarsis/events{/privacy}","received_events_url":"https://api.github.com/users/strarsis/received_events","type":"User","site_admin":false},"repo":{"id":46149938,"name":"svgo","full_name":"strarsis/svgo","owner":{"login":"strarsis","id":9271436,"avatar_url":"https://avatars.githubusercontent.com/u/9271436?v=3","gravatar_id":"","url":"https://api.github.com/users/strarsis","html_url":"https://github.com/strarsis","followers_url":"https://api.github.com/users/strarsis/followers","following_url":"https://api.github.com/users/strarsis/following{/other_user}","gists_url":"https://api.github.com/users/strarsis/gists{/gist_id}","starred_url":"https://api.github.com/users/strarsis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strarsis/subscriptions","organizations_url":"https://api.github.com/users/strarsis/orgs","repos_url":"https://api.github.com/users/strarsis/repos","events_url":"https://api.github.com/users/strarsis/events{/privacy}","received_events_url":"https://api.github.com/users/strarsis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/strarsis/svgo","description":"Nodejs-based tool for optimizing SVG vector graphics files.","fork":true,"url":"https://api.github.com/repos/strarsis/svgo","forks_url":"https://api.github.com/repos/strarsis/svgo/forks","keys_url":"https://api.github.com/repos/strarsis/svgo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strarsis/svgo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strarsis/svgo/teams","hooks_url":"https://api.github.com/repos/strarsis/svgo/hooks","issue_events_url":"https://api.github.com/repos/strarsis/svgo/issues/events{/number}","events_url":"https://api.github.com/repos/strarsis/svgo/events","assignees_url":"https://api.github.com/repos/strarsis/svgo/assignees{/user}","branches_url":"https://api.github.com/repos/strarsis/svgo/branches{/branch}","tags_url":"https://api.github.com/repos/strarsis/svgo/tags","blobs_url":"https://api.github.com/repos/strarsis/svgo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strarsis/svgo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strarsis/svgo/git/refs{/sha}","trees_url":"https://api.github.com/repos/strarsis/svgo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strarsis/svgo/statuses/{sha}","languages_url":"https://api.github.com/repos/strarsis/svgo/languages","stargazers_url":"https://api.github.com/repos/strarsis/svgo/stargazers","contributors_url":"https://api.github.com/repos/strarsis/svgo/contributors","subscribers_url":"https://api.github.com/repos/strarsis/svgo/subscribers","subscription_url":"https://api.github.com/repos/strarsis/svgo/subscription","commits_url":"https://api.github.com/repos/strarsis/svgo/commits{/sha}","git_commits_url":"https://api.github.com/repos/strarsis/svgo/git/commits{/sha}","comments_url":"https://api.github.com/repos/strarsis/svgo/comments{/number}","issue_comment_url":"https://api.github.com/repos/strarsis/svgo/issues/comments{/number}","contents_url":"https://api.github.com/repos/strarsis/svgo/contents/{+path}","compare_url":"https://api.github.com/repos/strarsis/svgo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strarsis/svgo/merges","archive_url":"https://api.github.com/repos/strarsis/svgo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strarsis/svgo/downloads","issues_url":"https://api.github.com/repos/strarsis/svgo/issues{/number}","pulls_url":"https://api.github.com/repos/strarsis/svgo/pulls{/number}","milestones_url":"https://api.github.com/repos/strarsis/svgo/milestones{/number}","notifications_url":"https://api.github.com/repos/strarsis/svgo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strarsis/svgo/labels{/name}","releases_url":"https://api.github.com/repos/strarsis/svgo/releases{/id}","deployments_url":"https://api.github.com/repos/strarsis/svgo/deployments","created_at":"2015-11-13T22:07:27Z","updated_at":"2016-09-05T15:43:21Z","pushed_at":"2016-10-13T13:36:28Z","git_url":"git://github.com/strarsis/svgo.git","ssh_url":"git@github.com:strarsis/svgo.git","clone_url":"https://github.com/strarsis/svgo.git","svn_url":"https://github.com/strarsis/svgo","homepage":"","size":1246,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"svg:master","ref":"master","sha":"4822a44f37bbbe803b710511f3b038cf9e21970d","user":{"login":"svg","id":2473585,"avatar_url":"https://avatars.githubusercontent.com/u/2473585?v=3","gravatar_id":"","url":"https://api.github.com/users/svg","html_url":"https://github.com/svg","followers_url":"https://api.github.com/users/svg/followers","following_url":"https://api.github.com/users/svg/following{/other_user}","gists_url":"https://api.github.com/users/svg/gists{/gist_id}","starred_url":"https://api.github.com/users/svg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svg/subscriptions","organizations_url":"https://api.github.com/users/svg/orgs","repos_url":"https://api.github.com/users/svg/repos","events_url":"https://api.github.com/users/svg/events{/privacy}","received_events_url":"https://api.github.com/users/svg/received_events","type":"Organization","site_admin":false},"repo":{"id":5508088,"name":"svgo","full_name":"svg/svgo","owner":{"login":"svg","id":2473585,"avatar_url":"https://avatars.githubusercontent.com/u/2473585?v=3","gravatar_id":"","url":"https://api.github.com/users/svg","html_url":"https://github.com/svg","followers_url":"https://api.github.com/users/svg/followers","following_url":"https://api.github.com/users/svg/following{/other_user}","gists_url":"https://api.github.com/users/svg/gists{/gist_id}","starred_url":"https://api.github.com/users/svg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svg/subscriptions","organizations_url":"https://api.github.com/users/svg/orgs","repos_url":"https://api.github.com/users/svg/repos","events_url":"https://api.github.com/users/svg/events{/privacy}","received_events_url":"https://api.github.com/users/svg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/svg/svgo","description":"Nodejs-based tool for optimizing SVG vector graphics files.","fork":false,"url":"https://api.github.com/repos/svg/svgo","forks_url":"https://api.github.com/repos/svg/svgo/forks","keys_url":"https://api.github.com/repos/svg/svgo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/svg/svgo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/svg/svgo/teams","hooks_url":"https://api.github.com/repos/svg/svgo/hooks","issue_events_url":"https://api.github.com/repos/svg/svgo/issues/events{/number}","events_url":"https://api.github.com/repos/svg/svgo/events","assignees_url":"https://api.github.com/repos/svg/svgo/assignees{/user}","branches_url":"https://api.github.com/repos/svg/svgo/branches{/branch}","tags_url":"https://api.github.com/repos/svg/svgo/tags","blobs_url":"https://api.github.com/repos/svg/svgo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/svg/svgo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/svg/svgo/git/refs{/sha}","trees_url":"https://api.github.com/repos/svg/svgo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/svg/svgo/statuses/{sha}","languages_url":"https://api.github.com/repos/svg/svgo/languages","stargazers_url":"https://api.github.com/repos/svg/svgo/stargazers","contributors_url":"https://api.github.com/repos/svg/svgo/contributors","subscribers_url":"https://api.github.com/repos/svg/svgo/subscribers","subscription_url":"https://api.github.com/repos/svg/svgo/subscription","commits_url":"https://api.github.com/repos/svg/svgo/commits{/sha}","git_commits_url":"https://api.github.com/repos/svg/svgo/git/commits{/sha}","comments_url":"https://api.github.com/repos/svg/svgo/comments{/number}","issue_comment_url":"https://api.github.com/repos/svg/svgo/issues/comments{/number}","contents_url":"https://api.github.com/repos/svg/svgo/contents/{+path}","compare_url":"https://api.github.com/repos/svg/svgo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/svg/svgo/merges","archive_url":"https://api.github.com/repos/svg/svgo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/svg/svgo/downloads","issues_url":"https://api.github.com/repos/svg/svgo/issues{/number}","pulls_url":"https://api.github.com/repos/svg/svgo/pulls{/number}","milestones_url":"https://api.github.com/repos/svg/svgo/milestones{/number}","notifications_url":"https://api.github.com/repos/svg/svgo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/svg/svgo/labels{/name}","releases_url":"https://api.github.com/repos/svg/svgo/releases{/id}","deployments_url":"https://api.github.com/repos/svg/svgo/deployments","created_at":"2012-08-22T10:41:43Z","updated_at":"2016-10-13T04:55:42Z","pushed_at":"2016-10-13T13:36:28Z","git_url":"git://github.com/svg/svgo.git","ssh_url":"git@github.com:svg/svgo.git","clone_url":"https://github.com/svg/svgo.git","svn_url":"https://github.com/svg/svgo","homepage":"","size":2437,"stargazers_count":5453,"watchers_count":5453,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":410,"mirror_url":null,"open_issues_count":106,"forks":410,"open_issues":106,"watchers":5453,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/svg/svgo/pulls/592"},"html":{"href":"https://github.com/svg/svgo/pull/592"},"issue":{"href":"https://api.github.com/repos/svg/svgo/issues/592"},"comments":{"href":"https://api.github.com/repos/svg/svgo/issues/592/comments"},"review_comments":{"href":"https://api.github.com/repos/svg/svgo/pulls/592/comments"},"review_comment":{"href":"https://api.github.com/repos/svg/svgo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/svg/svgo/pulls/592/commits"},"statuses":{"href":"https://api.github.com/repos/svg/svgo/statuses/ebcd712bb982801fe9d841241ae90bea6e120e1b"}}}}
{"actor":{"display_login":"GreLI"}}