StructuredTextExampleSyntaxHilight
It would be really useful if Zope would syntax-hilight to the best of its ability code that I include in my structured text documents.
There are plenty of syntax-hilighting programs out there, and there's probably alogrythms built into the open-source text editor that you're using. Here's an example of how this might work. Instead of this:
def doc_xref(self, s, expr = re.compile('\[([%s0-9\-.:/;,\n\r\~]+)\]' % letters).search ): r = expr(s) if r: start, end = r.span(1) return (StructuredTextXref(s[start:end]), start-1, end+1) else: return None
You would, instead, see this:
def doc_xref(self, s, expr = re.compile('\[([%s0-9\-.:/;,\n\r\~]+)\]' % letters).search ): r = expr(s) if r: start, end = r.span(1) return (StructuredTextXref(s[start:end]), start-1, end+1) else: return None
Pretty, no? This Syntax Hilight style comes directly from that used on cvs.zope.org
by viewcvs.cgi 0.7
.
Optimally, I'd like to add some sort of intelligence which would allow STX to determine what language it was hilighting automatically, possibly borrowing from the *nix file
command as well as the alogrythms embedded in most modern syntax-hilighting open-source text editors. Barring that, perhaps we could come up with some sort of machine-readable (yet not markup-like) identifier. Maybe Language: Python
on the first line of the example
paragraph?
Comments very welcome :)
- datagrok (Nov 2, 2001 10:24 am; Comment #1)
- I think the proper way to implement this would be to use a bunch of <span> tags within the preformatted text, then use CSS to handle the colorization. That way, the user is able to build a CSS stylesheet that colors, bolds, applies formatting based on the type of element it's working on.
Here's a quick example. View source to check it out:
def doc_xref(self, s, expr = re.compile('\[([%s0-9\-.:/;,\n\r\~]+)\]' % letters).search ): r = expr(s) if r: start, end = r.span(1) # How bout a comment? return (StructuredTextXref(s[start:end]), start-1, end+1) # And Another else: return None
Cool, eh? My favorite bit is the cool stuff that you can do with the comments, blocking them off to the right, away from the code, in a proportional font, with borders... sweet!