Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Syntax highlighting

  • 15-01-2014 07:29PM
    #1
    Closed Accounts Posts: 4,339 ✭✭✭


    I have a webpage that contains an iframe. I'm opening text files into that frame and I want to highlight java code in the text. I've googled syntax highlighters and came across geshi. Thing is I dont know much about php so I'm a bit confused as to how to use it even with the instructions for basic use.

    Here's the how to bit about the highlighter.
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';
     
    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //
     
    $source = '$foo = 45;
    for ( $i = 1; $i < $foo; $i++ )
    {
      echo "$foo\n";
      --$foo;
    }';
    $language = 'php';
     
    //
    // Create a GeSHi object
    //
     
    $geshi = new GeSHi($source, $language);
     
    //
    // And echo the result!
    //
    echo $geshi->parse_code();
    

    Can anyone explain how I use that in relation to the following bit of HTML ?
    <a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>
    


Comments

  • Registered Users, Registered Users 2 Posts: 4,846 ✭✭✭cython


    I have a webpage that contains an iframe. I'm opening text files into that frame and I want to highlight java code in the text. I've googled syntax highlighters and came across geshi. Thing is I dont know much about php so I'm a bit confused as to how to use it even with the instructions for basic use.

    Here's the how to bit about the highlighter.
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';
     
    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //
     
    $source = '$foo = 45;
    for ( $i = 1; $i < $foo; $i++ )
    {
      echo "$foo\n";
      --$foo;
    }';
    $language = 'php';
     
    //
    // Create a GeSHi object
    //
     
    $geshi = new GeSHi($source, $language);
     
    //
    // And echo the result!
    //
    echo $geshi->parse_code();
    

    Can anyone explain how I use that in relation to the following bit of HTML ?
    <a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>
    


    Haven't used the library before, but at a guess you could hack your two sections together like this:
    [PHP]
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';

    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //

    // Assign your source instead of the sample given. Potentially you want to put a segment to read file contents into the $source variable as a string though, and then pass that to geshi
    $source = '<a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>';

    $language = 'html'; //Assuming this is a valid option :-)

    //
    // Create a GeSHi object
    //

    $geshi = new GeSHi($source, $language);

    //
    // And echo the result!
    //
    echo $geshi->parse_code();[/PHP]


  • Closed Accounts Posts: 4,339 ✭✭✭Artful_Badger


    cython wrote: »
    Haven't used the library before, but at a guess you could hack your two sections together like this:
    [PHP]
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';

    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //

    // Assign your source instead of the sample given. Potentially you want to put a segment to read file contents into the $source variable as a string though, and then pass that to geshi
    $source = '<a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>';

    $language = 'html'; //Assuming this is a valid option :-)

    //
    // Create a GeSHi object
    //

    $geshi = new GeSHi($source, $language);

    //
    // And echo the result!
    //
    echo $geshi->parse_code();[/PHP]

    I think you misunderstood me. I dont want to apply it to that line of html I want to apply it to the txt file that I'm sending into the frame with that line of html.

    So could I give it the file as a source and then direct the echo to the frame ? Or open a php file in the frame with that code using the file as a source ?


  • Registered Users, Registered Users 2 Posts: 4,846 ✭✭✭cython


    I think you misunderstood me. I dont want to apply it to that line of html I want to apply it to the txt file that I'm sending into the frame with that line of html.

    So could I give it the file as a source and then direct the echo to the frame ? Or open a php file in the frame with that code using the file as a source ?

    Ah, I get you now, apologies for the mix up! I think half of your post just went straight out of my head as I read it :o

    Anyway, since you're going the route of an iframe, I would suggest potentially having a php script that can read a file whose name is passed, and simply echo that it out that as an appropriately highlighted string. You can then use this as the source/content of the iframe, and trigger changes in that as required, if you get me? Of course make sure that the file handling doesn't expose anything that it shouldn't too :)


Advertisement