rubychan / coderay Goto Github PK
View Code? Open in Web Editor NEWFast and easy syntax highlighting for selected languages, written in Ruby.
Home Page: http://coderay.rubychan.de/
License: Other
Fast and easy syntax highlighting for selected languages, written in Ruby.
Home Page: http://coderay.rubychan.de/
License: Other
From http://odd-eyed-code.org/issues/35
The code from Redmine is on the io-scanner branch https://github.com/rubychan/coderay/compare/io-scanner
"The current command line interface (coderay) does not provide access to all the features and options of scanners and higlighters. It should be enhanced to make it easy to use CodeRay without programming Ruby."
Discuss the New Command Line Interface in the wiki.
"We have a nice proposal; it needs to be reviewed, and then implemented. Maybe get feedback from the Pygments guys?" - @korny
Trollop may be a decent library to help with the command-line parsing.
Scanner and Encoder options are still missing.
From Redmine: http://odd-eyed-code.org/issues/45
can you add an option to output the lines number along with the syntax highlighted code?
Based on Pygments?
From Redmine: http://odd-eyed-code.org/issues/143
$ gem install coderay
Fetching: coderay-1.0.0.gem (100%)
Invalid gemspec in [/home/trans/.rvm/gems/ruby-1.9.2-p0/specifications/coderay-1.0.0.gemspec]: invalid date format in specification: "2011-09-21 00:00:00.000000000Z"
ERROR: While executing gem ... (NoMethodError)
undefined method `name' for nil:NilClass
I am using: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
Line 179 of plugin.rb fails when loading plugins that are there (json for example) when exercised by rspec when using rvm. What's also confusing, is that the next line "require path" already will raise a LoadError if the file is not found and behaves correctly in test.
Sebastian Yepes wrote a scanner for AppleScript.
From http://odd-eyed-code.org/issues/28
His code is on a branch: https://github.com/rubychan/coderay/commits/applescript-scanner
source:
function php中文() {
$issue = 'there is a encoding issue in php highlighting';
}
result:
http://coderay.rubychan.de/rays/7695
P.S. only php have encoding issue
From Redmine: http://odd-eyed-code.org/issues/140
All modern Linux terms support 256 colours (Gnome-Terminal [even though it doesn't advertise it and pretends to only support 8 colours -- and most other terminals provided and supported on GNOME, KDE and XFCE.) I'm asking and offering to help with this problem specifically because on a modern terminal with modern monitor the current colour set is pretty bright and blinding (exp: those blues kill) and some other colours tend to be harder to see unless they are darker (especially if you are using gnome-terminal with a transparent background.)
Coderay can detect colours using tput colors
(but on Gnome-Terminal it will report 8 so you should assume 256 colours because it supports it -- read above) it can also grep out TERM for 256 (in the case of multiplexors but they will also output the right colours with tput colors
) Anyways the idea is to make things more readable, force your VIM to use 256 colours in a GNOME-Terminal and see what I mean when it changes the default themes line number colours to a dark orange. Example code to prove my point in VIM:
if $COLORTERM == 'gnome-terminal'
set t_Co=256
endif
(copied from https://github.com/rubychan/coderay-old issue 2)
It woudl be great to be able to render markdown in the terminal: CodeRay.scan(text, :markdown).term
!!
Great tool btw!
I'm wondering what the preferred method for getting a list of all supported languages?
Currently i'm using CodeRay::Scanners.all_plugins, but this includes the Debug and RayDebug plugins which, as I understand it, are only used for testing.
Trying to run coderay's tests on JRuby (jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2011-06-08 6586) (OpenJDK 64-Bit Server VM 1.6.0_22) [amd64-java]) gives me the following test failures:
/usr/bin/jruby ./test/unit/suite.rb
Running CodeRay unit tests: comment_filter, count, debug, duo, file_type, filter, json_encoder, lines_of_code, null, plugin, statistic, text, token_kind_filter, tokens, word_list
Loaded suite ./test/unit/suite
Started
..........Block supersedes default value argument; use either.
F.......................F..................
Finished in 0.577 seconds.
1) Failure:
test_block_supersedes_default_warning(FileTypeTests) [./test/unit/file_type.rb:31]:
<"Block supersedes default value argument; use either.\n"> expected but was
<"">.
2) Failure:
test_plugin_not_found(PluginScannerTest) [./test/unit/plugin.rb:58]:
<CodeRay::PluginHost::PluginNotFound> exception expected but none was thrown.
53 tests, 158 assertions, 2 failures, 0 errors
ah fuck it, it's GPL 2 that's alright.
See http://www.redmine.org/issues/1689:
I'd say you just abandon tabs :) But maybe a per-language setting would be okay. Ruby style is 2 spaces, C is 8, Python is 4, for example. Better than the current 8-for-all setting.
From Redmine: http://odd-eyed-code.org/issues/219
Under "== Scanning", lines 82-86 have a subtle 1-space indent that causes "pry" to color that area as if it were ruby.
That's all.
-rking
The method is supposed to return an equivalent token stream with all newlines being a single :space token.
Also, group and line tokens have to be cut into lines. The implementation of the HTML encoder's :line_numbers => :inline
features is a good example of this technique.
Definition:
p(. A Token stream of correctly split lines is a stream where every line break is a single
:space
token that is not part of any block or line token.
Tokens#split_into_lines
must yield such a stream while retaining the token kind integrity for everything else:
- Every character must have the same token kind and block/line token nesting before and after the split.
- The resulting token stream must contain as little additional new tokens as possible.
- Splitting tokens is allowed only if they contain line breaks.
The token nesting may have to be repeated at the beginning of the new line. The method should be implemented in a way that calling it again is a non-op.
The resulting token stream must also be valid:
- Every token value must be a non-empty string or a valid token action (
open
,close
,begin_line
, orend_line
).
** Tokens may contain line breaks.- Every token must have a valid token kind (as defined in the
token_kinds.rb
list).
**nil
is not a valid token kind.- Every
open
action must have a companionclose
action of the same kind.- Every
begin_line
action must have a companionend_line
action of the same kind.
** Line tokens must not be nested.
** Tokens betweenbegin_line
andend_line
must not contain line breaks.The method
optimize
(which combines tokens of the same kind) should not create multi-line tokens. In other words,tokens.optimize.split_into_lines == tokens.optimize.split_into_lines.optimize
should betrue
for all token streams.
I guess we need this for three reasons:
- The Terminal encoders sometimes messes up colors when using pagers.
- The HTML encoder with list and div outputs without tables might be improved by this.
- Redmine/Chili project uses its own line numbering, and breaks up the code into lines before highlighting, which might not be necessary when CodeRay can provide line-wise output.
See also: Redmine issue 7495
From Redmine: http://odd-eyed-code.org/issues/222
Hi,
It would be great to use Coderay to generate PDFs using something like Prawn - has anyone looked to develop this?
I've had a go myself but I don't think my approach is very good as I don't fully understand the Coderay internals:
https://gist.github.com/2629954
The issues I have with my approach are that:
It would be great to get some feedback on my approach and some pointers on how it would be best to proceed!
Thanks,
Patrick
Hey. I'm developing a Ruby terminal application on top of CodeRay and I'm having troubles with understanding of string
, regexp
and shell
attributes.
What is regexp function
? Why does self
sub-attribute set a color value for \d
, \w
, \b
and so on?
regexp:
self
content
delimiter
modifier
function
Why does self
sub-attribute set a color value for escape sequences like \n
, \t
and so on?
shell:
self
content
delimiter
Why does self
sub-attribute set a color value for escape sequences like \n
, \t
and so on? What is a string modifier
? Why does escape
sub-attribute not set a color for escape sequences?
string:
self
content
modifier
escape
delimiter
From Redmine: http://odd-eyed-code.org/issues/77
Wouldn't looking at http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files help? The page contains language definition files for a variety of programming languages for Notepad++ including keywords and common color coding used. Perhaps this could be used to kick-start development for CodeRay? - Robert Thomas
Coding for VB is included with Notepad++ itself in the langs.xml file. Here's a list of the keywords:
addhandler addressof andalso alias and ansi as assembly attribute auto begin boolean byref byte byval call case catch cbool cbyte cchar cdate cdec cdbl char cint class clng cobj compare const continue cshort csng cstr ctype currency date decimal declare default delegate dim do double each else elseif end enum erase error event exit explicit false finally for friend function get gettype global gosub goto handles if implement implements imports in inherits integer interface is let lib like load long loop lset me mid mod module mustinherit mustoverride mybase myclass namespace new next not nothing notinheritable notoverridable object on option optional or orelse overloads overridable overrides paramarray preserve private property protected public raiseevent readonly redim rem removehandler rset resume return select set shadows shared short single static step stop string structure sub synclock then throw to true try type typeof unload unicode until variant wend when while with withevents writeonly xor
I was wondering if we could get a patch against 0.9 branch since Pry relies on Coderay 0.9 for now.
Pry ticket: pry/pry#352
Original coderay ticket: #3
Andreas Schwarz wrote a scanner for AVR Assembler.
Code from RedMine is on a branch https://github.com/rubychan/coderay/compare/avrasm-scanner
Hi Murphy,
I'm getting 6 failures with rake test:exe
on master, or if I checkout the v1.0.7 tag. Maybe I'm doing something wrong, as Travis CI is passing?
Also seeing some issues with rake test:scanners
. The tests for Go should really only exist on the go-scanner branch at this point, so that the full scanner suite runs on master.
Nathan.
Hello.
I have a file called foo.rb
I do this in bash:
cat foo.rb | coderay -ruby
This works and this outputs nice colours. Which is what I was searching for.
There is just one thing:
I do not know how to modify those colours. If I have black background, then
darkblue colours are hard to see.
Thus, I wish to modify the colours. But I do not know how. I could perhaps
patch the source to coderay for me, which is possible. But I want something
more elegant.
I propose either the addition of a .coderayrc file, where colours can be defined.
Or, commandline switch to use different colour-profiles.
PS: I think right now my only workaround is to modify the .rb files for coderay,
right?
Hi coderay author, according to Apache website (http://www.apache.org/legal/3party.html#criteriaandcategories) , LGPL License in incompatible with Apache License, so it prevent us from using coderay in an open source project with Apache License. This make coderay not so free to use .
Is it possible to license coderay under Apache License or MIT ?
From: http://odd-eyed-code.org/issues/32
Tony Arnold asked for an Objective-C Scanner.
"Objective-C support would be great in CodeRay (and therefore Redmine). I haven't really looked at how CodeRay works (I'm not a Ruby developer), but is it possible to provide highlighting for Cocoa classes in addition to language syntax and keywords? See http://coderay.rubychan.de/rays/show/6332 for an example of "Cocoa heavy" Objective-C." @danthorpe
"Sure! A list of all the built-in names would be great. Objective-C is becoming more popular, and I'm a little familiar with it. You can speed up the work by collecting more (public domain or LGPL) example code." - @korny
I use the :table
styling for line numbers. But when there's only a single line of code the line number column only contains a blank <pre></pre>
, where I'd expect to be a 1
.
Someone has written a start to c# support here: http://www.redmine.org/boards/3/topics/11616 - Joshua Galvez
Thanks Joshua! The C# scanner Joshua mentioned was created and posted by me.
For I don't have enough knowledge on Ruby, I only made small modifications on the Java scanner carefully to make it work with C#.
Because I don't know how to set up a standalone environment for developing for the latest version Coderay, I just worked in the Redmine environment. As a result, I could only use an old version of the Java scanner to start with, but not the latest version.
The version of Coderay in Redmine current trunk is now 0.7.6.227, quite an old version, lacking of quite a lot of new features.
- percy li
From Redmine: http://odd-eyed-code.org/issues/78
Hi, a few people running are complaining about this, see here: pry/pry#280
any idea?
Here is the grammar/lexic for CSS 2.1: http://www.w3.org/TR/CSS2/grammar.html
Very useful, the CodeRay scanner should be validated against it.
From Redmine: http://odd-eyed-code.org/issues/120
After seeing the list of supported languages I was quite disappointed to see that Perl was not in the list.
Any plans to support it?
We just started using RedMine at $work
.
If the answer is "patches welcome" you may hear from me again sometime...
I use table to display the code. Sometime a line of the code is too long so the table overflows. I want to set its wrap's overflow, how can I select it?
Some of my colleagues and me created a scanner for Fortran90, Fortran95 and Fortran2003. We use this patch for our redmine installation and did not encounter any errors, yet.
The only thing left on the todo list is the openmp term !$OMP at the beginning of the line. It would be nice to have that feature because our code make heavy use of parallelism (climate modelling). It may not be absolutely necessary for many other fortran programmers. If you have any implementation hints for me, please leave a comment.
Ralf Mueller
His code is on a branch: https://github.com/rubychan/coderay/compare/fortran-scanner
From Redmine: http://odd-eyed-code.org/issues/202
Would be nice to have one.
From http://odd-eyed-code.org/issues/40
The code from Redmine is on a branch: https://github.com/rubychan/coderay/compare/latex-encoder
We need a coderay-scanner-tests
repo to get started.
@murphy_karasu Hey I was wondering if it’s possible to disable click to hide line numbers with Coderay ?
Hello,
I would like to request support for x86/x64 Assembly for highlighting.
Thank you, great software!
I believe that CodeRay should consider making a Tcl as one of it's supported language.
I have attached a basic Tcl scanner. - @et
The scanners that are included in the distribution all fulfill the basic requirements. You can take the Python scanner and tests as an example. Also, the PLEAC examples are always a good source. Together, the test codes should cover all syntactic features and details of the language; that's simple for Python, and near impossible for Perl. I guess TCL is somewhere in between. - @korny
Have this about 50% done, been busy with some other stuff at the moment. The pleac data is showing me a lot about tcl that I didn't know you could even do. I'm also adding support for tk and itcl since they pretty much go hand in hand with tcl. - @et
The code Eric Thomas posted to Redmine is on a branch https://github.com/rubychan/coderay/compare/tcl-scanner
From Redmine: http://odd-eyed-code.org/issues/220
Alex Bevilacqua requested an x86 / NASM scanner.
"I've got a generic version working, but it still needs testing (as there's no way what I've got so far is right :P)." - @alexbevi
From Redmine: http://odd-eyed-code.org/issues/206
Hi Murphy,
I would be happy to help transition from RedMine to the the GitHub wiki. Right now I'm having some trouble logging in over at odd-eyed-code.org though... I'd like to be able to get at the Wiki source (edit) over there and see how well it translates to GitHub's system.
Nathan.
Nathan Weizenbaum wrote a Lisp scanner for CodeRay.
His code is on a branch: https://github.com/rubychan/coderay/commits/lisp-scanner
From http://odd-eyed-code.org/issues/30
Need example code.
I dunno if this is the place to post this, but since yesterday I'm getting :
Firefox can't establish a connection to the server at coderay.rubychan.de
Most of the documentation is there and I was needing to read about it and the css (since I'm getting new classes with the last gem, no more abbreviations). but i can't seem to get in. Thanks.
Would be nice.
From Redmine: http://odd-eyed-code.org/issues/135
This has pretty much already been done for you, just need to pull in the files. I have been working with Petr Kovář to fix a couple of bugs.
Currently, the following markup confuses CodeRay:
<textarea disabled>
This text area has been disabled.
</textarea>
The file test1.xml
hosted here has a good list of attributes that do not require a value, although there are new boolean attributes in the HTML5 spec:
gem install fail with return code 134:
FortyTwo ~/[…]/laboutique on async_export(v1.7.1lb-25-gb8d3a11)
91 laboutique:async_export % gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.6 (2010-09-02 patchlevel 420) [i686-darwin12.1.0]
- INSTALLATION DIRECTORY: /Users/thomas/.rbenv/versions/1.8.6-p420/gemsets/odmcul
- RUBY EXECUTABLE: /Users/thomas/.rbenv/versions/1.8.6-p420/bin/ruby
- EXECUTABLE DIRECTORY: /Users/thomas/.rbenv/versions/1.8.6-p420/gemsets/odmcul/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-12
- GEM PATHS:
- /Users/thomas/.rbenv/versions/1.8.6-p420/gemsets/odmcul
- /Users/thomas/.rbenv/versions/1.8.6-p420/gemsets/global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
FortyTwo ~/[…]/laboutique on async_export(v1.7.1lb-25-gb8d3a11)
92 laboutique:async_export % gem install --backtrace -V coderay
GET http://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
Installing gem coderay-1.0.8
zsh: abort gem install --backtrace -V coderay
FortyTwo ~/[…]/laboutique on async_export(v1.7.1lb-25-gb8d3a11) exited sigabrt
93 laboutique:async_export % echo $?
134
As you can see, I use rbenv on mac os X
Any pointer to fix that?
Andreas Schwarz wrote a scanner for VHDL.
From: http://odd-eyed-code.org/issues/38
His code is on a branch: https://github.com/rubychan/coderay/compare/vhdl-scanner
This is for the 0.9.8 gem, warning generated is:
/Users/john/.rvm/gems/ruby-1.9.3-preview1/gems/coderay-0.9.8/lib/coderay/token_classes.rb:6: warning: assigned but unused variable - with
This is very easy to fix, just change line 6 of token_classes.rb from:
ClassOfKind.update with = {
to
ClassOfKind.update({
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.