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.
The discussion revolves around using plugins in Discourse to write coding text in topics, similar to Discord. Thamer initially asked about plugins for writing code with colors and indentation. Canapin replied that Discourse already uses code blocks, which can be used with syntax highlighting by adding the language name after the backticks.
Thamer asked for clarification on how to use code blocks, and Canapin provided an example. When Thamer tested the code blocks with a Python code snippet, he noted that the colors were not displayed as they were in Discord.
Falco suggested that Discord uses the same library (Highlight.js) as Discourse and recommended installing the Codeblock Theme Picker plugin and changing the theme to Solarized Dark to achieve similar code formatting. EricGT shared a link to a page demonstrating different language highlighting variations.
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.
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.
3 backticks + language name (optional):
console.log("hi");
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);
}
}
}
AFAIK Discord uses the same library for code as we do: GitHub - highlightjs/highlight.js: JavaScript syntax highlighter with language auto-detection and zero dependencies. ยท GitHub
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.
At our site we have a page that demonstrates the different variations enabled.