Bringing Pharo's syntax highlighting to the web
I'd like to know whether there's a way to get Pharo's syntax highlighting in a web app coded in Iliad.
Actually, the framework shouldn't matter, as what I'd need is a plain HTML string of the sort:
<span style="color: rgb(102, 0, 0);">开发者_开发技巧^</span> Set <span
style="color: rgb(0, 0, 153);">withAll:</span> <span
style="color: rgb(102, 0, 0);">self</span>
I'm guessing this is not going to be trivial at all... :)
Pier supports syntax highlighting. An example can be found here: http://book.seaside.st/. This is implemented in the package Pier-Shout (see Lukas Renggli's SqueakSource repository).
We wrote a small, but rather complete syntax highlighter in Pharo for Seaside. It takes a method, parses it and outputs annotated html. You only have to specify some rules in css to change the color of the different AST nodes (selectors, strings, symbols, numbers, keywords, variables).
You will find a complete example in the WebDoc project on squeaksource. Look for the SourceFormatter
class, everything you need is there.
There is also a smalltalk lexer for pygments which has a bit more penetration than the smalltalk based alternatives.
精彩评论