Greasy Fork is available in English.

old-reddit-fenced-codeblocks-fix

Fixes triple backquote style code blocks in the old reddit layout and can apply syntax highlighting.

Tác giả
Kerfuffle
Cài đặt hàng ngày
0
Số lần cài đặt
44
Đánh giá
1 0 0
Phiên bản
0.3
Đã tạo
03-03-2023
Đã cập nhật
06-03-2023
Giấy phép
MIT
Áp dụng cho

old-reddit-fenced-codeblocks-fix

Overview

Fixes the display of fenced code blocks when using the old reddit layout. For example, the new reddit will allow people to use markup like:

```somelanguage
code_code();
```

Unfortunately, they never updated the old reddit to handle this so it comes out a garbled mess. This userscript attempts to find those comments and fix them. It can also perform syntax highlighting on the code at the same time.

Before

Before

After

After

Usage

The default settings will run the userscript automatically on page load. Note that currently it does not automatically get reapplied when new comments are loaded or collapsed ones are expanded. It also currently doesn't work in private messages and modmail (not a hard fix, so I can probably do it if someone pokes me).

It should also add an "Apply" action which can be accessed through your userscript manager. This can be used to manually reapply it after loading new content which needs the fix.

Configuration

See the top of the script source code for possible configuration options. You can prevent it from running automatically, change the syntax highlighting theme (defaults to dark github style), etc. The configuration is stored as a setting in the userscript manager. The exact way to modify it will depend on what you're using, but here's an example with ViolentMonkey: Go like you're going to edit the script, then choose the "values" tab at the top. You can edit the settings in JSON format from there. If you make a mistake or want to reset to the defaults, simple delete the config key and the userscript will regenerate from the defaults.

Notes/limitations

  1. Currently only tested on Firefox and ViolentMonkey (there's no particular reason I know of that it should fail on different browsers or userscript managers).
  2. It pulls in two relatively heavy dependencies: a markup to HTML engine and a syntax highlighting engine. If you don't need syntax highlighting, you can potentially just remove the @require line near the top of the script. It will detect highlighting is unavailable regardless of the configuration settings.
  3. It works by completely regenerating the HTML from the comment/post markup using a different engine than reddit. This may cause weird effects. (Appears to work for the testing I've done so far).
  4. Pages in the old reddit design don't contain the original markup, so any comment/submission that needs to be fixed requires loading the markup using an API call. This could be slow if there are a lot of comments requiring the fix (generally they are rare though).
  5. Since this regenerates the markdown, it will clobber changes from other addons/userscripts. For example, RES media preview buttons.