Unformatted Code Detector

Discourse
Thu, 28 Mar 2019 04:21:55 +0000
Theme component

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

Install this theme component

As this is an official theme component maintained by the Discourse team, Support, Bug, UX, and Feature requests can be made in the respective categories here on Meta, and tagged with the appropriate theme component tag. Click on a link below to get one started.

Support Bug UX Feature

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.

“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.

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

Last edited by @JammyDodger Sunday, June 16, 2024 11:48 AM UTC
Check document (klicke, um weitere Details zu sehen)

28 Beiträge - 13 Teilnehmer