{"action":"created","issue":{"url":"https://api.github.com/repos/jgm/commonmark.js/issues/41","labels_url":"https://api.github.com/repos/jgm/commonmark.js/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/jgm/commonmark.js/issues/41/comments","events_url":"https://api.github.com/repos/jgm/commonmark.js/issues/41/events","html_url":"https://github.com/jgm/commonmark.js/issues/41","id":82302165,"number":41,"title":"Allow Node classes to be set","user":{"login":"bebraw","id":166921,"avatar_url":"https://avatars.githubusercontent.com/u/166921?v=3","gravatar_id":"","url":"https://api.github.com/users/bebraw","html_url":"https://github.com/bebraw","followers_url":"https://api.github.com/users/bebraw/followers","following_url":"https://api.github.com/users/bebraw/following{/other_user}","gists_url":"https://api.github.com/users/bebraw/gists{/gist_id}","starred_url":"https://api.github.com/users/bebraw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bebraw/subscriptions","organizations_url":"https://api.github.com/users/bebraw/orgs","repos_url":"https://api.github.com/users/bebraw/repos","events_url":"https://api.github.com/users/bebraw/events{/privacy}","received_events_url":"https://api.github.com/users/bebraw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-05-29T07:10:21Z","updated_at":"2015-06-24T22:56:22Z","closed_at":null,"body":"I have to transform some custom syntax like this to HTML:\r\n\r\n```\r\n# Demo\r\n\r\nT> This is some tip.\r\n\r\nW> This is some warning.\r\n```\r\n\r\nI realized I could get 90% there by transforming those into blockquotes. That's not enough, though. I would need to attach that metadata (tip, warning) there to style these appropriately.\r\n\r\nHere's what I came up with:\r\n\r\n```javascript\r\n'use strict';\r\nvar markdown = require('commonmark');\r\n\r\nvar mdReader = new markdown.Parser();\r\nvar mdWriter = new markdown.HtmlRenderer();\r\n\r\nmain();\r\n\r\nfunction main() {\r\n    var content = '# demo\\nT> some tip\\n\\nW> some warning\\n'\r\n    var content2 = '> some';\r\n    var parsed = mdReader.parse(content);\r\n\r\n    parsed = transform(parsed);\r\n\r\n    var result = mdWriter.render(parsed);\r\n\r\n    console.log(result);\r\n}\r\n\r\nfunction transform(parsed) {\r\n    var walker = parsed.walker();\r\n    var event, node;\r\n\r\n    while ((event = walker.next())) {\r\n      node = event.node;\r\n      if (event.entering && node.type === 'Text') {\r\n        if(node.literal.indexOf('T>') === 0) {\r\n            node._parent._classes = ['tip']; // XXX: not possible yet\r\n            node._parent._type = 'BlockQuote';\r\n            node.literal = node.literal.slice(2).trim();\r\n        }\r\n        if(node.literal.indexOf('W>') === 0) {\r\n            // ... same thing for warning\r\n        }\r\n      }\r\n    }\r\n\r\n    return parsed;\r\n}\r\n```\r\n\r\nDo you think it would be alright to add support for something like `._classes`? This would make it so much easier to do custom stuff like this. No doubt there are some other applications."},"comment":{"url":"https://api.github.com/repos/jgm/commonmark.js/issues/comments/115039229","html_url":"https://github.com/jgm/commonmark.js/issues/41#issuecomment-115039229","issue_url":"https://api.github.com/repos/jgm/commonmark.js/issues/41","id":115039229,"user":{"login":"jgm","id":3044,"avatar_url":"https://avatars.githubusercontent.com/u/3044?v=3","gravatar_id":"","url":"https://api.github.com/users/jgm","html_url":"https://github.com/jgm","followers_url":"https://api.github.com/users/jgm/followers","following_url":"https://api.github.com/users/jgm/following{/other_user}","gists_url":"https://api.github.com/users/jgm/gists{/gist_id}","starred_url":"https://api.github.com/users/jgm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgm/subscriptions","organizations_url":"https://api.github.com/users/jgm/orgs","repos_url":"https://api.github.com/users/jgm/repos","events_url":"https://api.github.com/users/jgm/events{/privacy}","received_events_url":"https://api.github.com/users/jgm/received_events","type":"User","site_admin":false},"created_at":"2015-06-24T22:56:22Z","updated_at":"2015-06-24T22:56:22Z","body":"+++ Vladimir Starkov [Jun 24 15 12:31 ]:\n>   right now, I need another feature. I want process markdown and add \"id\"\n>   to headings. [1]@jgm what do you think about this?\n\nIt's fairly simple to modify the HTML renderer so it adds\nautomatic IDs to headings.  Feel free to do this in your own\nbranch; it's not going to be part of the reference\nimplementation, but the spec doesn't prohibit this kind\nof variation in renderers.\n\n"}}