From: Dave Benjamin <dave@ramenlabs.com>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Syntax highlighting and Ocaml/PHP integration
Date: Wed, 01 Oct 2008 08:27:27 -0700 [thread overview]
Message-ID: <48E396DF.6080304@ramenlabs.com> (raw)
In-Reply-To: <650721.83058.qm@web54605.mail.re2.yahoo.com>
Dario Teixeira wrote:
> I'm looking for a GPL-compatible syntax highlighting library with support
> for most common programming languages and markups. Obviously I would
> prefer a native Ocaml library, though something in C would also be
> acceptable due the relative ease of writing bindings.
I have had decent results opening a pipe to GNU source-highlight. I'm
mainly using it on JSON, so I can't vouch for its support of other
languages but it seems pretty comprehensive.
let pipe program input =
let (in_channel, out_channel) = Unix.open_process program in
output_string out_channel input;
close_out out_channel;
let result = ref [] in
begin
try
while true do
result := input_line in_channel :: !result
done
with End_of_file -> ()
end;
ignore (Unix.close_process (in_channel, out_channel));
String.concat "\n" (List.rev !result)
let pre_body = Pcre.regexp ~flags:[`DOTALL] ".*<pre>(.*)</pre>.*"
let source_highlight lang code =
let result = pipe ("source-highlight -s " ^ lang) code in
Pcre.replace ~rex:pre_body ~templ:"$1" result
Caveat: The "pipe" function above will block on large inputs due to
buffering deadlock. It should probably be rewritten using Unix.select.
Dave
next prev parent reply other threads:[~2008-10-01 15:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-01 15:21 Dario Teixeira
2008-10-01 15:27 ` [Caml-list] " Martin Jambon
2008-10-01 15:27 ` Dave Benjamin [this message]
2008-10-01 15:45 ` Re : " Adrien
2008-10-01 15:47 ` Re : " Adrien
2008-10-03 15:22 ` Dario Teixeira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48E396DF.6080304@ramenlabs.com \
--to=dave@ramenlabs.com \
--cc=caml-list@inria.fr \
--cc=darioteixeira@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox