rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
847 stars 115 forks source link

Provide a mechanism to enable/disable operator tokens #130

Closed Phrogz closed 11 years ago

Phrogz commented 11 years ago

token_kinds.rb currently has :operator => false, which drops operator markup. I'd like to turn this on for my parsing, but I don't want to have to hack the library source code to achieve it.

There should be a public interface during parsing that allows someone to override this, or any token/classes.

korny commented 11 years ago

but I don't want to have to hack the library source code to achieve it.

Mmh, you can just update the Hash:

CodeRay::TokenKinds[:operator] = 'op'

It's not frozen on purpose :-)

I consider it a public API, though it needs to be documented better.

Phrogz commented 11 years ago

It's not frozen on purpose :-)

I like your answer, but I'm confused by what you wrote, because it doesn't work. It is frozen, currently.

>> require 'coderay'
#=> true

>> CodeRay::TokenKinds[:operator] = 'op'
RuntimeError: can't modify frozen Hash
        from (irb):3:in `[]='
        from (irb):3
        from C:/Ruby193/bin/irb:12:in `<main>'

Did you mean that "It is a mistake that it is frozen, and it will be fixed in a future release"?

korny commented 11 years ago

Yikes, you're right! I think I froze it for testing once, and then accidently commited this change. Bad idea.

It's supposed to be unfrozen. I'll fix that. (In the meantime, you can try to CodeRay::TokenKinds = CodeRay::TokenKinds.dup or something.) Would such a fix also solve your request?

Phrogz commented 11 years ago

Would such a fix also solve your request?

Yup, totally. Thanks!