{"action":"created","issue":{"url":"https://api.github.com/repos/showdownjs/showdown/issues/255","repository_url":"https://api.github.com/repos/showdownjs/showdown","labels_url":"https://api.github.com/repos/showdownjs/showdown/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/showdownjs/showdown/issues/255/comments","events_url":"https://api.github.com/repos/showdownjs/showdown/issues/255/events","html_url":"https://github.com/showdownjs/showdown/issues/255","id":154947638,"number":255,"title":"parsing markdown inside of an extension","user":{"login":"ciel","id":438196,"avatar_url":"https://avatars.githubusercontent.com/u/438196?v=3","gravatar_id":"","url":"https://api.github.com/users/ciel","html_url":"https://github.com/ciel","followers_url":"https://api.github.com/users/ciel/followers","following_url":"https://api.github.com/users/ciel/following{/other_user}","gists_url":"https://api.github.com/users/ciel/gists{/gist_id}","starred_url":"https://api.github.com/users/ciel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciel/subscriptions","organizations_url":"https://api.github.com/users/ciel/orgs","repos_url":"https://api.github.com/users/ciel/repos","events_url":"https://api.github.com/users/ciel/events{/privacy}","received_events_url":"https://api.github.com/users/ciel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/showdownjs/showdown/labels/Help%20Needed","name":"Help Needed","color":"009800"},{"url":"https://api.github.com/repos/showdownjs/showdown/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"tivie","id":1608730,"avatar_url":"https://avatars.githubusercontent.com/u/1608730?v=3","gravatar_id":"","url":"https://api.github.com/users/tivie","html_url":"https://github.com/tivie","followers_url":"https://api.github.com/users/tivie/followers","following_url":"https://api.github.com/users/tivie/following{/other_user}","gists_url":"https://api.github.com/users/tivie/gists{/gist_id}","starred_url":"https://api.github.com/users/tivie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tivie/subscriptions","organizations_url":"https://api.github.com/users/tivie/orgs","repos_url":"https://api.github.com/users/tivie/repos","events_url":"https://api.github.com/users/tivie/events{/privacy}","received_events_url":"https://api.github.com/users/tivie/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2016-05-16T01:59:50Z","updated_at":"2016-05-16T14:08:38Z","closed_at":null,"body":"I've written a very barebones extension for `showdownjs` like this;\r\n\r\n````\r\n    showdown.extension('notice', () => {\r\n        return {\r\n            type: 'lang',\r\n            regex: /([^\\s]* > )(.*)/g,\r\n            replace: `<div class=\"notice notice-$1\">$2</div>`\r\n        };\r\n    });\r\n````\r\nAnd it works beautifully - but the text that gets put between the two `<div>` layers is not parsed. It comes out verbatim as it is typed. Is there a way to render it?\r\n\r\nIf I register it as an `output` and provide a function ,it gets parsed;\r\n````\r\n    showdown.extension('notice', () => {\r\n        return {\r\n            type: 'output',\r\n            regex: /([^\\s]* > )(.*)/g,\r\n            filter: (text: string,\r\n                     converter: Showdown.Converter,\r\n                     options: Showdown.ConverterOptions) => {\r\n                return text.replace(/([^\\s]* > )(.*)/g,\r\n                    `<div class=\"notice notice-$1\">$2</div>`);\r\n            }\r\n        };\r\n    });\r\n```\r\nbut this seems to run against every text, which strikes me as resource wasteful.\r\n\r\nI can put a function in the `lang` extension and parse it by manually creating a converter, but then it wraps everything in a `<p></p>` tag."},"comment":{"url":"https://api.github.com/repos/showdownjs/showdown/issues/comments/219434024","html_url":"https://github.com/showdownjs/showdown/issues/255#issuecomment-219434024","issue_url":"https://api.github.com/repos/showdownjs/showdown/issues/255","id":219434024,"user":{"login":"ciel","id":438196,"avatar_url":"https://avatars.githubusercontent.com/u/438196?v=3","gravatar_id":"","url":"https://api.github.com/users/ciel","html_url":"https://github.com/ciel","followers_url":"https://api.github.com/users/ciel/followers","following_url":"https://api.github.com/users/ciel/following{/other_user}","gists_url":"https://api.github.com/users/ciel/gists{/gist_id}","starred_url":"https://api.github.com/users/ciel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciel/subscriptions","organizations_url":"https://api.github.com/users/ciel/orgs","repos_url":"https://api.github.com/users/ciel/repos","events_url":"https://api.github.com/users/ciel/events{/privacy}","received_events_url":"https://api.github.com/users/ciel/received_events","type":"User","site_admin":false},"created_at":"2016-05-16T14:08:38Z","updated_at":"2016-05-16T14:08:38Z","body":"Thanks. Both of these seem reasonable. I’ll likely go with the first one, and just style them inside the corresponding output.\n\n \n\nFrom: Estevão Soares dos Santos [mailto:notifications@github.com] \nSent: Monday, May 16, 2016 9:07 AM\nTo: showdownjs/showdown <showdown@noreply.github.com>\nCc: Ciel <stacey.cielia.lynn@gmail.com>; Mention <mention@noreply.github.com>\nSubject: Re: [showdownjs/showdown] parsing markdown inside of an extension (#255)\n\n \n\nThat is a pickle indeed. Since the default markdown behavior is to treat blocks of text as paragraphs, that can't easily be changed.\nHowever, I can think of two ways around it:\n\n*         Leave the <p> tags and format them with css. Example:\n\n*         .notice p {\n*           line-height: normal;\n*           margin-bottom: 0;\n}\n\n*         Use an output extension to remove the <p> tags inside <div class=\"notice\">\n\nshowdown.extension('myext', [{\n  type: 'output',\n  filter: function(text) {\n    var replacement = function (wholeMatch, inner, left, right) {\n      return left + inner.replace(/^\\s*<p>/, '').replace(/<\\/p>\\s*$/, '') + right;\n    };\n    return showdown.helper.replaceRecursiveRegExp(text, replacement, '<div markdown class=\"notice.*\">', \"</div>\", \"gi\");\n  }\n}]);\n\nThe first approach only \"styles\" the issue. However, it is semantically correct to have p tags inside divs. And it's a lot simpler and faster.\n\nThe second approach removes the p tags altogether but is a bit slower. However, it's a lot faster than the output extension you proposed, since it only parses the appropriate divs.\n\n—\nYou are receiving this because you were mentioned.\nReply to this email directly or view it on GitHub <https://github.com/showdownjs/showdown/issues/255#issuecomment-219433653>   <https://github.com/notifications/beacon/AAavtJSucLldVeTf5AsA-owwqZHsXjbVks5qCHoWgaJpZM4Ie_EO.gif> \n\n"}}