Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
975 views
in Q2A Core by
Some users do like this:

 

 

 

 

 

 

 

 

 

and then write something.

 

I would like to filter line-breaks and reduce such spaces.

In HTML it is:

<p>&nbsp;</p>
<p>&nbsp;</p>
 ...

I can find these posts with mysql like that:

SELECT *  FROM `qa_posts` WHERE `content` LIKE '%<p>&nbsp;</p>\n<p>&nbsp;</p>%'

However, is there a way to filter posts when posted?

How would you do it?

 

PS: All <p>&nbsp;</p> <p>&nbsp;</p> in a row should become one: <p>&nbsp;</p>
Q2A version: 1.5.4
by
I have same trouble too. It may be tuning problem or bug of CKeditor...? If we read pages of this neighborhood carefully, can we solve this?
https://www.google.co.jp/search?q=ckeditor+%3Cp%3E%26nbsp%3B%3C%2Fp%3E&oq=ckeditor+%3Cp%3E%26nbsp%3B%3C%2Fp%3E&aqs=chrome.0.57j0l3.2678j0&sourceid=chrome&ie=UTF-8
by
"ignoreEmptyParagraph = true" option ?
by
Tried the config option "ignoreEmptyParagraph". No effect visible.

I think it has to be done serverside in PHP. Scott once described how this can be done with a filter plugin: http://www.question2answer.org/qa/19331/how-to-disallow-posts-of-links-to-external-images?show=19350#a19350

By the way, same "paragraph" / "line break" problem appears with that HTML: &nbsp;<br />
<br />
&nbsp;<br />

1 Answer

0 votes
by
edited by

Found the according regex to filter the content string:

$Content preg_replace('~\s?<p>(\s|&nbsp;)+</p>\s?~'''$Content); 

source

Only question where to implement it the best possible...

--- Edit: Did it with a filter plugin:

Setting up a filter plugin works:

1. File qa-plugin.php:
    qa_register_plugin_module('filter', 'qa-filter-empty-paragraphs.php', 'qa_filter_empty_paragraphs', 'Filter Empty Paragraphs');

2. File qa-filter-empty-paragraphs.php
    class qa_filter_empty_paragraphs {

        var $directory;
        function load_module($directory, $urltoroot)
        {
            $this->directory=$directory;
        }

        function filter_question(&$question, &$errors, $oldquestion) {}

        function filter_answer(&$answer, &$errors, $question, $oldanswer) {
            // replace empty p tags causing unnecessary line breaks, such as <p>&nbsp;</p>
            $answer['content'] = preg_replace('~\s?<p>(\s|&nbsp;)+</p>\s?~', '', $answer['content']);
        }

        function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment){}
    }

=)

...