![]() |
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 |
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.
|
| All times are GMT +1. The time now is 03:24 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.