Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2013, 02:44 PM   PM User | #1
bhayanisunny
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bhayanisunny is an unknown quantity at this point
Reading C-Code contents from a file & displaying it in HTML page by syntax highlight

Hi All,

I am new to HTML coding.

I am creating a offline - local website to organize my c-codes.

I am trying to do the following things:

1. Read contents of a file (c-code in my case, where the file extension is *.c or *.txt).
2. Before displaying the read contents of the c-code, do the syntax highlighting.


Now, I am able to do syntax highlighting by a javascript from Google, i.e. prettify.js.

You just need to call it in your <pre> </pre> tags like below and you get your c-code syntax highlighted:



[CODE]
<pre class="prettyprint">
<!-- -------------------- Code Start -------------------->
int main()
{
return 0;
}
<!-- -------------------- Code End -------------------->
</pre>
[CODE]


But, there are 2 disadvantages of doing this.

Firstly, you need to manually copy the c-code in the "Code Start" and "Code End".

The other problem in doing above is that, lot of codes are there, and there might be modifications in the *.c or *.txt files present on the local disk. So you need to manually do the changing of the code in your html file as well.

Can anybody give any other way which I can try.

I have tried several things, but I am not able to achieve this.

Your help will really be appreciated.


Thanks,
Sunny
bhayanisunny is offline   Reply With Quote
Old 02-16-2013, 08:26 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
HTML can’t retreive contents of files, you need some kind of server and a program in an appropriate programming language (PHP is the most popular). If this is solely a local environment where you have full control over the browser features you might also be able to retreive file contents with JavaScript (AJAX) but it depends on the browser whether you can do that from with local file system paths or still need a server.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:13 PM.


Advertisement
Log in to turn off these ads.