How to remove the paragraph tags around Pulse Tags in Redactor

Is there any solution that redactor did not add p tags around pulse tags?

e. g. if there is a div, redactor notices this and omits the p tags.
At pulse tags redactor probably believes that it is normal text.

By default Redactor creates paragraph on the enter key pressed. You can change it:

$R('#content', {
        markup: 'div'
});

As for around Pulse Tags - this is something that will need adding. In the meantime, surround any custom tags in Divs

Hi Oliver,
I put together a Redactor 10 (Pulse 4) plug-in a while ago that filters the user input and automatically strips <p> tags from around Pulse plug-in content. You can find the download link at the foot of this post.

You should see this sort of code;
<p>{{pulseplugin}}</p>

getting automatically changed to;
{{pulseplugin}}

To install it you'll need to

  • add the plugin file to admin/js/redactor,
  • include the plugin in the head of your main Pulse index.php file (<script src="<?php echo $path.'/'.$admin; ?>/js/redactor/addpulseplugin.js"></script>),
  • update the redactor/options.js file to tell Redactor to load the plugin (plugins: ['image manager','table','fullscreen','addpulseplugin'])

I hope it helps.

(As a sidenote it would be good to see Pulse automatically load any plug-ins that are present in the admin/js/redactor directory without having to load them manually.)

2 Likes

hi @TimPlumb

not working {{pulseplugin}}, does not work plugin ?

What do you see when you click on the Redactor source code view? Does the plugin alter the source code in any way?

When I wrote the code I noticed that Redactor would either wrap the short code directly in paragraph tags;
<p>{{pulseplugin}}</p>,
or add in a line break and/or <br>. So something like;
<p>{{pulseplugin}}
</p>
or
<p>{{pulseplugin}}<br>
</p>

If you open up the addpulseplugin.js file it may be worth changing the filter code to;

filter: function(html) { //try and match plugin content wrapped directly in <p> tags var newHTML = html; var plugintag = /(<p>)({{[^}]+}})(\\r)?(<br>)?(<\/p>)/gi; console.log(newHTML.match(plugintag)); newHTML = newHTML.replace(plugintag,"$2"); return newHTML; }
where the regular expression specifically looks for an optional return character and <br>. I also added in a console log so you can see what the regex is matching without having to constantly switch to Redactor’s code view.

2 Likes

Hi Tim,
thanks for your solution. I tried, but unfortunately it doesn't work for me. I also did not get any console log but I would say the plugin is loaded.

What I did:

I have put your plugin to /admin/redactor/plugins/
Added the Plugin inside the /admin/redactor/redactor_init.js
and inserted the following line of code inside the admin/index.php (also tried it in the root index.php)

\pulsecore\get_context()->theme->js_body->add( "{$path}/{$admin}/redactor/plugins/addpulseplugin.js", array( 'redactor' ) );

Hello Oliver.
This script is for Redactor 1.
Plugins for Redactor1 do not work in Redactor 2.
Plugin for Redactor 2, has another script header.
Try editing the script header.
I did not try it, I did not install Pulse.

`if (!RedactorPlugins) var RedactorPlugins = {};

(function($)
{
RedactorPlugins.addpulseplugin = function()
{
return {
init: function() {`

	-------Redactor 2 ------------

(function($) { $.Redactor.prototype.addpulseplugin = function() { return { init: function() {

1 Like

This topic was automatically closed after 5 days. New replies are no longer allowed.

From Imperavi:

“At the moment, Redactor does not support Pulse’s tags without wrapping to p or div. But we are working on it and not only for pulse tags, but in general to support the insertion of template variables.”

1 Like