|
Posted by Andy Hassall on 10/12/06 21:17
On 12 Oct 2006 13:35:18 -0700, "rockstar_" <rockstar.dev@gmail.com> wrote:
> I'm developing a Content Management software for my own site, and
>possibly package and deploy to other sites (for friends, family, etc.)
>The content management software is combined blog, photo, and site
>management tools. One the of the tools I would find INREDIBLY helpful
>is the ability to block out and syntax highlight code. I would like to
>be able to, as I'm writing a blog post about something I've done in
>Python (for example), just stop and type something like:
>
><python>
>def foo():
> bar()
>
>foo()
>
></python>
>
> Do you get the idea? The only code I've been writing recently is
>PHP, Python, and C++, so I could start with the regex for those
>languages first and then expand. The blocks of code would then add
>some style info (like making the font a fixed size font, etc....) and
>then would highlight certain terms (a regex nightmare).
>
> I've talked this over with another PHP dev, and he suggested I use
>the xml_parser_create function to generate a parser object, and then
>the xml parsing functions to find these tidbits of code. This sounds
>like a great idea to me. However, does anyone have suggestions on a
>better way to do this, or an efficient way to do the syntax
>highlighting?
What happens when what's inside the tags isn't valid XML?
> I'm assuming for syntax highlighting, I'd have to do a massive
>preg_replace with the regex, and then add in the HTML for items I
>wanted to highlight. I don't mind doing this, but I was also wondering
>if someone had a great resource for syntax highlighting regex that
>someone else may have created that I could use, and possibly modify.
As for syntax highlighting, I use GeSHi - it's not the fastest, but it has a
very wide range of supported language without having to write it all again.
http://qbnz.com/highlighter/ (GPL license)
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
[Back to original message]
|