{"action":"created","issue":{"url":"https://api.github.com/repos/chjj/marked/issues/798","repository_url":"https://api.github.com/repos/chjj/marked","labels_url":"https://api.github.com/repos/chjj/marked/issues/798/labels{/name}","comments_url":"https://api.github.com/repos/chjj/marked/issues/798/comments","events_url":"https://api.github.com/repos/chjj/marked/issues/798/events","html_url":"https://github.com/chjj/marked/pull/798","id":173591029,"number":798,"title":"Add Feature - Support `Promise`","user":{"login":"crazyguitar","id":3689606,"avatar_url":"https://avatars.githubusercontent.com/u/3689606?v=3","gravatar_id":"","url":"https://api.github.com/users/crazyguitar","html_url":"https://github.com/crazyguitar","followers_url":"https://api.github.com/users/crazyguitar/followers","following_url":"https://api.github.com/users/crazyguitar/following{/other_user}","gists_url":"https://api.github.com/users/crazyguitar/gists{/gist_id}","starred_url":"https://api.github.com/users/crazyguitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crazyguitar/subscriptions","organizations_url":"https://api.github.com/users/crazyguitar/orgs","repos_url":"https://api.github.com/users/crazyguitar/repos","events_url":"https://api.github.com/users/crazyguitar/events{/privacy}","received_events_url":"https://api.github.com/users/crazyguitar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-27T11:06:31Z","updated_at":"2016-09-30T23:30:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/chjj/marked/pulls/798","html_url":"https://github.com/chjj/marked/pull/798","diff_url":"https://github.com/chjj/marked/pull/798.diff","patch_url":"https://github.com/chjj/marked/pull/798.patch"},"body":"Hi,\r\n\r\nI made this project support `Promise` . Consider the following scenario:\r\n\r\n```js\r\nvar marked = require('marked')\r\n    , fs = require('fs');\r\nvar renderer = new marked.Renderer();\r\n\r\nrenderer.heading = function (text, level) {\r\n  var escapedText = text.toLowerCase().replace(/[^\\w]+/g, '-');\r\n  // need read file, but we cannot using fs.readFile(filename, enc, cb).\r\n  // We cannot use  any async functions.\r\n},\r\nconsole.log(marked('# heading+', { renderer: renderer }));\r\n```\r\n\r\nthen we can solve this by using `Promise` object:\r\n\r\n```js\r\nvar marked = require('./index')\r\n  , fs = require('fs')\r\n  , util = require('util');\r\nvar renderer = new marked.Renderer();\r\n\r\nvar path = \"layout.html\";\r\n\r\nrenderer.heading = function (text, level) {\r\n  return new Promise((resolve, reject) => {\r\n    fs.readFile(path, 'utf8', (err, data) => {\r\n      try {\r\n        resolve(util.format(data, text));\r\n      } catch (e) {\r\n        reject(e);\r\n      }\r\n    });\r\n  });\r\n},\r\n\r\nmarked('# Heading2\\n```js\\nconsole.log(\"hi\")```\\n', { promise: true, renderer: renderer })\r\n.then(function(html) {\r\n  console.log(html);\r\n}).catch(e => {\r\n  console.log(e);\r\n});\r\n```\r\nand I can get the result like:\r\n\r\n```bash\r\n<h1>Heading2</h1>\r\n<pre><code class=\"lang-js\">console.log(&quot;hi&quot;)\r\n</code></pre>\r\n```\r\n\r\nThe `Promise` object solve the problem which I cannot call async functions in render function. Hope this feature can make the project better.\r\n\r\nthanks,\r\nchang-ning"},"comment":{"url":"https://api.github.com/repos/chjj/marked/issues/comments/250875031","html_url":"https://github.com/chjj/marked/pull/798#issuecomment-250875031","issue_url":"https://api.github.com/repos/chjj/marked/issues/798","id":250875031,"user":{"login":"nchase","id":197309,"avatar_url":"https://avatars.githubusercontent.com/u/197309?v=3","gravatar_id":"","url":"https://api.github.com/users/nchase","html_url":"https://github.com/nchase","followers_url":"https://api.github.com/users/nchase/followers","following_url":"https://api.github.com/users/nchase/following{/other_user}","gists_url":"https://api.github.com/users/nchase/gists{/gist_id}","starred_url":"https://api.github.com/users/nchase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nchase/subscriptions","organizations_url":"https://api.github.com/users/nchase/orgs","repos_url":"https://api.github.com/users/nchase/repos","events_url":"https://api.github.com/users/nchase/events{/privacy}","received_events_url":"https://api.github.com/users/nchase/received_events","type":"User","site_admin":false},"created_at":"2016-09-30T23:30:23Z","updated_at":"2016-09-30T23:30:23Z","body":"This would be really useful to me."}}
{"actor":{"display_login":"nchase"}}