Solved Is this a bug in the Forum Code widget ?

Nicola Mingotti

Well-Known Member

Thanks: 121
Messages: 308

#1
Hi,

I was posting a block of code in a discussion when I saw
the code is not correctly represented in the Forum.

I put here the code in a CODE block and also in a file.
Comparing the two you will see that e.g. this part is not correct
in CODE block.
====
(0..4).each do |i|
....
end
====

Code:
while true do
  st1 = `sysctl kern.cp_times`
  st1.chomp!
  vals1 = st1.split(/ /); vals1.shift
  sleep 1
  st2 = `sysctl kern.cp_times`
  st2.chomp!
  vals2 = st2.split(/ /); vals2.shift
  diffs = [-1,-1,-1,-1,-1]
  (0..4).each do |i|
    diffs = vals2.to_f - vals1.to_f
  end
  tot = diffs.sum
  diffsPerc = [-1,-1,-1,-1,-1]
  (0..4).each do |i|
    diffsPerc = (diffs / tot) * 100.0
  end
  userv = "%.1f" % diffsPerc[0]; nicev = "%.1f" % diffsPerc[1]
  systemv = "%.1f" % diffsPerc[2]; interv = "%.1f" % diffsPerc[3]
  idlev = "%.1f" % diffsPerc[4]
  puts "CPU: #{userv}% user, #{nicev}% nice, #{systemv}% system, " +
       "#{interv}% interrupt, #{idlev}% idle"
end
 

Attachments

ShelLuser

Son of Beastie

Thanks: 1,501
Messages: 3,303

#2
I can confirm that something weird is up, but it's not necessarily a bug but most likely a bad configuration (this is an assumption on my part).

See, the cause of this problem is that [i] is actually a BBCode snippet for italics. And guess what you used in your codeblock?

Code:
  (0..4).each do |i| 
    [noparse]diffs[i] = vals2[i].to_f - vals1[i].to_f[/noparse]
  end
As such the forum parsed it as if you wanted to start an italic formatted block.

I'm not sure but it is possible that this behavior can be reconfigured so that code blocks no longer parse BBCode.
 
OP
OP
Nicola Mingotti

Nicola Mingotti

Well-Known Member

Thanks: 121
Messages: 308

#3
Hi,

tobik@ suggested to use the NOPARSE tag to fix this behaviour,
putting it Just after the CODE tag.

In my opinion code blocks should be by default verbatim so that one
can easily copy and paste code and be sure the text is correctly represented.

Then, if a user wants to beautify his code, it is his duty to do it in the right way.
When I copied code from Emacs I did not expect the colors to be here,
but I expected the naked text to be here. It is just a metter of luck I re-red
the code in the forum and not in Emacs.

I suggest to modify the current "code" button behaviour in such
a way that it puts NOPARSE by default, then if somebody wants to beautify he
should close and re-open the NOPARSE at his will.

The principle would be: easy click "code" button for a simple copy and paste.
More tagging if you want something different from verbatim as setting
colors, fonts, weigth etc.

Bye
Nicola
 

danger@

Administrator
Staff member
Administrator
Moderator
Developer

Thanks: 345
Messages: 981

#5
I think this is no more required. Previously there was a custom code bbtag which was interpreting other tags within it, however there were some other problems I couldnt deal with. Since I found a way to move the builtin code button to another place within the editor I just disabled our custom code tag. The builtin code tag also supports syntax hilighting for specific languages.
 
OP
OP
Nicola Mingotti

Nicola Mingotti

Well-Known Member

Thanks: 121
Messages: 308

#6
Since the forum has been changed I tried to paste code and now the issue seems resolved. But i will check again later and close the thread if all seems fine.
 
OP
OP
Nicola Mingotti

Nicola Mingotti

Well-Known Member

Thanks: 121
Messages: 308

#7
ok, I made a test with an ugly block of code full of nasty simbols.
It was all fine ! The new (I never saw it before) code editor seems very good !
I close the thread.
 

danger@

Administrator
Staff member
Administrator
Moderator
Developer

Thanks: 345
Messages: 981

#12
To add more info to this, you can still do [CODE=rich][/CODE].

There’s no syntax highlighting in that mode but you can control the formatting yourself with bbcode.
 
Top