{"action":"created","comment":{"url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/comments/37392277","id":37392277,"diff_hunk":"@@ -14,6 +20,85 @@ module.exports =\n       throw new Error \"Neither Blob nor Buffer are accessible in this environment. \" +\n         \"Consider adding Blob.js shim\"\n \n+  generateMHTDocument: (htmlSource) ->\n+    # take care of images\n+    @prepareImageParts(htmlSource).then (result) ->\n+      if result.htmlSource\n+        {htmlSource, imageContentParts} = result\n+      else\n+        htmlSource = htmlSource.outerHTML\n+        imageContentParts = result.imageContentParts\n+      # for proper MHT parsing all '=' signs in html tags need to be replaced with '=3D'\n+      htmlSource = htmlSource.replace /\\=/g, '=3D'\n+      W.resolve mhtDocumentTemplate {htmlSource, contentParts: imageContentParts.join '\\n'}\n+    , (err) -> throw err\n+\n+  prepareImageParts: (htmlSource) ->\n+    imageContentParts = []\n+    # regular expressions to work with DATA URI sourced (inlined) and regular images\n+    inlinedSrcPattern = /\"data:(\\w+\\/\\w+);(\\w+),(\\S+)\"/g\n+    regularSrcPattern = /(<img[^<>]+src=\")(?!file)(?!data\\:\\S+)(\\S+)(\")/g\n+    # replacer function for images sources via DATA URI\n+    inlinedReplacer = (match, contentType, contentEncoding, encodedContent) ->\n+      index = imageContentParts.length\n+      extension = contentType.split('/')[1]\n+      contentLocation = \"file://fake/image#{index}.#{extension}\"\n+      imageContentParts.push mhtPartTemplate {contentType, contentEncoding, contentLocation, encodedContent}\n+      \"\\\"#{contentLocation}\\\"\"\n+\n+    if typeof htmlSource is 'string'\n+      # don't have to do anything if there are no images in provided htmlSource\n+      return W.resolve({htmlSource, imageContentParts}) unless /<img/g.test htmlSource\n+      # take care of 'regular' images first\n+      matches = htmlSource.match regularSrcPattern\n+      if matches\n+        deferred = W.defer()\n+        # temporary canvas and image objects needed to convert image into base64 string\n+        canvas = document.createElement 'canvas'\n+        fakeImg = document.createElement 'img'\n+        fakeImg.style.visibility = 'hidden'\n+        document.body.appendChild fakeImg","path":"src/internal.coffee","position":55,"original_position":55,"commit_id":"e57320714618b0e4933a2d52a0ac3da033d48b39","original_commit_id":"e57320714618b0e4933a2d52a0ac3da033d48b39","user":{"login":"anowak","id":389726,"avatar_url":"https://avatars.githubusercontent.com/u/389726?v=3","gravatar_id":"","url":"https://api.github.com/users/anowak","html_url":"https://github.com/anowak","followers_url":"https://api.github.com/users/anowak/followers","following_url":"https://api.github.com/users/anowak/following{/other_user}","gists_url":"https://api.github.com/users/anowak/gists{/gist_id}","starred_url":"https://api.github.com/users/anowak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anowak/subscriptions","organizations_url":"https://api.github.com/users/anowak/orgs","repos_url":"https://api.github.com/users/anowak/repos","events_url":"https://api.github.com/users/anowak/events{/privacy}","received_events_url":"https://api.github.com/users/anowak/received_events","type":"User","site_admin":false},"body":"Observe that we modify the document of the 'calling' webpage herre","created_at":"2015-08-19T08:48:29Z","updated_at":"2015-08-19T08:48:29Z","html_url":"https://github.com/evidenceprime/html-docx-js/pull/13#discussion_r37392277","pull_request_url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13","_links":{"self":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/comments/37392277"},"html":{"href":"https://github.com/evidenceprime/html-docx-js/pull/13#discussion_r37392277"},"pull_request":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13","id":42347999,"html_url":"https://github.com/evidenceprime/html-docx-js/pull/13","diff_url":"https://github.com/evidenceprime/html-docx-js/pull/13.diff","patch_url":"https://github.com/evidenceprime/html-docx-js/pull/13.patch","issue_url":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/13","number":13,"state":"open","locked":false,"title":"Added images support","user":{"login":"N1kto","id":5045863,"avatar_url":"https://avatars.githubusercontent.com/u/5045863?v=3","gravatar_id":"","url":"https://api.github.com/users/N1kto","html_url":"https://github.com/N1kto","followers_url":"https://api.github.com/users/N1kto/followers","following_url":"https://api.github.com/users/N1kto/following{/other_user}","gists_url":"https://api.github.com/users/N1kto/gists{/gist_id}","starred_url":"https://api.github.com/users/N1kto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N1kto/subscriptions","organizations_url":"https://api.github.com/users/N1kto/orgs","repos_url":"https://api.github.com/users/N1kto/repos","events_url":"https://api.github.com/users/N1kto/events{/privacy}","received_events_url":"https://api.github.com/users/N1kto/received_events","type":"User","site_admin":false},"body":"Please review support of images in Word export files. This should work for both inlined and regular (sourced from static files) images. ","created_at":"2015-08-13T13:07:59Z","updated_at":"2015-08-19T08:48:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"194ed39e4fec4af4f9e32ce73597da0d54f88e6c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13/commits","review_comments_url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13/comments","review_comment_url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/13/comments","statuses_url":"https://api.github.com/repos/evidenceprime/html-docx-js/statuses/e57320714618b0e4933a2d52a0ac3da033d48b39","head":{"label":"N1kto:master","ref":"master","sha":"e57320714618b0e4933a2d52a0ac3da033d48b39","user":{"login":"N1kto","id":5045863,"avatar_url":"https://avatars.githubusercontent.com/u/5045863?v=3","gravatar_id":"","url":"https://api.github.com/users/N1kto","html_url":"https://github.com/N1kto","followers_url":"https://api.github.com/users/N1kto/followers","following_url":"https://api.github.com/users/N1kto/following{/other_user}","gists_url":"https://api.github.com/users/N1kto/gists{/gist_id}","starred_url":"https://api.github.com/users/N1kto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N1kto/subscriptions","organizations_url":"https://api.github.com/users/N1kto/orgs","repos_url":"https://api.github.com/users/N1kto/repos","events_url":"https://api.github.com/users/N1kto/events{/privacy}","received_events_url":"https://api.github.com/users/N1kto/received_events","type":"User","site_admin":false},"repo":{"id":39631289,"name":"html-docx-js","full_name":"N1kto/html-docx-js","owner":{"login":"N1kto","id":5045863,"avatar_url":"https://avatars.githubusercontent.com/u/5045863?v=3","gravatar_id":"","url":"https://api.github.com/users/N1kto","html_url":"https://github.com/N1kto","followers_url":"https://api.github.com/users/N1kto/followers","following_url":"https://api.github.com/users/N1kto/following{/other_user}","gists_url":"https://api.github.com/users/N1kto/gists{/gist_id}","starred_url":"https://api.github.com/users/N1kto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N1kto/subscriptions","organizations_url":"https://api.github.com/users/N1kto/orgs","repos_url":"https://api.github.com/users/N1kto/repos","events_url":"https://api.github.com/users/N1kto/events{/privacy}","received_events_url":"https://api.github.com/users/N1kto/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/N1kto/html-docx-js","description":"Converts HTML documents to DOCX in the browser","fork":true,"url":"https://api.github.com/repos/N1kto/html-docx-js","forks_url":"https://api.github.com/repos/N1kto/html-docx-js/forks","keys_url":"https://api.github.com/repos/N1kto/html-docx-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/N1kto/html-docx-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/N1kto/html-docx-js/teams","hooks_url":"https://api.github.com/repos/N1kto/html-docx-js/hooks","issue_events_url":"https://api.github.com/repos/N1kto/html-docx-js/issues/events{/number}","events_url":"https://api.github.com/repos/N1kto/html-docx-js/events","assignees_url":"https://api.github.com/repos/N1kto/html-docx-js/assignees{/user}","branches_url":"https://api.github.com/repos/N1kto/html-docx-js/branches{/branch}","tags_url":"https://api.github.com/repos/N1kto/html-docx-js/tags","blobs_url":"https://api.github.com/repos/N1kto/html-docx-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/N1kto/html-docx-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/N1kto/html-docx-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/N1kto/html-docx-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/N1kto/html-docx-js/statuses/{sha}","languages_url":"https://api.github.com/repos/N1kto/html-docx-js/languages","stargazers_url":"https://api.github.com/repos/N1kto/html-docx-js/stargazers","contributors_url":"https://api.github.com/repos/N1kto/html-docx-js/contributors","subscribers_url":"https://api.github.com/repos/N1kto/html-docx-js/subscribers","subscription_url":"https://api.github.com/repos/N1kto/html-docx-js/subscription","commits_url":"https://api.github.com/repos/N1kto/html-docx-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/N1kto/html-docx-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/N1kto/html-docx-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/N1kto/html-docx-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/N1kto/html-docx-js/contents/{+path}","compare_url":"https://api.github.com/repos/N1kto/html-docx-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/N1kto/html-docx-js/merges","archive_url":"https://api.github.com/repos/N1kto/html-docx-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/N1kto/html-docx-js/downloads","issues_url":"https://api.github.com/repos/N1kto/html-docx-js/issues{/number}","pulls_url":"https://api.github.com/repos/N1kto/html-docx-js/pulls{/number}","milestones_url":"https://api.github.com/repos/N1kto/html-docx-js/milestones{/number}","notifications_url":"https://api.github.com/repos/N1kto/html-docx-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/N1kto/html-docx-js/labels{/name}","releases_url":"https://api.github.com/repos/N1kto/html-docx-js/releases{/id}","created_at":"2015-07-24T12:16:28Z","updated_at":"2015-07-24T12:16:29Z","pushed_at":"2015-08-13T13:00:46Z","git_url":"git://github.com/N1kto/html-docx-js.git","ssh_url":"git@github.com:N1kto/html-docx-js.git","clone_url":"https://github.com/N1kto/html-docx-js.git","svn_url":"https://github.com/N1kto/html-docx-js","homepage":"http://evidenceprime.github.io/html-docx-js/","size":810,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"evidenceprime:master","ref":"master","sha":"c7cc522519c69f4e2989e9a9f09da17ae210cf7b","user":{"login":"evidenceprime","id":6417949,"avatar_url":"https://avatars.githubusercontent.com/u/6417949?v=3","gravatar_id":"","url":"https://api.github.com/users/evidenceprime","html_url":"https://github.com/evidenceprime","followers_url":"https://api.github.com/users/evidenceprime/followers","following_url":"https://api.github.com/users/evidenceprime/following{/other_user}","gists_url":"https://api.github.com/users/evidenceprime/gists{/gist_id}","starred_url":"https://api.github.com/users/evidenceprime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evidenceprime/subscriptions","organizations_url":"https://api.github.com/users/evidenceprime/orgs","repos_url":"https://api.github.com/users/evidenceprime/repos","events_url":"https://api.github.com/users/evidenceprime/events{/privacy}","received_events_url":"https://api.github.com/users/evidenceprime/received_events","type":"Organization","site_admin":false},"repo":{"id":22472379,"name":"html-docx-js","full_name":"evidenceprime/html-docx-js","owner":{"login":"evidenceprime","id":6417949,"avatar_url":"https://avatars.githubusercontent.com/u/6417949?v=3","gravatar_id":"","url":"https://api.github.com/users/evidenceprime","html_url":"https://github.com/evidenceprime","followers_url":"https://api.github.com/users/evidenceprime/followers","following_url":"https://api.github.com/users/evidenceprime/following{/other_user}","gists_url":"https://api.github.com/users/evidenceprime/gists{/gist_id}","starred_url":"https://api.github.com/users/evidenceprime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evidenceprime/subscriptions","organizations_url":"https://api.github.com/users/evidenceprime/orgs","repos_url":"https://api.github.com/users/evidenceprime/repos","events_url":"https://api.github.com/users/evidenceprime/events{/privacy}","received_events_url":"https://api.github.com/users/evidenceprime/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/evidenceprime/html-docx-js","description":"Converts HTML documents to DOCX in the browser","fork":false,"url":"https://api.github.com/repos/evidenceprime/html-docx-js","forks_url":"https://api.github.com/repos/evidenceprime/html-docx-js/forks","keys_url":"https://api.github.com/repos/evidenceprime/html-docx-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/evidenceprime/html-docx-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/evidenceprime/html-docx-js/teams","hooks_url":"https://api.github.com/repos/evidenceprime/html-docx-js/hooks","issue_events_url":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/events{/number}","events_url":"https://api.github.com/repos/evidenceprime/html-docx-js/events","assignees_url":"https://api.github.com/repos/evidenceprime/html-docx-js/assignees{/user}","branches_url":"https://api.github.com/repos/evidenceprime/html-docx-js/branches{/branch}","tags_url":"https://api.github.com/repos/evidenceprime/html-docx-js/tags","blobs_url":"https://api.github.com/repos/evidenceprime/html-docx-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/evidenceprime/html-docx-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/evidenceprime/html-docx-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/evidenceprime/html-docx-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/evidenceprime/html-docx-js/statuses/{sha}","languages_url":"https://api.github.com/repos/evidenceprime/html-docx-js/languages","stargazers_url":"https://api.github.com/repos/evidenceprime/html-docx-js/stargazers","contributors_url":"https://api.github.com/repos/evidenceprime/html-docx-js/contributors","subscribers_url":"https://api.github.com/repos/evidenceprime/html-docx-js/subscribers","subscription_url":"https://api.github.com/repos/evidenceprime/html-docx-js/subscription","commits_url":"https://api.github.com/repos/evidenceprime/html-docx-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/evidenceprime/html-docx-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/evidenceprime/html-docx-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/evidenceprime/html-docx-js/contents/{+path}","compare_url":"https://api.github.com/repos/evidenceprime/html-docx-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/evidenceprime/html-docx-js/merges","archive_url":"https://api.github.com/repos/evidenceprime/html-docx-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/evidenceprime/html-docx-js/downloads","issues_url":"https://api.github.com/repos/evidenceprime/html-docx-js/issues{/number}","pulls_url":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls{/number}","milestones_url":"https://api.github.com/repos/evidenceprime/html-docx-js/milestones{/number}","notifications_url":"https://api.github.com/repos/evidenceprime/html-docx-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/evidenceprime/html-docx-js/labels{/name}","releases_url":"https://api.github.com/repos/evidenceprime/html-docx-js/releases{/id}","created_at":"2014-07-31T14:34:41Z","updated_at":"2015-08-18T20:58:15Z","pushed_at":"2015-08-13T13:07:59Z","git_url":"git://github.com/evidenceprime/html-docx-js.git","ssh_url":"git@github.com:evidenceprime/html-docx-js.git","clone_url":"https://github.com/evidenceprime/html-docx-js.git","svn_url":"https://github.com/evidenceprime/html-docx-js","homepage":"http://evidenceprime.github.io/html-docx-js/","size":984,"stargazers_count":36,"watchers_count":36,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":5,"forks":8,"open_issues":5,"watchers":36,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13"},"html":{"href":"https://github.com/evidenceprime/html-docx-js/pull/13"},"issue":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/13"},"comments":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/evidenceprime/html-docx-js/statuses/e57320714618b0e4933a2d52a0ac3da033d48b39"}}}}