Testing Syntax Highlighter

+1 Bucky Roberts · July 30, 2014
Python
@requires_authorization
def somefunc(param1='', param2=0):
r'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
return (param2 - param1 + 1 + 0b10l) or None

class SomeClass: pass

>>> message = '''interpreter
... prompt'''

Ruby
class A < B; def self.create(object = User) object end end
class Zebra; def inspect; "X#{2 + self.object_id}" end end

module
include Comparable

# @param test
# @return [String] nothing
def foo(test)
Thread.new do |blockvar|
ABCreverse(:a_symbol, :'a symbol', :<=>, 'test' + ?\012)
answer = valid?4 && valid?CONST && ?A && ?A.ord
end.join
end

def [](index) self[index] end
def ==(other) other == self end
end

class Car < ActiveRecord::Base
has_many :wheels, :class_name => 'Wheel', :foreign_key => 'car_id'
end
omega = -> { 'alpha' }
alpha = ->(arg) { arg*2 }
hash = {1 => 'one', 2 => 'two'}

anIdentifier = an_identifier
Constant = 1
render action: :new

str =~ /^(?:foo)$/
str =~ %r{foo|bar|buz$}
str =~ %r!foo|bar$!
str =~ %r[foo|bar$]
str =~ %r(\(foo|bar\)$)

2.0.0p0 :001 > ['some']
=> ["some"]
2.0.0p0 :002 > if true
2.0.0p0 :003?> "yop"
2.0.0p0 :004?> end
=> "yop"

>> obj = OpenStruct.new :integer => 987, :symbol => :so_great
=> #<OpenStruct integer=987, symbol=:so_great>
>> [obj,obj,obj]
=> [#<OpenStruct integer=987, symbol=:so_great>, #<OpenStruct integer=987, symbol=:so_great>, #<OpenStruct integer=987, symbol=:so_great>]
>> {1 => obj, 2 => obj}
=> {1=>#<OpenStruct integer=987, symbol=:so_great>, 2=>#<OpenStruct integer=987, symbol=:so_great>}
>> if 10 > 20
>> "YEAH"
>> else
?> "NO"
>> end
=> "NO"


Perl

# loads object
sub load
{
my $flds = $c->db_load($id,@_) || do {
Carp::carp "Can`t load (class: $c, id: $id): '$!'"; return undef
};
my $o = $c->_perl_new();
$id12 = $id / 24 / 3600;
$o->{'ID'} = $id12 + 123;
#$o->{'SHCUT'} = $flds->{'SHCUT'};
my $p = $o->props;
my $vt;
$string =~ m/^sought_text$/;
$items = split //, 'abc';
$string //= "bar";
for my $key (keys %$p)
{
if(${$vt.'::property'}) {
$o->{$key . '_real'} = $flds->{$key};
tie 'CMSBuilder::Property', $o, $key;
}
}
$o->save if delete $o->{'_save_after_load'};

# GH-117
my $g = glob("/usr/bin/*");

return $o;
}

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Mathias Frits Rørvik · August 25, 2014
What's up with the question mark stuff going on? Do you convert between charsets?
0 Bucky Roberts · August 25, 2014
Question mark  diamond means an unknown symbol/character.  It is having some trouble determining between the code it is supposed to display and the code is for the actual site. 
0 Yoncho Yonchev · August 25, 2014
Btw instead of ':)' I get 'https://buckysroom.org/images/emoticons/smile.png
' in the code tags. Just saying.

Provide some test page for that syntax high-lightening as you haven't written enough comments at least for me to make it working- I consider my javascript level pretty basic, but enough to get most of your code and I understand how it works. Your functions  dont have neither comments, not meaningful names as the conventions asks for so I am lost.
0 Bucky Roberts · August 25, 2014
You just have to call:

hljs.initHighlightingOnLoad(code_goes_here); 


It is converting the less than sign in most languages properly, I just don't know how to have it convert it in all languages. If you can figure out what line of code I have to edit, it would help me out a ton  :)
0 Yannis Sp · August 25, 2014
Bucky i think the div that contain the highlighted code has a width that is bigger than the forum white space and it has exceed the limit.Or the padding.
0 Bucky Roberts · August 25, 2014
It should be limited by the forums max-width. It seems fine on my computer. What browser are you using?
0 Yannis Sp · August 25, 2014
Google chrome.Maybe the adblock but i have disabled it for this page..
0 Bucky Roberts · August 25, 2014
Does it look like this?

/images/forum/upload/2014-08-25/d83ca6cd98a88889e8179c84d1424b4c.png
-1 Yannis Sp · August 25, 2014
Holy shit it is a bug.Even though i have disable the adblock for the site it messes up the dimensions of the forum elements.Check how i watch the page./images/forum/upload/2014-08-25/3135a67aa5befaa76d5e3024e4cee4d9.png
-1 Bucky Roberts · August 25, 2014
Well, at least I have something else to work on now  :getlost:  haha
  • 1
  • 2

Bug Reports

107,131 followers
About

Found a bug on the site? Report it here. For all security related bugs, please send me a private message.

Links
Moderators
Bucky Roberts Administrator