We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3586
    • 27 Posts
    After searching hopeless for a decent syntax highlighter to display sources in a webpage I remembered the GeSHi Project. This PHP-project helps to highlight A LOT of different languages and outputs them to HTML.

    So I began writing a snippet for it. It’s not completely finished, cause I’m not sure about several configurations, but it’s perfectly working. Have a look at this testpage.

    The snippet reads a given file and highlights it with html. Please see the comments in the snippet for parameters. You also need to have the syntax files and the geishi.php which you’ll find on the projects homepage. Put them in a directory of your choice and pass the name of the directory to the snippet. For more configuration (like css-styling) I suggest you have a look in the excellent GeSHi-documentation.

    You call the snippet like:
    [[GeSHi?&file=`source/myFile.php` &lang=`php`]]


    Cheers,
    bll0
      • 32241
      • 1,495 Posts
      Nice.

      One thing that I do notice, that GeShi class is a little bit slow, don’t you think?
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 3586
        • 27 Posts
        Not sure about how fast geshi is. I think when the files get larger, it will be slow. Tried it with geishi.php itself, that was very slow, cause the source contains about 2500 lines of code. But I think this is more because of my server wink
          • 32241
          • 1,495 Posts
          Quote from: bll0 at Mar 22, 2006, 11:19 PM

          Not sure about how fast geshi is. I think when the files get larger, it will be slow. Tried it with geishi.php itself, that was very slow, cause the source contains about 2500 lines of code. But I think this is more because of my server wink

          I don’t think so though. I tried this before when playing around with the class, and I can notice the performance hit when parsing the code, but it sure does the job. Do they support caching? I haven’t really look into the class yet, but I think caching is needed to avoid performance problem when parsing the code. Worst come to wrost, we can use built caching from MODx wink

          Cool snippet. When you’re ready to release it, feel free to drop a post in our repository thread, and I will add it to the list.

          Sincerely,
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
            • 3586
            • 27 Posts
            Quote from: Djamoer at Mar 23, 2006, 01:29 AM


            I don’t think so though. I tried this before when playing around with the class, and I can notice the performance hit when parsing the code, but it sure does the job. Do they support caching? I haven’t really look into the class yet, but I think caching is needed to avoid performance problem when parsing the code. Worst come to wrost, we can use built caching from MODx wink

            How did you notice the performance pitch? Just by looking at the page with your browser? Or is there a good method to test this. And of course, to test it with caching, too.
            By caching you think about the checkbox "Enable Caching" in the manager?
              • 32241
              • 1,495 Posts
              Quote from: bll0 at Mar 23, 2006, 02:52 PM

              How did you notice the performance pitch? Just by looking at the page with your browser? Or is there a good method to test this. And of course, to test it with caching, too.
              By caching you think about the checkbox "Enable Caching" in the manager?

              lol, I said all that just by loading the page. Actually I never do any benchmark testing yet, considering I don’t have any project that requires this type of class. I just notice the performance from the loading time.

              That’s the reason why I always use "I think, I don’t think".

              Yes, just called the snippet cached, and check that cache option on the page where the snippet reside. So basically the output will be cached by MODx, without having to parse the snippet again. But this only work if you snippet only required to view 1 code on one page. If you create the snippet to receive querstring and fetch a dynamic code everytime you change the querystring and etc, then it won’t work, because you need to call the snippet uncached smiley
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
                • 3586
                • 27 Posts
                I thought that your just saying this by looking at the page. Now I inserted a box on the page to show the time for loading the page. Though I cached the site, it is displayed in less than a second. So I don’t think it is to slow. With caching disabled (eventhough without caching the snippet by using [!...!] instead of [[...]] for calling the snipped) it is most times less or equal a second. I will try it with some bigger files though and report.

                Maybe you can have a look at http://utopia-vision.de/index.php?id=29 and tell me what times are written on the left hand side box? That would be nice!
                  • 32241
                  • 1,495 Posts
                  It’s average 0.75-0.8 seconds

                  Btw, it’s no biggie buddy. wink
                  Don’t worry too much with performance. It’s just my simple thought when seeing the loading time the first time I saw the use of this class. It’s not on your snippet though, but it’s on some other website.
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                    • 5683
                    • 96 Posts
                    Hi bll0,

                    a couple of weeks ago I was looking for a sintax highlighting plugin for MODx, but I couldn’t find any... thus I decided to write a wrapper for GeSHi.

                    Today I refined it in order to publish it on the MODx site, I searched for "geshi" again and... I found your snippet! Ahhh, the problem of synchronization in distributed computing grin

                    Anyway, I’m going to post my plugin too, because the target is slighty different: mine is a plugin, and yours is a snippet!

                    Cheers,
                    Luca
                      • 3586
                      • 27 Posts
                      Quote from: Commodore64 at Mar 27, 2006, 04:26 PM


                      a couple of weeks ago I was looking for a sintax highlighting plugin for MODx, but I couldn’t find any... thus I decided to write a wrapper for GeSHi.

                      Same for me smiley
                      But I think your plugin got a different approach than my snippet. In some way. (Well, I hope so, so that my work wasn’t completely worthless...)

                      For my snippet you define a special file where the code is located. That way you don’t have to rewrite/copy-paste the code into the editor. I think it might be better for larger sources, though the snippet just prints out the file like it is written, with tabs, identation and so on. I’m not sure how manageble large code is with your plugin.

                      But I like your plugin, because at the moment I need a seperate file for highlighting a single line which is a little bit too much... I thought about this, but didn’t know how to implement it. So here is were you come into play wink