Re: [viewvc-dev] GNU Enscript and ViewVC 1.1...or Pygments
"C. Michael Pilato" <[email protected]>
| Newsgroups | gmane.comp.version-control.cvs.viewcvs.devel |
|---|---|
| Organization | CollabNet, Inc. |
| Message-ID | <4836F46D.5010603__48935.2956218228$1211561143$gmane$org@collab.net> |
Your mail could not have come at a more coincidental time. I happen to have
spent some time today trying to find a Python-based syntax highlighter
because I'm getting really annoyed by trying to maintain integrations with
'enscript', 'highlight', 'src-highlite', 'php', 'py2html', etc.
Interestingly, your integration to Pygments uses the 'pygmentize'
command-line program. Surely there is a way to simply import the necessary
bits of the Pygments library and go all-Python here, right?
I'll file a tracker issue for Pygments integration referencing your mail,
and including your patch. But I'd like to find out more about this library
and how we could use it more directly inside ViewVC.
Sandy Pérez González wrote:
> After some attempts, now GNU Enscript works fine using the ViewVC�s
> standalone server. When I try to access through Apache it does not
> work. Definitely, I threw in the towel with GNU Enscript and Apache.
>
> But, I have made another attempt with Pygments (http://pygments.org/).
> And, again, it works fine using the ViewVC�s standalone server but not
> using Apache. So, I think both (GNU Enscript and Pygments) are fine as
> well as ViewVC. In my opinion, what is wrong is Apache�s mod_python or
> some of its dependencies.
>
> To integrate Pygments with ViewVC I did some changes in the ViewVC�s
> code. If GNU Enscript works fine for somebody, then, my changes for
> integrate Pygments with ViewVC could work fine for somebody too. So, I
> describe my changes here for these people interested in integrating
> ViewVC and Pygments.
>
> CHANGES:
> ---------------
>
> In file <VIEWVC_HOME>/lib/viewvc.py, just after the declaration of
> �MarkupEnscript� class, I added the following class:
> ###################################################
> class MarkupPygments(MarkupShell):
> def __init__(self, cfg, fp, filename):
> pygments_cmd = [cfg.utilities.pygments or 'pygmentize',
> '-f', 'html']
>
> if cfg.options.pygments_line_numbers:
> pygments_cmd.extend(['-O', 'noclasses=1,style=colorful,linenos=1', ''])
> else:
> pygments_cmd.extend(['-O', 'noclasses=1,style=colorful', ''])
>
> MarkupShell.__init__(self, cfg, fp, [pygments_cmd])
> self.filename = filename
> self.cfg = cfg
>
> def __call__(self, ctx):
> dir = compat.mkdtemp("", "viewvc")
> try:
> file = os.path.join(dir, self.filename)
> try:
> copy_stream(self.fp, open(file, 'wb'), self.cfg)
> self.fp.close()
> self.fp = None
> self.cmds[0][-1] = file
> MarkupShell.__call__(self, ctx)
> finally:
> os.unlink(file)
> finally:
> os.rmdir(dir)
> ###################################################
>
> And, in the definition of �markup_or_annotate�, I modified the following �if� statement with the two last lines.
> ###################################################
> if not markup_fp:
> if cfg.options.use_enscript:
> markup_fp = MarkupEnscript(cfg, fp, request.path_parts[-1])
> elif cfg.options.use_highlight:
> markup_fp = MarkupHighlight(cfg, fp, request.path_parts[-1])
> elif cfg.options.use_source_highlight:
> markup_fp = MarkupSourceHighlight(cfg, fp, request.path_parts[-1])
> elif cfg.options.use_pygments:
> markup_fp = MarkupPygments(cfg, fp, request.path_parts[-1])
> ###################################################
>
> In file <VIEWVC_HOME>/viewvc.conf, in �utilities� section, I added the following:
> ###################################################
> # Pygments, a syntax highlighting program (see options.use_pygments)
> pygments =
> # pygments = /usr/bin/pigments
> ###################################################
>
> And in �options� section, I added the Pygments� options:
> ###################################################
> # should we use 'enscript' for syntax coloring?
> use_enscript = 0
>
> # should we use 'pygments' for syntax coloring?
> # NOTE: use_enscript has to be 0 or enscript will be used instead
> use_pygments = 1
>
> # should we add line numbers?
> pygments_line_numbers = 1
>
> # should we use 'highlight' for syntax coloring?
> # NOTE: use_enscript and use_pygments have to be 0
> use_highlight = 0
>
> # should we add line numbers?
> highlight_line_numbers = 1
>
> # convert tabs to ## spaces (use 0 for no conversion)
> highlight_convert_tabs = 2
>
> # should we use 'source-highlight' for syntax coloring?
> # NOTE: use_enscript, use_pygments and use_highlight have to be 0
> use_source_highlight = 0
>
> # should we add line numbers?
> source_highlight_line_numbers = 1
> ###################################################
>
> These changes work fine using the ViewVC�s standalone server. So, I
> think they could work fine for somebody, good luck. Pygments is a very
> good code hightlighter, I enclose two screenshots.
>
> Best regards,
> Sandy
>
>
> ------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
--
C. Michael Pilato <[email protected]>
CollabNet <> www.collab.net <> Distributed Development On Demand
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFINvRtokEGqRcG/W4RAvO5AJ4jzQHrQw58VCQnFC3zylYhchpwMwCeOkW+ NPsTcnf6wVQaOaOnrTyz5B0= =4kkU -----END PGP SIGNATURE-----