{"action":"created","issue":{"url":"https://api.github.com/repos/jekyll/jekyll/issues/3435","labels_url":"https://api.github.com/repos/jekyll/jekyll/issues/3435/labels{/name}","comments_url":"https://api.github.com/repos/jekyll/jekyll/issues/3435/comments","events_url":"https://api.github.com/repos/jekyll/jekyll/issues/3435/events","html_url":"https://github.com/jekyll/jekyll/pull/3435","id":57041115,"number":3435,"title":"Fix: Invalid highlight html with rouge and linenos #2607","user":{"login":"EdMcBane","id":8511142,"avatar_url":"https://avatars.githubusercontent.com/u/8511142?v=3","gravatar_id":"","url":"https://api.github.com/users/EdMcBane","html_url":"https://github.com/EdMcBane","followers_url":"https://api.github.com/users/EdMcBane/followers","following_url":"https://api.github.com/users/EdMcBane/following{/other_user}","gists_url":"https://api.github.com/users/EdMcBane/gists{/gist_id}","starred_url":"https://api.github.com/users/EdMcBane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EdMcBane/subscriptions","organizations_url":"https://api.github.com/users/EdMcBane/orgs","repos_url":"https://api.github.com/users/EdMcBane/repos","events_url":"https://api.github.com/users/EdMcBane/events{/privacy}","received_events_url":"https://api.github.com/users/EdMcBane/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-09T14:59:46Z","updated_at":"2015-02-10T04:24:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jekyll/jekyll/pulls/3435","html_url":"https://github.com/jekyll/jekyll/pull/3435","diff_url":"https://github.com/jekyll/jekyll/pull/3435.diff","patch_url":"https://github.com/jekyll/jekyll/pull/3435.patch"},"body":"Fixes broken HTML being generated when using rouge highlighter with linenos feature enabled.\r\n\r\nCaused by a naive regex replace done on rouge output to add `<code></code>` tags within `<pre></pre>` tags, that assumes there will be just one such `<pre>` block. Rouge actually generates two when linenos is enabled, one for the line numbers and one for the actual code block.\r\n\r\nRegex replaces the first `<pre>` tag with `<pre><code>` and the **first** `</pre>` tag with `</code></pre>`. Should be the **last**.\r\n\r\nFixes issue [#2067](https://github.com/jekyll/jekyll/issues/2607)\r\n\r\n## Todo\r\n* The fix is more of a workaround, since regex-replacing tags within third-party library output should definitely be avoided, but a major change would be required and this needs input from project mantainers\r\n* The test for highlighting with rouge has been created as a separate file, may be merged into TestTags\r\n* The way the test themselves are written could be improved, in this case I kept it similar to what was already there."},"comment":{"url":"https://api.github.com/repos/jekyll/jekyll/issues/comments/73642320","html_url":"https://github.com/jekyll/jekyll/pull/3435#issuecomment-73642320","issue_url":"https://api.github.com/repos/jekyll/jekyll/issues/3435","id":73642320,"user":{"login":"parkr","id":237985,"avatar_url":"https://avatars.githubusercontent.com/u/237985?v=3","gravatar_id":"","url":"https://api.github.com/users/parkr","html_url":"https://github.com/parkr","followers_url":"https://api.github.com/users/parkr/followers","following_url":"https://api.github.com/users/parkr/following{/other_user}","gists_url":"https://api.github.com/users/parkr/gists{/gist_id}","starred_url":"https://api.github.com/users/parkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parkr/subscriptions","organizations_url":"https://api.github.com/users/parkr/orgs","repos_url":"https://api.github.com/users/parkr/repos","events_url":"https://api.github.com/users/parkr/events{/privacy}","received_events_url":"https://api.github.com/users/parkr/received_events","type":"User","site_admin":false},"created_at":"2015-02-10T04:24:08Z","updated_at":"2015-02-10T04:24:08Z","body":"> it should be Jekyll responsibility to properly deal with whatever output both pygments and rouge generate, possibly avoiding fragile regex-replaces.\r\n\r\nI agree here – any changes we make to the output are our bugs to handle. \r\n\r\nAs a *super hacky* but kind of clever way of handling this, StackOverflow suggests:\r\n\r\n```ruby\r\nnew_str = old_str.reverse.sub(pattern.reverse, replacement.reverse).reverse\r\n```\r\n\r\nI don't think we'll be going with that, but it was too funny not to share.\r\n\r\n"}}