Coder Social home page Coder Social logo

colorize's Introduction

colorize

colorize is a lisp library for syntax highlighting supporting the following languages:

  • Common Lisp, :common-lisp
  • Emacs Lisp, :elisp
  • Scheme, :scheme
  • Clojure, :clojure alpha
  • C, :c
  • C++, :c++
  • Java, :java
  • Python, :python
  • Erlang, :erlang
  • Haskell, :haskell
  • Objective-C, :objective-c
  • Diff, :diff
  • Webkit, :webkit

Install

You are strongly encouraged to use this library via Quicklisp. Simply start your lisp and run: (ql:quickload 'colorize).

Getting Started

The API has three main entry points:

  1. COLORIZE-FILE which takes a language keyword and input file and writes the result to an html file in the same directory. An alternate path for the output file may be provided as a third argument.
  2. COLORIZE-FILE-TO-STREAM takes a keyword indicating the language, the path of a file to color, and a stream to write the result to. By default, it writes a complete self-contained page but if the :wrap keyword is given nil it only writes the colorized code snippet.
  3. HTML-COLORIZATION takes a keyword indicating the language and a string of code and returns the colorized html.

In addition, the COLORING-TYPES function takes no arguments and returns a list of the supported coloring types as keywords. Finally, the variable COLORING-CSS returns suggested css code for highlighting the produced html.

That's all for now. And remember, patches welcome!

colorize's People

Contributors

aeronotix avatar avodonosov avatar kingcons avatar woudshoo 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

Watchers

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

colorize's Issues

Investigate encode-for-tt to encode-for-pre switch...

From #lisp:
What's up?
Fade and I have an IRC bot implemented in Common Lisp which uses the colorize library to serve up source code files on a Web interface.
Oh nice. :)
The call we use is (colorize::colorize-file-to-stream :common-lisp source-file out-stream)
Sometime after your August updates, though, we started getting weird output. It's no longer breaking lines where there are line breaks in the source file, and we're also not seeing the indentation in source lines.
In the function html-colorization, there's a call to html-encode:encode-for-pre. It used to call encode-for-tt instead.
When I switch back to encode-for-tt, we get back our indentation and our line breaks.

Colorize continues to work fine for coleslaw but it's only being used under the covers by 3bmd, particularly the print-tagged-element method which in turn calls html-colorization.

What happened here? This is the commit in lisppaste that changed the call. It appears from the 3bmd source that the string resulting from html-colorization simply needs to be wrapped in a <PRE> block.

Issue with incorrect HTML being generated

The following generates invalid html:

(colorize:html-colorization :c++ "}")

Namely:

"<span class=\"\"></span>}</span></span>"

Notice that there are 3 span close tags and only one scan open tag.

I now it is not well balanced at the source code level, but unfortunately that is life for me :-(

Wim Oudshoorn.
P.S.: (This had nothing todo with coleslaw, but it is pure coincidence that I just encounter it now.)

erlang syntax highlighting fails on parenthesis

(colorize:colorize-file :erlang "foo.md")

foo.md:

[].

Fails with:

Expected paren, but is neither closing paren, nor open paren.
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {10030C7FA3}>)

Backtrace:
  0: ((LAMBDA (TYPE S) :IN CALL-FORMATTER) #<unused argument> "]")
  1: (FORMAT-SCAN :ERLANG (((:NORMAL . #1=#) . "[") ((:PAREN-ISH . #2=#) . "[") ((:PAREN-ISH . #3=#) . "[") ((:VARIABLE :PAREN-ISH . #3#) . "Foo") ((:PAREN-ISH :PAREN-ISH . #3#) . "]") ((:NORMAL . #1#) . "..
  2: (COLORIZE-FILE-TO-STREAM :ERLANG "/home/xeno/dev/aerokode/foo.md" #<SB-SYS:FD-STREAM for "file /home/xeno/dev/aerokode/foo.html" {1003523C33}> :WRAP T :CSS-BACKGROUND "default" :ENCODER ENCODE-FOR-PRE..
  3: (COLORIZE-FILE :ERLANG "/home/xeno/dev/aerokode/foo.md" NIL)
  4: (SB-INT:SIMPLE-EVAL-IN-LEXENV (COLORIZE-FILE :ERLANG "/home/xeno/dev/aerokode/foo.md") #<NULL-LEXENV>)
  5: (EVAL (COLORIZE-FILE :ERLANG "/home/xeno/dev/aerokode/foo.md"))
 --more--

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.