Unformatted Code Detector

:discourse2: Summary Unformatted Code Detector detects unformatted code and gives a warning before posting.
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/unformatted-code-detector
:open_book: New to Discourse Themes? Beginnerā€™s guide to using Discourse Themes

Install this theme component

Features

Users posting unformatted code will see a warning message instructing them how to format it correctly.

Sensitivity and whether it detects HTML are configurable via theme settings.

Settings

Name Description
emoji icon The emoji icon to be displayed next to the title in the unformatted warning modal.
disable at trust level Disable warning for users with a trust level of N or higher. -1 = enabled for all users.
sensitivity Sensitivity of the detection algorithm. 0 = plugin disabled; 1 = warn for anything that looks even slightly like code.
min post length to check Minimum post length to check (number of characters)
max post length to check Maximum post length to check (number of characters). -1 = no maximum.
include html Check for HTML tags as well as other types of code. Recommended to disable if users frequently need to render custom HTML in their posts.
Translation Default
warning_modal.title Are you posting code?
warning_modal.content It looks like your post may contain code or logs. To keep your post readable, please remember to format your code using the Preformatted text toolbar button </>, or the backtick ` key on your keyboard, like so: [examples]
warning_modal.do_not_show_again do not show this message again
warning_modal.fix_post Edit Post
warning_modal.ignore_and_post_anyway Post Anyway

Debugging

If you receive a warning for a post which doesnā€™t include any text, you can print debug information by opening the browser JS console, and typing debugUnformattedCodeDetector() Enter. This will print some information about which lines were considered ā€˜codeā€™, and what the sensitivity settings are.

:information_source: ā€œDo not show this message againā€ only works per device, not per user. This is a known issue and will be fixed once Discourse gains the functionality to attach user info from themes.


:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

Last edited by @JammyDodger 2024-06-16T11:48:08Z

Check documentPerform check on document:
58 Likes