Whitelisting some HTML tags


(cpradio) #22

Okay, this is bizarre, as it works on my development machine. Going to upgrade my sandbox to see if it magically works there again.

(cpradio) #23

Err, seems I was wrong. It does work in my sandbox … when I remember to actually include the plugin in my app.yml.

@broz, I can’t recreate a scenario where this fails. Make sure your plugin is enabled both in your app.yml and in your Site Settings.

(Marvin Wattiau) #24

Hi guys, sorry for the up of this topic.

I explain, i have many markdown table on my discourse forum and i would like manage the header’s color on CSS file. In this way i try to apply a class on a div which contain the table but doesn’t work.

After some research i found class element are trapped for security reason.

By the way i fell on this topic and i imagine this kind of trick to solve my idea, could you tell me if it’s possible

  // [RED]...[/RED]
  // [BLUE]...[/BLUE]
  // [YELLOW]...[/YELLOW]
  ["red", "blue", "right"].forEach(function(color){
    Discourse.BBCode.replaceBBCode(color, function(contents) { return ['div', {'class':  + color}].concat(contents); });
  Discourse.Markdown.whiteListTag('div', 'class', /^.+$/);

to obtain this kind of div

   <div class="blue"> </div>

Thanks by advance guys

(Sam Saffron) #25

This is not supported in the new CommonMark engine, see: discourse-bbcode/bbcode.js.es6 at master · discourse/discourse-bbcode · GitHub for an example pattern of what is meant to be done now.

(Paul Lin) #26

Just to confirm, if I want to put blank checkboxes in a post (the checklist plugin doesn’t work here as I want the checkboxes to load up cleared each time) would the following be the right way?

  1. put a line on the plugin.rb pointing to an es6 file
  2. create the es6 file with the following:
    export function setup(helper) {
    helper.whiteList([ ‘input[type=checkbox]’ ]);
  3. put this in the post:
<input type="checkbox">Safety check step 1</input>

(Joe) #27

I’m not sure what your use case is, but if you only want blank checkboxes to be added to posts, you don’t need a plugin. You can use a theme component.

This goes in the </head> section:

<script type="text/discourse-plugin" version="0.8.18">
var checkbox_selector = 'div[data-theme-checkbox="1"]';

$.fn.checkbox = function() {
  this.each(function() {
    id = Math.floor(Math.random() * 900) + 10000;
    text = $(this).text();
      "<label for=" +
        id +
        "><input id=" +
        id +
        ' type="checkbox"> ' +
        text +
  return this;

api.decorateCooked($elem => $elem.children(checkbox_selector).checkbox());

So that when you enter

<div data-theme-checkbox='1'>This is a test</div>

It will get converted into this


Again, this won’t store any data but that’s what I think you wanted based on your description above.