Giter Site home page Giter Site logo

coderay's Introduction

CodeRay

CircleCI Gem Version Maintainability

About

CodeRay is a Ruby library for syntax highlighting.

You put your code in, and you get it back colored; Keywords, strings, floats, comments - all in different colors. And with line numbers.

Installation

gem install coderay

Dependencies

CodeRay needs Ruby 1.8.7, 1.9.3 or 2.0+. It also runs on JRuby.

Example Usage

require 'coderay'

html = CodeRay.scan("puts 'Hello, world!'", :ruby).div(:line_numbers => :table)

Documentation

See rubydoc.

coderay's People

Contributors

avezina-ubik avatar benbasson avatar conradirwin avatar deivid-rodriguez avatar dfa1 avatar djberg96 avatar dslh avatar eric-guo avatar jgeiger avatar jordimassaguerpla avatar junaruga avatar jwillemsen avatar korny avatar mtasaka avatar nathany avatar noprompt avatar pat avatar shimomura1004 avatar shurizzle avatar t-gergely avatar tildewill avatar tricknotes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coderay's Issues

Install Date Error

$ 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]

Tcl scanner

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

Fortran Scanner (Fortran 90, 95, 2003)

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

Perl support

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...

Spurious 1-Space Indent in Docs

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

Term encoder still has problems with nested tokens

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

Visual Basic Scanner

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

Support a 256 colour set in modern terms.

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

Objective-C Scanner

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

Extraneous file check fails in rspec

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.

How to not list debug and raydebug

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.

Class attribute for wrap?

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?

Improved command line interface

"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

Support ASM

Hello,

I would like to request support for x86/x64 Assembly for highlighting.

Thank you, great software!

Add support for boolean HTML attributes

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:

  • <iframe>: seamless and sandbox (source)
  • <style>: scoped (source)

Website offline

I dunno if this is the place to post this, but since yesterday I'm getting :


Unable to connect

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.

PDF encoding support

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:

  • I'm defining styles in the encoder using a hash, yet the HTML encoder seems to fetch data from a CSS
  • It's really reliant on Prawn inline formatting, which might not be so bad for doing snippets (e.g. like the div encoder) but it would be good to be able to generate complete pdf files too
  • I'm not sure the best way to unit test the encoder

It would be great to get some feedback on my approach and some pointers on how it would be best to proceed!

Thanks,
Patrick

generates a warning in ruby 1.9.3 (when run with -w)

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({

Line numbers

can you add an option to output the lines number along with the syntax highlighted code?

Transition to GitHub Wiki & Issues

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.

Test failures for CodeRay Executable

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.

Tokens#split_into_lines

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, or end_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 companion close action of the same kind.
  • Every begin_line action must have a companion end_line action of the same kind.
    ** Line tokens must not be nested.
    ** Tokens between begin_line and end_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 be true 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

Line number blank with single line code

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.

coderay 1.0.0 fails tests on jruby

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

C# Scanner

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

Feature Request: use ~/.coderayrc or allow another means to customize the colours on commandline

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?

Can't install coderay gem v=1.0.8 with ruby 1.8.6-p420

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.