Plugins for writing coding text in the topics

Hi there,

I would like to know if there is any plugins at Discourse which I can write a topic with codes like in the picture bellow??

With colors, idents and so on.

1 Like

I may be missing something, but you can already use code blocks:

console.log("hi");

It works the same as Discord which your screenshot was taken from.

2 Likes

sorry about my ignorance, but how can I use these code blocks writing a topic?

Exactly the ideia is to copy Discord in this way.

1 Like

3 backticks + language name (optional):

```js
console.log(“hi”);
```

1 Like

I think I got it, but for example in this code, how about the colors for some functions? It is displaying some colors but not as the picture is shown in discord.

The language is python.

input long  MagicN = 1234;

CTrade         negocio;
CPositionInfo  posicao;
bool           InseriuParcial = false;


void OnTrade()
{
   ExpiringOrdersPartial(_Symbol, MagicN);
}


void OnTick()
{   
   //....
   
   bool pos = posicao.SelectByMagic(_Symbol, MagicN);
   
   if (pos) && (!InseriuParcial)
   {
      string comment = "[part:" + IntegerToString(posicao.Ticket()) + "]"; 
      if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
      {
         negocio.BuyLimit(1.0, simbolo.Last() -500, _Symbol, 0, 0, orderTypeTime, 0, comment + " Partial");
         negocio.BuyLimit(1.0, simbolo.Last()-1000, _Symbol, 0, 0, orderTypeTime, 0, comment + " Partial");
      }
      else
      {
         //....
      }
      InseriuParcial = true;
   }
   
   //....
}

void ExpiringOrdersPartial(string symbol, long m_magic)
{  
   int total = OrdersTotal();
   for(int i = total - 1; i >= 0; i--)
   {    
      ulong  order_ticket  = OrderGetTicket(i);
      
      if((OrderGetString(ORDER_SYMBOL) != symbol) || (OrderGetInteger(ORDER_MAGIC) != m_magic))
         return;
      
      string comment = OrderGetString(ORDER_COMMENT);
      string tokenB  = "[part:";
      string tokenE  = "]";
      
      int posB = StringFind(comment,tokenB);
      if (posB != -1)
      {
         int posE = StringFind(comment,tokenE, posB + StringLen(tokenB));
         if (posE == -1)
            return;
         
         string position_ticketS = StringSubstr(comment, posB + StringLen(tokenB), posE - (posB + StringLen(tokenB)));
         ulong  position_ticket  = (ulong)StringToInteger(position_ticketS);
         
         if (!PositionSelectByTicket(position_ticket))
            OrderDelete(order_ticket);
      }
   }
}
2 Likes

AFAIK Discord uses the same library for code as we do: GitHub - highlightjs/highlight.js: Javascript syntax highlighter

If you want your code to look the same as Discord in a Discourse post, install Codeblock Theme Picker and change the theme to Solarized Dark.

4 Likes

At our site we have a page that demonstrates the different variations enabled.

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.