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.
We at the Home Assistant forums think that this is the best thing invented since sliced bread. Or maybe Home Assistant. Thank you so so much @lionel-rowe!!!
Two minor request:
I donât want to allow users to skip formatting or disable the dialog in the future. I want them to feel pain until they change their ways. Iâm sadistic like that. Can you make the âDonât show this message againâ and âPost anywayâ buttons optional? For now Iâve hid them with some CSS but would be better to just not include the HTML at all.
Unsure if you are doing language detection or not, but if you are, can you add the estimated language name after the first code fence so that users will properly syntax highlight too?
I wouldnât recommend hiding them, especially if you leave the setting to include HTML detection on. Power users may still want to have their (sanitized) HTML parsed as such, not formatted as code. Two examples where this can be useful are kbd and abbr tags.
If you exclude HTML tags from detection (which may be viable depending on the scope of your forum), hiding the âdonât show this againâ would probably be OK. I still wouldnât recommend hiding the âpost anywayâ, though, because there are bound to still be some edge cases of false positives (I hit one the other day where Iâd omitted a space before an opening parenthesis â poor typesetting, but not unformatted code). Then youâll have a situation where users canât post their question at all, and, unless they report the issue to you directly, you wonât even know about it.
Language detection is beyond the scope of this component, Iâm afraid. Where possible, it looks for syntactical features shared by many languages, such as lines ending in semicolons, certain configurations of curly braces, and so on.
I am thinking about ways to enhance the UX, though. One big improvement would be to make it much more interactive. For example, instead of a simple modal, the user would be presented with a wizard that first asks them which language their post concerns (select from a dropdown), then a screen which asks them to select which ranges of their post are code (defaulting to lines that contain strings flagged by the plugin), then generating the appropriate markdown. This would still include a âskip and post anywayâ option, though, for the reasons I mentioned.
I donât have a timeline for this change, but itâd be good to know if itâs something people would be interested in.
Quick note, we will be official-izing this component soon and working closely with @lionel-rowe and @david to get there. Any ideas or feedback, now is the time to share it!
It would also be great if there was a hint where the suspected unformatted code is.
I was just writing another reply and got the alert, although I havenât pasted any code. After a while I realized itâs because I used the word topic_id⌠But itâs not obvious that the detector thinks this word is code (and most people wouldnât think that) IMO.
I think that when a word has an underscore in it that doesnât necessarily mean itâs code.
Thanks for all your feedback so far folks! Weâll be adding and tweaking a few settings to reduce the oversensitivity of detection.
@tpetrov one other thing â does the wording of the popup make it clear that you can choose to ignore it and post anyway if you donât think your post contains code? Or does it make it seem like youâre forced to find and âfixâ the perceived problem?
My concern is that a lot of people will not read through itâŚ
You know, when people see a popup with more than one sentence text nowadays, they seem to ignore the text and look for the button Ok (I accept cookies, terms, etc,).
Still, maybe âIt looks like your post may contain unformatted codeâ could be changed to âDo you use code in your post?â, as sometimes questions draw more attention.
Iâm not a UX expert, but this button seems a bit nuclear:
- something I wouldnât like to click. Which of course is the idea - that people will not simply skip it instead of trying to format their post better.
Oooh, I like this idea⌠but I just got a false positive:
It might have been the broken links that tripped it up? Theyâre just taken from the templating engine and look like: [keep things civilized](%{guidelines_url}). Or maybe the HTML img tag?
Weâre rolling out new copy, and building a corpus of positive and negative test sample posts for the component. Bear with us, as this is shaping up nicely!
Minor nitpick: The default for the warning_modal.content is asking for the âcodeâ toolbar button, but this button is called the âPreformatted textâ button in the editor when you hover over it with your mouse.
To make it easier for new users to find this button (they will not find any code button), the warning_modal.content should be changed from âcode buttonâ â âPreformatted text buttonâ.
I just noticed that changing even a single character in warning_modal.content breaks the formatting.
Even worse: Just clicking into the warning_modal.content input field and then moving the cursor by the arrow keys makes the input field highlighted. After clicking the green checkmark to save the âeditedâ warning_modal.content (no change at all has been done, just moving the cursor one character), the formatting is broken as shown above.
@codinghorror@lionel-rowe Maybe you should look into this and adjust the default warning_modal.content accordingly regarding spaces and backticks (missing spaces within the heavily with backticks equipped âmultiplelinesâ section were causing the problems described above).
The user obviously tried to follow the instructions, but chose the wrong key for the code fences ( ' instead of `). In the past I have also seen ... instead of ```. Both cases indicate that users need more explicit instructions which key to choose.
Alternatively: Donât confuse users with those keys and just say: Use the âPreformatted textâ button and you are done.
@lionel-rowe How can I customize the detection behaviour?
Currently the shebang is not detected as code, and I would like to change this.
Expected behaviour: #! indicates the beginning of a script and therefore should be detected as code.
In addition to this, it would be useful for us if root@ would be detected as code.
root@OpenWrt:~# ip link add link eth0 name eth0.9 type vlan id 9
root@OpenWrt:~# brctl addbr br-foo
root@OpenWrt:~# brctl addif br-foo eth0.9
root@OpenWrt:~# ip link set eth0.9 up
root@OpenWrt:~# ip link set br-foo up
There isnât any way to have per-site customizations at the moment, no. We could certainly look at adding shebang and shell prompt detection to the âcode energyâ system though.