{"action":"created","comment":{"url":"https://api.github.com/repos/PrismJS/prism/pulls/comments/53911350","id":53911350,"diff_hunk":"@@ -0,0 +1,82 @@\n+(function(){\n+\tif (typeof self === 'undefined' || !self.Prism || !self.document) {\n+\t\treturn;\n+\t}\n+\n+\tvar callbacks = [];\n+\n+\tPrism.plugins.toolbar = {};\n+\n+\t/**\n+\t * Register a button callback with the toolbar.\n+\t *\n+\t * @param {Object|Function} opts\n+\t */\n+\tPrism.plugins.toolbar.registerButton = function (opts) {\n+\t\tvar callback;\n+\n+\t\tif (typeof opts === 'function') {\n+\t\t\tcallback = opts;\n+\t\t} else {\n+\t\t\tcallback = function (env) {\n+\t\t\t\tvar element;\n+\n+\t\t\t\tif (typeof opts.onClick === 'function') {\n+\t\t\t\t\telement = document.createElement('a');\n+\t\t\t\t\telement.addEventListener('click', function () {\n+\t\t\t\t\t\topts.onClick(env);\n+\t\t\t\t\t});\n+\t\t\t\t} else {\n+\t\t\t\t\telement = document.createElement('span');\n+\t\t\t\t}\n+\n+\t\t\t\telement.innerHTML = opts.text;","path":"plugins/toolbar/prism-toolbar.js","position":33,"original_position":33,"commit_id":"44d0c1dd5007ec526cc9953c59b01604e4b08904","original_commit_id":"44d0c1dd5007ec526cc9953c59b01604e4b08904","user":{"login":"zeitgeist87","id":1210795,"avatar_url":"https://avatars.githubusercontent.com/u/1210795?v=3","gravatar_id":"","url":"https://api.github.com/users/zeitgeist87","html_url":"https://github.com/zeitgeist87","followers_url":"https://api.github.com/users/zeitgeist87/followers","following_url":"https://api.github.com/users/zeitgeist87/following{/other_user}","gists_url":"https://api.github.com/users/zeitgeist87/gists{/gist_id}","starred_url":"https://api.github.com/users/zeitgeist87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zeitgeist87/subscriptions","organizations_url":"https://api.github.com/users/zeitgeist87/orgs","repos_url":"https://api.github.com/users/zeitgeist87/repos","events_url":"https://api.github.com/users/zeitgeist87/events{/privacy}","received_events_url":"https://api.github.com/users/zeitgeist87/received_events","type":"User","site_admin":false},"body":"Is this use of `innerHTML` intentional or would `textContent` be enough?","created_at":"2016-02-24T09:15:45Z","updated_at":"2016-02-24T09:15:45Z","html_url":"https://github.com/PrismJS/prism/pull/891#discussion_r53911350","pull_request_url":"https://api.github.com/repos/PrismJS/prism/pulls/891","_links":{"self":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/comments/53911350"},"html":{"href":"https://github.com/PrismJS/prism/pull/891#discussion_r53911350"},"pull_request":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/891"}}},"pull_request":{"url":"https://api.github.com/repos/PrismJS/prism/pulls/891","id":59278487,"html_url":"https://github.com/PrismJS/prism/pull/891","diff_url":"https://github.com/PrismJS/prism/pull/891.diff","patch_url":"https://github.com/PrismJS/prism/pull/891.patch","issue_url":"https://api.github.com/repos/PrismJS/prism/issues/891","number":891,"state":"open","locked":false,"title":"Plugins: Toolbar & Copy to Clipboard","user":{"login":"mAAdhaTTah","id":4371429,"avatar_url":"https://avatars.githubusercontent.com/u/4371429?v=3","gravatar_id":"","url":"https://api.github.com/users/mAAdhaTTah","html_url":"https://github.com/mAAdhaTTah","followers_url":"https://api.github.com/users/mAAdhaTTah/followers","following_url":"https://api.github.com/users/mAAdhaTTah/following{/other_user}","gists_url":"https://api.github.com/users/mAAdhaTTah/gists{/gist_id}","starred_url":"https://api.github.com/users/mAAdhaTTah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mAAdhaTTah/subscriptions","organizations_url":"https://api.github.com/users/mAAdhaTTah/orgs","repos_url":"https://api.github.com/users/mAAdhaTTah/repos","events_url":"https://api.github.com/users/mAAdhaTTah/events{/privacy}","received_events_url":"https://api.github.com/users/mAAdhaTTah/received_events","type":"User","site_admin":false},"body":"I'm using Prism as the syntax highlighter for my WordPress plugin, [WP-Gistpen](https://github.com/mAAdhaTTah/WP-Gistpen). I've built a toolbar plugin that I'd like to contribute to Prism. I've got a first pass at extracting the plugin from its CommonJS origins,, but I need some feedback on how to change it to fit the Prism way of doing things, e.g. the HTML API. I also see some possible synergy with the [Parse Settings](https://github.com/PrismJS/prism/pull/851) plugin.\r\n\r\nThe Toolbar exposes two methods: a `hook` method, which is registered with Prism's `complete` hook, and a `registerButton` method, which takes a callback that creates the buttons. The callback will be passed the `env` and should return an `a` or `span` element, which other plugins can use to register themselves with the Toolbar to get their text or link to display.\r\n\r\nI've also created a [Clipboard](https://github.com/mAAdhaTTah/WP-Gistpen/blob/7b26f5027eba6d65fc54432401459811f98c0168/src/js/prism/clipboard.js) plugin is an example of this callback, which creates an anchor tag that, when clicked, copies the code to the clipboard. I plan to extract that into a Prism plugin as well, but I'm not sure how Prism wants to handle dependencies like [Clipboard.js](https://clipboardjs.com/), or how the download page will work with internal dependencies like this. In the interest of user friendliness, what's the best approach to take here?\r\n\r\nPrior art:\r\n\r\n* https://github.com/PrismJS/prism/issues/280\r\n* https://github.com/PrismJS/prism/issues/286\r\n* http://dev.misterphilip.com/prism/plugins/toolbar/\r\n* https://github.com/PrismJS/prism/pull/142/files\r\n\r\nOpen Questions:\r\n\r\n* [x] Should the `registerButton` method be polymorphic?\r\n* [ ] How can the CSS styles be improved?\r\n* [ ] How should we handle 3rd party dependencies, like [Clipboard.js](https://clipboardjs.com/)?","created_at":"2016-02-13T21:23:15Z","updated_at":"2016-02-24T09:15:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"99428288047daf89203ead0222d486adb9456575","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/PrismJS/prism/pulls/891/commits","review_comments_url":"https://api.github.com/repos/PrismJS/prism/pulls/891/comments","review_comment_url":"https://api.github.com/repos/PrismJS/prism/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PrismJS/prism/issues/891/comments","statuses_url":"https://api.github.com/repos/PrismJS/prism/statuses/44d0c1dd5007ec526cc9953c59b01604e4b08904","head":{"label":"mAAdhaTTah:plugin/toolbar-and-copy-to-clipboard","ref":"plugin/toolbar-and-copy-to-clipboard","sha":"44d0c1dd5007ec526cc9953c59b01604e4b08904","user":{"login":"mAAdhaTTah","id":4371429,"avatar_url":"https://avatars.githubusercontent.com/u/4371429?v=3","gravatar_id":"","url":"https://api.github.com/users/mAAdhaTTah","html_url":"https://github.com/mAAdhaTTah","followers_url":"https://api.github.com/users/mAAdhaTTah/followers","following_url":"https://api.github.com/users/mAAdhaTTah/following{/other_user}","gists_url":"https://api.github.com/users/mAAdhaTTah/gists{/gist_id}","starred_url":"https://api.github.com/users/mAAdhaTTah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mAAdhaTTah/subscriptions","organizations_url":"https://api.github.com/users/mAAdhaTTah/orgs","repos_url":"https://api.github.com/users/mAAdhaTTah/repos","events_url":"https://api.github.com/users/mAAdhaTTah/events{/privacy}","received_events_url":"https://api.github.com/users/mAAdhaTTah/received_events","type":"User","site_admin":false},"repo":{"id":50249197,"name":"prism","full_name":"mAAdhaTTah/prism","owner":{"login":"mAAdhaTTah","id":4371429,"avatar_url":"https://avatars.githubusercontent.com/u/4371429?v=3","gravatar_id":"","url":"https://api.github.com/users/mAAdhaTTah","html_url":"https://github.com/mAAdhaTTah","followers_url":"https://api.github.com/users/mAAdhaTTah/followers","following_url":"https://api.github.com/users/mAAdhaTTah/following{/other_user}","gists_url":"https://api.github.com/users/mAAdhaTTah/gists{/gist_id}","starred_url":"https://api.github.com/users/mAAdhaTTah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mAAdhaTTah/subscriptions","organizations_url":"https://api.github.com/users/mAAdhaTTah/orgs","repos_url":"https://api.github.com/users/mAAdhaTTah/repos","events_url":"https://api.github.com/users/mAAdhaTTah/events{/privacy}","received_events_url":"https://api.github.com/users/mAAdhaTTah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mAAdhaTTah/prism","description":"Lightweight, robust, elegant syntax highlighting.","fork":true,"url":"https://api.github.com/repos/mAAdhaTTah/prism","forks_url":"https://api.github.com/repos/mAAdhaTTah/prism/forks","keys_url":"https://api.github.com/repos/mAAdhaTTah/prism/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mAAdhaTTah/prism/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mAAdhaTTah/prism/teams","hooks_url":"https://api.github.com/repos/mAAdhaTTah/prism/hooks","issue_events_url":"https://api.github.com/repos/mAAdhaTTah/prism/issues/events{/number}","events_url":"https://api.github.com/repos/mAAdhaTTah/prism/events","assignees_url":"https://api.github.com/repos/mAAdhaTTah/prism/assignees{/user}","branches_url":"https://api.github.com/repos/mAAdhaTTah/prism/branches{/branch}","tags_url":"https://api.github.com/repos/mAAdhaTTah/prism/tags","blobs_url":"https://api.github.com/repos/mAAdhaTTah/prism/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mAAdhaTTah/prism/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mAAdhaTTah/prism/git/refs{/sha}","trees_url":"https://api.github.com/repos/mAAdhaTTah/prism/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mAAdhaTTah/prism/statuses/{sha}","languages_url":"https://api.github.com/repos/mAAdhaTTah/prism/languages","stargazers_url":"https://api.github.com/repos/mAAdhaTTah/prism/stargazers","contributors_url":"https://api.github.com/repos/mAAdhaTTah/prism/contributors","subscribers_url":"https://api.github.com/repos/mAAdhaTTah/prism/subscribers","subscription_url":"https://api.github.com/repos/mAAdhaTTah/prism/subscription","commits_url":"https://api.github.com/repos/mAAdhaTTah/prism/commits{/sha}","git_commits_url":"https://api.github.com/repos/mAAdhaTTah/prism/git/commits{/sha}","comments_url":"https://api.github.com/repos/mAAdhaTTah/prism/comments{/number}","issue_comment_url":"https://api.github.com/repos/mAAdhaTTah/prism/issues/comments{/number}","contents_url":"https://api.github.com/repos/mAAdhaTTah/prism/contents/{+path}","compare_url":"https://api.github.com/repos/mAAdhaTTah/prism/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mAAdhaTTah/prism/merges","archive_url":"https://api.github.com/repos/mAAdhaTTah/prism/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mAAdhaTTah/prism/downloads","issues_url":"https://api.github.com/repos/mAAdhaTTah/prism/issues{/number}","pulls_url":"https://api.github.com/repos/mAAdhaTTah/prism/pulls{/number}","milestones_url":"https://api.github.com/repos/mAAdhaTTah/prism/milestones{/number}","notifications_url":"https://api.github.com/repos/mAAdhaTTah/prism/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mAAdhaTTah/prism/labels{/name}","releases_url":"https://api.github.com/repos/mAAdhaTTah/prism/releases{/id}","deployments_url":"https://api.github.com/repos/mAAdhaTTah/prism/deployments","created_at":"2016-01-23T17:24:15Z","updated_at":"2016-01-23T17:24:17Z","pushed_at":"2016-02-24T05:20:10Z","git_url":"git://github.com/mAAdhaTTah/prism.git","ssh_url":"git@github.com:mAAdhaTTah/prism.git","clone_url":"https://github.com/mAAdhaTTah/prism.git","svn_url":"https://github.com/mAAdhaTTah/prism","homepage":"http://prismjs.com","size":3177,"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":"gh-pages"}},"base":{"label":"PrismJS:gh-pages","ref":"gh-pages","sha":"954c90a21729368b2d64a0e9fd2ec5e7db5fa222","user":{"login":"PrismJS","id":11140484,"avatar_url":"https://avatars.githubusercontent.com/u/11140484?v=3","gravatar_id":"","url":"https://api.github.com/users/PrismJS","html_url":"https://github.com/PrismJS","followers_url":"https://api.github.com/users/PrismJS/followers","following_url":"https://api.github.com/users/PrismJS/following{/other_user}","gists_url":"https://api.github.com/users/PrismJS/gists{/gist_id}","starred_url":"https://api.github.com/users/PrismJS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PrismJS/subscriptions","organizations_url":"https://api.github.com/users/PrismJS/orgs","repos_url":"https://api.github.com/users/PrismJS/repos","events_url":"https://api.github.com/users/PrismJS/events{/privacy}","received_events_url":"https://api.github.com/users/PrismJS/received_events","type":"Organization","site_admin":false},"repo":{"id":4979467,"name":"prism","full_name":"PrismJS/prism","owner":{"login":"PrismJS","id":11140484,"avatar_url":"https://avatars.githubusercontent.com/u/11140484?v=3","gravatar_id":"","url":"https://api.github.com/users/PrismJS","html_url":"https://github.com/PrismJS","followers_url":"https://api.github.com/users/PrismJS/followers","following_url":"https://api.github.com/users/PrismJS/following{/other_user}","gists_url":"https://api.github.com/users/PrismJS/gists{/gist_id}","starred_url":"https://api.github.com/users/PrismJS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PrismJS/subscriptions","organizations_url":"https://api.github.com/users/PrismJS/orgs","repos_url":"https://api.github.com/users/PrismJS/repos","events_url":"https://api.github.com/users/PrismJS/events{/privacy}","received_events_url":"https://api.github.com/users/PrismJS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PrismJS/prism","description":"Lightweight, robust, elegant syntax highlighting.","fork":false,"url":"https://api.github.com/repos/PrismJS/prism","forks_url":"https://api.github.com/repos/PrismJS/prism/forks","keys_url":"https://api.github.com/repos/PrismJS/prism/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PrismJS/prism/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PrismJS/prism/teams","hooks_url":"https://api.github.com/repos/PrismJS/prism/hooks","issue_events_url":"https://api.github.com/repos/PrismJS/prism/issues/events{/number}","events_url":"https://api.github.com/repos/PrismJS/prism/events","assignees_url":"https://api.github.com/repos/PrismJS/prism/assignees{/user}","branches_url":"https://api.github.com/repos/PrismJS/prism/branches{/branch}","tags_url":"https://api.github.com/repos/PrismJS/prism/tags","blobs_url":"https://api.github.com/repos/PrismJS/prism/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PrismJS/prism/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PrismJS/prism/git/refs{/sha}","trees_url":"https://api.github.com/repos/PrismJS/prism/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PrismJS/prism/statuses/{sha}","languages_url":"https://api.github.com/repos/PrismJS/prism/languages","stargazers_url":"https://api.github.com/repos/PrismJS/prism/stargazers","contributors_url":"https://api.github.com/repos/PrismJS/prism/contributors","subscribers_url":"https://api.github.com/repos/PrismJS/prism/subscribers","subscription_url":"https://api.github.com/repos/PrismJS/prism/subscription","commits_url":"https://api.github.com/repos/PrismJS/prism/commits{/sha}","git_commits_url":"https://api.github.com/repos/PrismJS/prism/git/commits{/sha}","comments_url":"https://api.github.com/repos/PrismJS/prism/comments{/number}","issue_comment_url":"https://api.github.com/repos/PrismJS/prism/issues/comments{/number}","contents_url":"https://api.github.com/repos/PrismJS/prism/contents/{+path}","compare_url":"https://api.github.com/repos/PrismJS/prism/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PrismJS/prism/merges","archive_url":"https://api.github.com/repos/PrismJS/prism/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PrismJS/prism/downloads","issues_url":"https://api.github.com/repos/PrismJS/prism/issues{/number}","pulls_url":"https://api.github.com/repos/PrismJS/prism/pulls{/number}","milestones_url":"https://api.github.com/repos/PrismJS/prism/milestones{/number}","notifications_url":"https://api.github.com/repos/PrismJS/prism/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PrismJS/prism/labels{/name}","releases_url":"https://api.github.com/repos/PrismJS/prism/releases{/id}","deployments_url":"https://api.github.com/repos/PrismJS/prism/deployments","created_at":"2012-07-10T19:47:14Z","updated_at":"2016-02-23T22:07:07Z","pushed_at":"2016-02-24T05:20:11Z","git_url":"git://github.com/PrismJS/prism.git","ssh_url":"git@github.com:PrismJS/prism.git","clone_url":"https://github.com/PrismJS/prism.git","svn_url":"https://github.com/PrismJS/prism","homepage":"http://prismjs.com","size":4226,"stargazers_count":2811,"watchers_count":2811,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":397,"mirror_url":null,"open_issues_count":98,"forks":397,"open_issues":98,"watchers":2811,"default_branch":"gh-pages"}},"_links":{"self":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/891"},"html":{"href":"https://github.com/PrismJS/prism/pull/891"},"issue":{"href":"https://api.github.com/repos/PrismJS/prism/issues/891"},"comments":{"href":"https://api.github.com/repos/PrismJS/prism/issues/891/comments"},"review_comments":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/891/comments"},"review_comment":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PrismJS/prism/pulls/891/commits"},"statuses":{"href":"https://api.github.com/repos/PrismJS/prism/statuses/44d0c1dd5007ec526cc9953c59b01604e4b08904"}}}}