/    Sign up×
Community /Pin to ProfileBookmark

Highlighting question

Hello everyone. I am building a website and I want be able to add snippets of code transparently, so I have built a php+javascript system, that parses some text and highlights it. But what concerns me is that the code is kind of dumb, so, if I have many snippets of code on my page, it ends up by using a lot of the processor, and the page delays to load. So I decided, that instead of parsing the code at runtime, I would take each and every snippet and parse it separately and only add the static source to the page. But this doesn’t seem very elegant. So, I was wondering if you know of any good highlighting tutorials using javascript and php. Or maybe you know a better solution.. pls help

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsSep 11.2006 — need exaples of 'some text '
Copy linkTweet thisAlerts:
@nc3bauthorSep 11.2006 — need exaples of 'some text '[/QUOTE]

#include "iostream"

using namespace std;

int main()

{

[INDENT]

cout<<"blabla";

int a,b,c;

return(0);

[/INDENT]

}

And, obviously, I want the keywords to be highlighted. My current system does that just fine, but I am looking for something more resource-freindly.
Copy linkTweet thisAlerts:
@vwphillipsSep 11.2006 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function tmWords(tmN,tmwrd,tmcol){
var tmnu=tmN.childNodes.length;
for(var tm0=0;tm0<tmnu;tm0++) {
var tmTxt=tmN.firstChild.data;
var tm=tmN.removeChild(tmN.firstChild);
if(tm.nodeType==3){
tmTxt=tmTxt.replace(tmwrd,'$£$£$');
tmAry=tmTxt.split(' ');
for(var tm1=0;tm1<tmAry.length; tm1++) {
var tmT=document.createElement('SPAN');
if(tmAry[tm1]=='$£$£$'){ tmAry[tm1]=tmwrd; tmT.style.backgroundColor=tmcol; }
tmT.ref='#';
var tmTTxt=document.createTextNode(tmAry[tm1]+' ');
tmT.appendChild(tmTTxt);
tmN.appendChild(tmT);
}
}
else {
tmWords(tm,tmwrd,tmcol);
tmN.appendChild(tm);
}
}
}

//-->
</script></head>

<body onload="tmWords(document.getElementsByTagName('BODY')[0],'word','blue');tmWords(document.getElementById('Tst'),'test','red');">
word som test 1<br>
word som test 2<br>
<div id="Tst" >
word som test 3</div>
word som test 4<br>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@nc3bauthorSep 13.2006 — Thank you. ?
×

Success!

Help @nc3b spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...