{"action":"created","comment":{"url":"https://api.github.com/repos/mlb7687/amphtml/pulls/comments/51735001","id":51735001,"diff_hunk":"@@ -263,6 +263,64 @@ export function installAd(win) {\n         this.element.removeChild(this.iframe_);\n       });\n     }\n+\n+    /**\n+     * Takes an AMP ad and immediately renders.\n+     * @param {string} ampHtmlAd AMP HTML that will be immediately rendered if\n+     *   it is validated.\n+     * @private\n+     */\n+    validateAndRenderOrFallback_(ampHtmlAd) {\n+      // First find the body of the valid AMP document. Wrap this in an\n+      // identifiable div and append it as a child to our amp-ad tag.\n+      var ampBodyStart = ampHtmlAd.indexOf(\"<body>\");\n+      if(ampBodyStart > 0) {\n+        var ampBodyEnd = ampHtmlAd.lastIndexOf(\"</body>\");\n+        var div = createDivContainer(this.element.ownerDocument.defaultView,\n+            this.element);\n+        var uniqueId = \" #\" + div.id + \" \";\n+        div.innerHTML = ampHtmlAd.substring(\n+          ampBodyStart + \"<body>\".length, ampBodyEnd);;\n+        this.element.appendChild(div);\n+\n+\n+        // Next append any styles to our amp-custom style tag. Use the unique\n+        // div id to nest these styles appropriately.\n+        var ampStyleStart = ampHtmlAd.indexOf(\"<style amp-custom>\");\n+        if(ampStyleStart > 0) {\n+          var ampStyleEnd = ampHtmlAd.indexOf(\"</style>\", ampStyleStart);\n+          var ampStyle = ampHtmlAd.substring(ampStyleStart +\n+            \"<style amp-custom>\".length, ampStyleEnd);\n+\n+          // Split the string on ending braces, remove the empty item at the end,\n+          // and create new set of styles nesting the existing styles as\n+          // descendants of the unique id of the div.\n+          var splitArray = ampStyle.split('}');\n+          splitArray.pop();\n+          ampStyle = uniqueId + splitArray.join('} ' + uniqueId) + '}');\n+\n+          // Lastly find the amp-custom tag and append to that.\n+          var styleTags = document.getElementsByTagName(\"style\");\n+          var customStyleTag = null;\n+          for (var i = 0; i < styleTags.length; i++)\n+          {\n+            if(styleTags[i].attributes.getNamedItem(\"amp-custom\") != null)\n+            {\n+              customStyleTag = styleTags[i];\n+              break;\n+            }\n+          }\n+          // If no amp-custom tag exists, create one.\n+          if (customStyleTag === null) {\n+            var head = document.head || document.getElementsByTagName('head')[0];\n+            customStyleTag = document.createElement('style');\n+            customStyleTag.setAttribute('amp-custom','');\n+            head.appendChild(customStyleTag);\n+          }\n+          customStyleTag.innerHTML = customStyleTag.innerHTML.concat(ampStyle);","path":"builtins/amp-ad.js","position":67,"original_position":67,"commit_id":"d61c6a438cc1566e1c64df6382ceea650bd61887","original_commit_id":"d61c6a438cc1566e1c64df6382ceea650bd61887","user":{"login":"keithwrightbos","id":1766447,"avatar_url":"https://avatars.githubusercontent.com/u/1766447?v=3","gravatar_id":"","url":"https://api.github.com/users/keithwrightbos","html_url":"https://github.com/keithwrightbos","followers_url":"https://api.github.com/users/keithwrightbos/followers","following_url":"https://api.github.com/users/keithwrightbos/following{/other_user}","gists_url":"https://api.github.com/users/keithwrightbos/gists{/gist_id}","starred_url":"https://api.github.com/users/keithwrightbos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithwrightbos/subscriptions","organizations_url":"https://api.github.com/users/keithwrightbos/orgs","repos_url":"https://api.github.com/users/keithwrightbos/repos","events_url":"https://api.github.com/users/keithwrightbos/events{/privacy}","received_events_url":"https://api.github.com/users/keithwrightbos/received_events","type":"User","site_admin":false},"body":"customStyleTag.innerHTML += ampStyle;","created_at":"2016-02-03T15:24:54Z","updated_at":"2016-02-03T15:24:54Z","html_url":"https://github.com/mlb7687/amphtml/pull/1#discussion_r51735001","pull_request_url":"https://api.github.com/repos/mlb7687/amphtml/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/comments/51735001"},"html":{"href":"https://github.com/mlb7687/amphtml/pull/1#discussion_r51735001"},"pull_request":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/mlb7687/amphtml/pulls/1","id":57875818,"html_url":"https://github.com/mlb7687/amphtml/pull/1","diff_url":"https://github.com/mlb7687/amphtml/pull/1.diff","patch_url":"https://github.com/mlb7687/amphtml/pull/1.patch","issue_url":"https://api.github.com/repos/mlb7687/amphtml/issues/1","number":1,"state":"open","locked":false,"title":"A4a render amp ad","user":{"login":"mlb7687","id":11046373,"avatar_url":"https://avatars.githubusercontent.com/u/11046373?v=3","gravatar_id":"","url":"https://api.github.com/users/mlb7687","html_url":"https://github.com/mlb7687","followers_url":"https://api.github.com/users/mlb7687/followers","following_url":"https://api.github.com/users/mlb7687/following{/other_user}","gists_url":"https://api.github.com/users/mlb7687/gists{/gist_id}","starred_url":"https://api.github.com/users/mlb7687/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlb7687/subscriptions","organizations_url":"https://api.github.com/users/mlb7687/orgs","repos_url":"https://api.github.com/users/mlb7687/repos","events_url":"https://api.github.com/users/mlb7687/events{/privacy}","received_events_url":"https://api.github.com/users/mlb7687/received_events","type":"User","site_admin":false},"body":"Discussed f2f, some things left to do.\r\n1) Use \\<ins\\> instead of \\<div\\> to prevent inheriting CSS\r\n2) I plan to update some of the naming. Ex: validateAndRenderOrFallback I will likely change to have this just be the rendering function called from inside the validation callback.","created_at":"2016-02-01T17:58:43Z","updated_at":"2016-02-03T15:24:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e34c168465af7cd0c59320c6060b12285d30086e","assignee":{"login":"keithwrightbos","id":1766447,"avatar_url":"https://avatars.githubusercontent.com/u/1766447?v=3","gravatar_id":"","url":"https://api.github.com/users/keithwrightbos","html_url":"https://github.com/keithwrightbos","followers_url":"https://api.github.com/users/keithwrightbos/followers","following_url":"https://api.github.com/users/keithwrightbos/following{/other_user}","gists_url":"https://api.github.com/users/keithwrightbos/gists{/gist_id}","starred_url":"https://api.github.com/users/keithwrightbos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithwrightbos/subscriptions","organizations_url":"https://api.github.com/users/keithwrightbos/orgs","repos_url":"https://api.github.com/users/keithwrightbos/repos","events_url":"https://api.github.com/users/keithwrightbos/events{/privacy}","received_events_url":"https://api.github.com/users/keithwrightbos/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mlb7687/amphtml/pulls/1/commits","review_comments_url":"https://api.github.com/repos/mlb7687/amphtml/pulls/1/comments","review_comment_url":"https://api.github.com/repos/mlb7687/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mlb7687/amphtml/issues/1/comments","statuses_url":"https://api.github.com/repos/mlb7687/amphtml/statuses/d61c6a438cc1566e1c64df6382ceea650bd61887","head":{"label":"mlb7687:a4a-render-amp-ad","ref":"a4a-render-amp-ad","sha":"d61c6a438cc1566e1c64df6382ceea650bd61887","user":{"login":"mlb7687","id":11046373,"avatar_url":"https://avatars.githubusercontent.com/u/11046373?v=3","gravatar_id":"","url":"https://api.github.com/users/mlb7687","html_url":"https://github.com/mlb7687","followers_url":"https://api.github.com/users/mlb7687/followers","following_url":"https://api.github.com/users/mlb7687/following{/other_user}","gists_url":"https://api.github.com/users/mlb7687/gists{/gist_id}","starred_url":"https://api.github.com/users/mlb7687/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlb7687/subscriptions","organizations_url":"https://api.github.com/users/mlb7687/orgs","repos_url":"https://api.github.com/users/mlb7687/repos","events_url":"https://api.github.com/users/mlb7687/events{/privacy}","received_events_url":"https://api.github.com/users/mlb7687/received_events","type":"User","site_admin":false},"repo":{"id":49509700,"name":"amphtml","full_name":"mlb7687/amphtml","owner":{"login":"mlb7687","id":11046373,"avatar_url":"https://avatars.githubusercontent.com/u/11046373?v=3","gravatar_id":"","url":"https://api.github.com/users/mlb7687","html_url":"https://github.com/mlb7687","followers_url":"https://api.github.com/users/mlb7687/followers","following_url":"https://api.github.com/users/mlb7687/following{/other_user}","gists_url":"https://api.github.com/users/mlb7687/gists{/gist_id}","starred_url":"https://api.github.com/users/mlb7687/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlb7687/subscriptions","organizations_url":"https://api.github.com/users/mlb7687/orgs","repos_url":"https://api.github.com/users/mlb7687/repos","events_url":"https://api.github.com/users/mlb7687/events{/privacy}","received_events_url":"https://api.github.com/users/mlb7687/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mlb7687/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/mlb7687/amphtml","forks_url":"https://api.github.com/repos/mlb7687/amphtml/forks","keys_url":"https://api.github.com/repos/mlb7687/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mlb7687/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mlb7687/amphtml/teams","hooks_url":"https://api.github.com/repos/mlb7687/amphtml/hooks","issue_events_url":"https://api.github.com/repos/mlb7687/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/mlb7687/amphtml/events","assignees_url":"https://api.github.com/repos/mlb7687/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/mlb7687/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/mlb7687/amphtml/tags","blobs_url":"https://api.github.com/repos/mlb7687/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mlb7687/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mlb7687/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mlb7687/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mlb7687/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/mlb7687/amphtml/languages","stargazers_url":"https://api.github.com/repos/mlb7687/amphtml/stargazers","contributors_url":"https://api.github.com/repos/mlb7687/amphtml/contributors","subscribers_url":"https://api.github.com/repos/mlb7687/amphtml/subscribers","subscription_url":"https://api.github.com/repos/mlb7687/amphtml/subscription","commits_url":"https://api.github.com/repos/mlb7687/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mlb7687/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mlb7687/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mlb7687/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mlb7687/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/mlb7687/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mlb7687/amphtml/merges","archive_url":"https://api.github.com/repos/mlb7687/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mlb7687/amphtml/downloads","issues_url":"https://api.github.com/repos/mlb7687/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/mlb7687/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/mlb7687/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/mlb7687/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mlb7687/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/mlb7687/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/mlb7687/amphtml/deployments","created_at":"2016-01-12T15:37:45Z","updated_at":"2016-01-12T15:37:47Z","pushed_at":"2016-02-01T17:58:43Z","git_url":"git://github.com/mlb7687/amphtml.git","ssh_url":"git@github.com:mlb7687/amphtml.git","clone_url":"https://github.com/mlb7687/amphtml.git","svn_url":"https://github.com/mlb7687/amphtml","homepage":"https://ampproject.org","size":20505,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mlb7687:master","ref":"master","sha":"af6015e366e8ec0e3f32889a4124c003689abd4d","user":{"login":"mlb7687","id":11046373,"avatar_url":"https://avatars.githubusercontent.com/u/11046373?v=3","gravatar_id":"","url":"https://api.github.com/users/mlb7687","html_url":"https://github.com/mlb7687","followers_url":"https://api.github.com/users/mlb7687/followers","following_url":"https://api.github.com/users/mlb7687/following{/other_user}","gists_url":"https://api.github.com/users/mlb7687/gists{/gist_id}","starred_url":"https://api.github.com/users/mlb7687/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlb7687/subscriptions","organizations_url":"https://api.github.com/users/mlb7687/orgs","repos_url":"https://api.github.com/users/mlb7687/repos","events_url":"https://api.github.com/users/mlb7687/events{/privacy}","received_events_url":"https://api.github.com/users/mlb7687/received_events","type":"User","site_admin":false},"repo":{"id":49509700,"name":"amphtml","full_name":"mlb7687/amphtml","owner":{"login":"mlb7687","id":11046373,"avatar_url":"https://avatars.githubusercontent.com/u/11046373?v=3","gravatar_id":"","url":"https://api.github.com/users/mlb7687","html_url":"https://github.com/mlb7687","followers_url":"https://api.github.com/users/mlb7687/followers","following_url":"https://api.github.com/users/mlb7687/following{/other_user}","gists_url":"https://api.github.com/users/mlb7687/gists{/gist_id}","starred_url":"https://api.github.com/users/mlb7687/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlb7687/subscriptions","organizations_url":"https://api.github.com/users/mlb7687/orgs","repos_url":"https://api.github.com/users/mlb7687/repos","events_url":"https://api.github.com/users/mlb7687/events{/privacy}","received_events_url":"https://api.github.com/users/mlb7687/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mlb7687/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/mlb7687/amphtml","forks_url":"https://api.github.com/repos/mlb7687/amphtml/forks","keys_url":"https://api.github.com/repos/mlb7687/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mlb7687/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mlb7687/amphtml/teams","hooks_url":"https://api.github.com/repos/mlb7687/amphtml/hooks","issue_events_url":"https://api.github.com/repos/mlb7687/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/mlb7687/amphtml/events","assignees_url":"https://api.github.com/repos/mlb7687/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/mlb7687/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/mlb7687/amphtml/tags","blobs_url":"https://api.github.com/repos/mlb7687/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mlb7687/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mlb7687/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mlb7687/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mlb7687/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/mlb7687/amphtml/languages","stargazers_url":"https://api.github.com/repos/mlb7687/amphtml/stargazers","contributors_url":"https://api.github.com/repos/mlb7687/amphtml/contributors","subscribers_url":"https://api.github.com/repos/mlb7687/amphtml/subscribers","subscription_url":"https://api.github.com/repos/mlb7687/amphtml/subscription","commits_url":"https://api.github.com/repos/mlb7687/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mlb7687/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mlb7687/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mlb7687/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mlb7687/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/mlb7687/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mlb7687/amphtml/merges","archive_url":"https://api.github.com/repos/mlb7687/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mlb7687/amphtml/downloads","issues_url":"https://api.github.com/repos/mlb7687/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/mlb7687/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/mlb7687/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/mlb7687/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mlb7687/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/mlb7687/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/mlb7687/amphtml/deployments","created_at":"2016-01-12T15:37:45Z","updated_at":"2016-01-12T15:37:47Z","pushed_at":"2016-02-01T17:58:43Z","git_url":"git://github.com/mlb7687/amphtml.git","ssh_url":"git@github.com:mlb7687/amphtml.git","clone_url":"https://github.com/mlb7687/amphtml.git","svn_url":"https://github.com/mlb7687/amphtml","homepage":"https://ampproject.org","size":20505,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/1"},"html":{"href":"https://github.com/mlb7687/amphtml/pull/1"},"issue":{"href":"https://api.github.com/repos/mlb7687/amphtml/issues/1"},"comments":{"href":"https://api.github.com/repos/mlb7687/amphtml/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mlb7687/amphtml/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/mlb7687/amphtml/statuses/d61c6a438cc1566e1c64df6382ceea650bd61887"}}}}