473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Syntax Highlighting using XML and regex

Hello all-

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?

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.

Licensing for this software would be the GPL, so obviously everything
else should be GPL. I thought I'd bounce the idea against some other
PHP developers, and see what they thought of it.

Thanks in advance
rockstar_

Oct 12 '06 #1
2 2590
rockstar_ 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.
Does highlight_file() / highlite_string() suit your purposes? (See PHP
manual for more info).

C.
Oct 12 '06 #2
On 12 Oct 2006 13:35:18 -0700, "rockstar_" <ro**********@gmail.comwrote:
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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jay Davis | last post by:
I use xemacs and syntax highlighting for my IDE, but I'm not a big fan of the default syntax highlighting colors. For instance, in 'def fun():' both 'def' and 'fun' are the same color. I kind of...
9
by: news.microsoft.com | last post by:
Dear all, I have to do a source code editor to implement syntax hilighted with special colors , IntelliSense function. Could anybody give me some tips or links? Thanks,
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
4
by: Patrick Porter | last post by:
Arrrgh! I have tried everything (ok, not EVERYTHING) but i cant get solve the problem of getting syntax highlighting in a rich textbox. in the code below, im attempting to highlight all of the...
3
by: Patrick Porter | last post by:
I am looking at followin the suggestion made by Larry on my last post. (his reply is on the bottom) it seems that you can't directly mess with the rich text header text....specifically the addtion...
4
by: frikker | last post by:
Hello, I have an idea for a project which involves an editor that supports syntax highlighting. This would be for any language, particularly php, html, css, etc. I would like to write this...
11
by: Christoph Burschka | last post by:
Are there any free PHP libraries/utility functions that can color the syntax of various programming languages (eg. Java and C++)? I am posting code snippets on my site and would like to know if...
0
by: Scott | last post by:
Hi, I think I may have finally found a IDE/text editor that I like, but, it still haves one problem. Geany haves syntax highlighting, but it is not very good for Python. It only seems to have...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.