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

 

I planning to create plugin for Q2A for markitup editor, becouse default (ckeditor) is really annoyng with is output messy code and lots of unnesesary features.

A don't have lot experience, i know i need to use editor module but for me it's still dificult to understand.

Maybe someone is already done editor in Q2A and can say how can i implement editor into q2a plugin. Or maybe it's easier to edit ckeditor to work with markitup ?

Thanks for any help with markitup editor.

related to an answer for: WYSIWYG editor for comments too!
by
bravo ! .. upvote for this effort.. which could be more stable than ckEditor due to  JQuery foundation. fingers crossed   

. although I like many ckEditor features,  even the users on S.O. have trouble it seems..  

   http://stackoverflow.com/questions/1794219/ckeditor-instance-already-exists

I spent a day studying the cke API and just touched the surface.  it's a monster :)

2 Answers

+1 vote
by
 
Best answer

You need to download the MarkItUp editor end put it inside a folder, with a name like markitup, and put it inside your plugin folder. Also download jquery and download it into your markitup plugin folder, and then rename the file to jquery.js

I'm not sure if this step is still need, because I think I read somewhere that Q2A already uses jQuery, so it isn't needed do include the file again.

Then create the qa-plugin.php:

if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
    header('Location: ../../');
    exit;
}

qa_register_plugin_module('editor','qa-bbcode-markitup.php','qa_bbcode_markitup','BBCode Markitup');

After that, create a file named qa-bbcode-markitup.php:

<?php
class qa_bbcode_markitup {
    var $page2plugin;
    var $pdirectory;

    function load_module($pdirectory, $page2plugin) {
        $this->pdirectory = $pdirectory;
        $this->page2plugin = $page2plugin;
    }

    function calc_quality($content, $format) {
        if($format == 'bbcode') return 1.0;
        elseif($format == 'html') return 0.0;
        elseif($format == '') return 0.8;
        else return 0;
    }

        function get_field(&$qa_content, $content, $format, $fieldname, $rows, $autofocus) {
        if ($autofocus)
            $qa_content['focusid'] = $fieldname;

        $textfield = '
<script type="text/javascript" src="'.$this->page2plugin.'jquery.js"></script>
<script type="text/javascript" src="'.$this->page2plugin.'markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="'.$this->page2plugin.'markitup/sets/bbcode/set.js"></script>
<link rel="stylesheet" type="text/css" href="'.$this->page2plugin.'markitup/skins/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="'.$this->page2plugin.'markitup/sets/default/style.css" />

<script language="javascript">
$(document).ready(function()    {
    $(\'.markItUp\').markItUp(mySettings);
});
</script>
    
<textarea class="markItUp" name="'.$fieldname.'" id="'.$fieldname.'" cols="80" rows="'.$rows.'">'.$content.'</textarea>';    

        return array(
            'type' => 'custom',
            'html' => $textfield,
        );
    }

    function read_post($fieldname) {
        $text = qa_post_text($fieldname);
        return array(
            'format' => 'bbcode',
            'content' => $text);
    }
}

 

by
thanks but this doesnt work for me. Just blank editor :/
by
Are you sure? Check the paths. It's stange, because for me it works.
by
Paths are ok, but directory that shown in code "/sets/bbcode/set.js" doesn't exists ("bbcode" directory) in markitup.
by
What doesn't work now?
by
Same, just blank box.
by
It's ok now. Thanks ! :)
by
Oh no... "Fatal error: Call to a member function get_text() on a non-object in /xxxx/xxxx/xxxx/xxxx/public_html/qa-include/qa-app-format.php on line 1334" after posting something.
by
Q2A 1.4 beta 1 includes jQuery on every page, so you don't need to include that as part of this editor.
by
@Another one Sent PM to you.
by
similar error on qa-app-format.php
Could you release it as a plugin scorch?
Thanks
by
Unfortunately I can't because the plugin isn't mine, and Another One was just an exception. I don't think the plugin onwer will open more exceptios. Sorry.

Btw, what you have to do is create a viewer module to render BBCode. You can find a good and simple free parser here:
http://nbbc.sourceforge.net/
And info about viewer module:
http://www.question2answer.org/modules.php#viewer
+2 votes
by
I have a Markdown editor plugin that I'm happy to share. It uses the WMD editor as provided by Stack Overflow (with a few bug fixes in place) and Showdown for the live preview.

I'm currently working on setting up a blog so I can post stuff like this, I'll keep you posted.
by
Thanks ;D. I will patiently waiting =)
by
I just registered on your pokemondb.net website to see how the markdown editor works. It seems it works fine :). I need markdown since my site using latex a lot to write math symbols. The showdown helps to have a live preview of the messy latex.
by
Any chance that it is available for download now DisgruntledGoat?
by
edited by
...