<!-- thumbnail: https://avatars.githubusercontent.com/u/84144502?s=200&v=4 --> <!-- version: 1.2.3 --> <!-- tag: design --> <!-- excerpt: Restore syntax highlighting on revision and review pages --> # Obsolete This script is now obsolete; [a permanent fix](https://meta.stackoverflow.com/a/423542) has been implemented by Stack Exchange. --- ### About Some time ago, Stack Exchange moved to [highlight.js](https://github.com/highlightjs/highlight.js) v11. One of the breaking changes of this version was the [removal of the HTML auto-passthru](https://github.com/highlightjs/highlight.js/blob/main/VERSION_11_UPGRADE.md#feature-removal), which SE uses to indicate addition/deletion in diffs (that is, nested `span`s in `code` elements). As a result, highlighting broke in code blocks for diffs. The bug was reported [on MSO](https://meta.stackoverflow.com/q/408781) and [MSE](https://meta.stackexchange.com/q/366899). A week later, a "hotfix" was pushed which has been out for... 2 months! Essentially, it disabled highlight.js entirely on the pages where there were diffs (revisions and suggested edits). ### What is this? This is a [highlight.js plugin](https://highlightjs.readthedocs.io/en/latest/plugin-api.html). The idea as well as a large part of the code have been taken from [this GitHub issue](https://github.com/highlightjs/highlight.js/issues/2889). ### Screenshots From revisions: [![Diff highlighting in revisions][1]][1] From suggested edits: [![Diff highlighting in suggested edits][2]][2] ### License The script is licensed under the [GPL-3.0-or-later](https://spdx.org/licenses/GPL-3.0-or-later) license. ### Download [GitHub](https://github.com/userscripters/restore-highlightjs/blob/master/restore_highlightjs.user.js) | [Install](https://raw.githubusercontent.com/userscripters/restore-highlightjs/master/restore_highlightjs.user.js) ### Platform The script should work in most browsers and userscript managers. It has been tested on Chrome using Tampermonkey. ## Contact Author: [double-beep](https://stackoverflow.com/users/10607772) Organization: [UserScripters](https://github.com/userscripters) Please, submit bug reports [on the source repository](https://github.com/userscripters/restore-highlightjs/issues). Before adding a new one, please check if it hasn't been raised before. You can also [drop by to chat](https://chat.stackoverflow.com/rooms/214345), we are a friendly bunch. ## Code [Source code](https://github.com/userscripters/restore-highlightjs) written in Vanilla JS. Contributions are welcome, you can always [submit a PR here](https://github.com/userscripters/restore-highlightjs/pulls). ## Changelog | Version | Changes | | ------- | ------- | | [1.2.3](https://github.com/userscripters/restore-highlightjs/commit/c6a1f9c161140617835c7498f55084fc1944cee1) | Correctly handle rate-limits | | [1.2.2](https://github.com/userscripters/restore-highlightjs/blob/162b926248a85d1559ecf106c600cdceedf336bd/restore_highlightjs.user.js) | Fetch `langdiv` on each review item | | [1.2.1](https://github.com/userscripters/restore-highlightjs/blob/46d0c67bc3994577405118ff99c940acdc142978/restore_highlightjs.user.js) | Run `highlightCodeBlocks()` on page load for revisions, remove unnecessary `.map()` | | [1.2.0](https://github.com/userscripters/restore-highlightjs/blob/c72b6276d738acf8033bde4da3e1a59724499a2f/restore_highlightjs.user.js) | Highlight code in the suggested edits editor | | [1.1.0](https://github.com/userscripters/restore-highlightjs/blob/8ea918744ea7f4e4bf196db59a9e95db02e81765/restore_highlightjs.user.js) | Reduce reliance on Stack Exchange's JS by fetching the preferred language ourselves | | [1.0.3](https://github.com/userscripters/restore-highlightjs/blob/5e5c84a18c57115505d4cb4fe6d8c20b63ba326a/restore_highlightjs.user.js) | Use the selectors Stack Exchange uses | | [1.0.2](https://github.com/userscripters/restore-highlightjs/blob/959ad12d0082df742e51f0aef30910afa016864e/restore_highlightjs.user.js) | Prevent double-highlighting of some elements, disable unescaped HTML warnings ([after request](https://chat.stackoverflow.com/transcript/message/53028641)) | | [1.0.1](https://github.com/userscripters/restore-highlightjs/blob/949ffa46a07910b26b0d3ab9e9ac3b94d52eb4fc/restore_highlightjs.user.js) | Update userscript metadata (`@include`, `@license`, `@homepageURL` and `@supportURL`) | | [1.0.0](https://github.com/userscripters/restore-highlightjs/blob/fe28a5dd6d5cc74948ca07a69dada2e7043ab539/restore_highlightjs.user.js) | Initial release | [1]: https://i.sstatic.net/tymuh.png [2]: https://i.sstatic.net/4OyFK.png