Re[2]: [viewvc-dev] GNU Enscript and ViewVC 1.1...or Pygments
Sandy Pérez González <[email protected]>
| Newsgroups | gmane.comp.version-control.cvs.viewcvs.devel |
|---|---|
| Organization | Onekin |
| Message-ID | <242090543.20080523222556__9152.92284121296$1211575285$gmane$org@gmail.com> |
Dear,
> 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?
Yes, pygments is usable as a command-line tool and as a library. But,
I used the command-line tool because I am not a python developer.
Indeed, this is the first thing I wrote using python. Really, process
was easy: copy&paste and make some little modifications to the
existing code :-)
> 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.
I have been looking for a tool in order to replace GNU Enscript.
Finally, I chose Pygments because it seems a very complete library
with support for a wide range of common languages and markup formats.
Some of them very useful for me like LaTeX. Another feature to take
into account is that Pygments is licensed under the BSD license. But,
sincerely, I did not find any other library for code hightlighting
based on python :-)
Another solution I was seeing was Google Syntax Highlighter
(http://code.google.com/p/syntaxhighlighter/), which is based on
JavaScript and licensed under the GNU Lesser General Public License. I
do not know if it is totally cross-browser or not. But, as far as I
know, it supports fewer languages than Pygments. I hope to be useful :-)
Best Regards,
Sandy
> 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]