Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Thanked 0 Times in 0 Posts

    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:

    <pre class="prettyprint">
    <!-- -------------------- Code Start -------------------->
    int main()
    return 0;
    <!-- -------------------- Code End -------------------->

    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.


  2. #2
    Administrator VIPStephan's Avatar
    Join Date
    Jan 2006
    Halle (Saale), Germany
    Thanked 1,300 Times in 1,270 Posts
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts