Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.2k views
in Plugins by
edited by

I need help with creating Syntax Highlight Plugin. I created the plugin containing one module of viewer type. But I noticed, that qa-viewer-basic.php takes precedence over my plugin. I don't want to change the content format, because it is still html. I would rather make a class that extends the qa-viewer-basic. Could you please give me some clarification on that?

EDIT:

I've finally decided to use new custom format "codehtml" to force my plugin to work. But now  I have another problem. In wysiwyg editor plugin you use $qa_content['script_src'] to include some js code within the header. I'm trying to do the same in my viewer module, but it simply doesn't work. Here's the code:

        function get_html($content, $format, $options)
        {
            if ($format=='codehtml' || $format=='html') {
                $qa_content['script_src'][]='./qa-plugin/syntax-highlighter/js/scripts/shCore.js';
                $html=$content;

What's wrong? Is there another way to include some javascript in header using plugins?

1 Answer

0 votes
by

Hi there - great that you're working on this.

First, if you want to go back to the original method, i.e. using the 'html' format in the database, you can make your viewer take precedence over qa_viewer_basic by returning a value greater than 1.0 from the calc_quality(...) function in your viewer's class. Of course you should only do this if the $format parameter you're supplied is 'html'.

Second, the get_html(...) function in a viewer class can't access the global $qa_content variable, since it's not passed a reference to it. Instead, you can embed the Javascript load inside a <SCRIPT...> tag within the HTML that is returned by your function. Also, when buliding the URL for this Javascript file, you should start from the relative URL that was passed to your module's load_module(...) function to ensure it works on all pages. And finally, make sure you only enter your Javascript tag once per Q2A page, since your viewer could be called multiple times for multiple answers. A PHP global variable can solve this for you.

Hope this helps - feel free to ask any more questions about this.

by
Hi Ernest - sorry for the delay - I just saw your comment. Would you like to put your plugin code online somewhere so I can link to it from the Q2A site?
by
Hi Gidgreen, of course, it is available for download at http://quanda.pl/index.php?qa=download
and this is a direct link to zip file: http://quanda.pl/download/syntax-highlighter.zip
by
Thanks - I've added the link to the page since the explanation is helpful: http://www.question2answer.org/install.php#addons
by
Roger that :) Thanks
...