Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript bbcode编辑器验证插件_Javascript_Jquery_Ajax_Ckeditor_Bbcode - Fatal编程技术网

Javascript bbcode编辑器验证插件

Javascript bbcode编辑器验证插件,javascript,jquery,ajax,ckeditor,bbcode,Javascript,Jquery,Ajax,Ckeditor,Bbcode,我安装了ckeditor,在安装代码(bbcode插件)后: 我安装了该代码(justify plugin): 在我安装插件后,所有的插件都可以工作,但当我在justify插件中点击中间、右边或左边时,bbcode插件不支持justify mod 有谁能帮我在bbcode插件中构建一个简单的代码来支持justify mod吗 它的论坛,我只需要bbcode 我需要这样的代码: 如果text此处 将其替换为[center]text此处[/center] 或者类似的 谢谢你的帮助 我尝试以下代码

我安装了ckeditor,在安装代码(bbcode插件)后:

我安装了该代码(justify plugin):

在我安装插件后,所有的插件都可以工作,但当我在justify插件中点击中间、右边或左边时,bbcode插件不支持justify mod

有谁能帮我在bbcode插件中构建一个简单的代码来支持justify mod吗

它的论坛,我只需要bbcode

我需要这样的代码:

如果
text此处

将其替换为
[center]text此处[/center]

或者类似的

谢谢你的帮助

我尝试以下代码:

(function() {
  CKEDITOR.plugins.add('bbcode',
  {
    requires: ['htmlwriter'],
    init: function(editor) {
      editor.dataProcessor = new CKEDITOR.htmlDataProcessor(editor);
      editor.dataProcessor.toHtml = toHtml;
      editor.dataProcessor.toDataFormat = toDataFormat;
    }
  });

  var toHtml = function(data, fixForBody) {
    // Convert < and > to their HTML entities.
    data = data.replace(/</g, '&lt;');
    data = data.replace(/>/g, '&gt;');

    // Convert line breaks to <br>.
    data = data.replace(/(?:\r\n|\n|\r)/g, '<br>');

    // [url]
    data = data.replace(/\[url\](.+?)\[\/url]/gi, '<a href="$1">$1</a>');
    data = data.replace(/\[url\=([^\]]+)](.+?)\[\/url]/gi, '<a href="$1">$2</a>');


    // [b]
    data = data.replace(/\[b\](.*?)\[\/b]/gi, '<b>$1</b>');

    // [i]
    data = data.replace(/\[i\](.*?)\[\/i]/gi, '<i>$1</i>');

    // [u]
    data = data.replace(/\[u\](.*?)\[\/u]/gi, '<u>$1</u>');

    // [h3]
    data = data.replace(/\[h3\](.*?)\[\/h3](?:<br ?\/?>|\n)?/gi, '<h3>$1</h3>');

    // [img]
    data = data.replace(/\[img\](.*?)\[\/img\]/gi,'<img src="$1" />');
    data = data.replace(/\[img class=([\w-]+)\](.*?)\[\/img\]/gi,'<img class="$1" src="$2" />');

    // [quote]
    data = data.replace(/\[quote\]/gi, '<blockquote>');
    data = data.replace(/\[\/quote]/gi, '</blockquote>');

    // [poster]
    data = data.replace(/\[poster\](.+?)\[\/poster]/gi, '<div class="text-poster">$1</div>');

    // [code]
    data = data.replace(/\[code\]/gi,'<code>');
    data = data.replace(/\[\/code\]/gi,'</code>');

    // [size]
    data = data.replace(/\[size=(\d+)\](.*?)\[\/size\]/gi,'<span style="font-size: $1px">$2</span>');

    // [color]
    data = data.replace(/\[color=(.*?)\](.*?)\[\/color\]/gi,'<span style="color: $1">$2</span>');

    // [center] 
    data = data.replace(/\[align=(.*?)\](.*?)\[\/align\]/gi,'<span style="align: center">$2</span>');

    // [right] 
    data = data.replace(/\[align=(.*?)\](.*?)\[\/align\]/gi,'<span style="align: right">$2</span>');

    // [left] 
    data = data.replace(/\[align=(.*?)\](.*?)\[\/align\]/gi,'<span style="align: left">$2</span>');


    // smileys
    for (var i = 0; i < this.editor.config.smiley_images.length; i++) {
      var smiley = this.editor.config.smiley_images[i].replace('.gif', '');
      if (data.indexOf(smiley) != -1) {
        data = data.split(smiley).join('<img src="'+ this.editor.config.smiley_path + this.editor.config.smiley_images[i] + '" class="smiley" />');
      }
    }

    return data;
  };
  var toDataFormat = function(html, fixForBody ) {
    if (html == '<br>' || html == '<p><br></p>') {
      return "";
    }
    // Convert <br> to line breaks.
    html = html.replace(/<br><\/p>/gi,"\n");
    html = html.replace(/<br(?=[ \/>]).*?>/gi, '\r\n');
    html = html.replace(/<p>/gi,"");
    html = html.replace(/<\/p>/gi,"\n");
    html = html.replace(/&nbsp;/gi," ");

    // [url]
    html = html.replace(/<a .*?href=(["'])(.+?)\1.*?>(.+?)<\/a>/gi, '[url=$2]$3[/url]');

    // [b]
    html = html.replace(/<(?:b|strong)>/gi, '[b]');
    html = html.replace(/<\/(?:b|strong)>/gi, '[/b]');

    // [i]
    html = html.replace(/<(?:i|em)>/gi, '[i]');
    html = html.replace(/<\/(?:i|em)>/gi, '[/i]');

    // [u]
    html = html.replace(/<u>/gi, '[u]');
    html = html.replace(/<\/u>/gi, '[/u]');

    // [h3]
    html = html.replace(/<h3>/gi, '[h3]');
    html = html.replace(/<\/h3>/gi, '[/h3]\n');

    // smileys
    html = html.replace(/<img .*?src=(["']).+?(:.+?:?|(\W)_\3).gif\1.*?>/gi, '$2');

    // [img]
    html = html.replace(/<img .*?class=(["'])([\w-]+)\1.*?src=(["'])(.+?)\3.*?>/gi, '[img class=$2]$4[/img]');
    html = html.replace(/<img .*?src=(["'])(.+?)\1.*?class=(["'])([\w-]+)\3.*?>/gi, '[img class=$4]$2[/img]');
    html = html.replace(/<img .*?src=(["'])(.+?)\1.*?>/gi, '[img]$2[/img]');

    // [quote]
    html = html.replace(/<blockquote>/gi, '[quote]');
    html = html.replace(/\n*<\/blockquote>/gi, '[/quote]');

    // [poster]
    html = html.replace(/<div class="text-poster">([\s\S]+?)<\/div>/gi, '[poster]$1[/poster]');

    // [code]
    html = html.replace(/<code>/gi, '[code]');
    html = html.replace(/<\/code>/gi, '[/code]');

    // [color]
    html = html.replace(/<span style="color: ?(.*?);?">(.*?)<\/span>/gi,"[color=$1]$2[/color]");

    // [size]
    html = html.replace(/<span style="font-size: ?(\d+)px;?">(.*?)<\/span>/gi,"[size=$1]$2[/size]");

    // Remove remaining tags.
    html = html.replace(/<[^>]+>/g, '');

    // Restore < and >
    html = html.replace(/&lt;/g, '<');
    html = html.replace(/&gt;/g, '>');

    // Restore (and )
    html = html.replace(/%28/g, '(');
    html = html.replace(/%29/g, ')');

    // Restore %20
    html = html.replace(/%20/g, ' ');

    return html;
  }
})();
但是这个代码不起作用


我认为这是ckeditor 3或其他东西的代码。

我今天遇到了同样的问题,我通过修改bbcode plugin文件夹中的plugin.js成功地使其工作

第29行:

var bbcodeMap = { b: 'strong', u: 'u', i: 'em', color: 'span', size: 'span', quote: 'blockquote', code: 'code', url: 'a', email: 'span', img: 'span', '*': 'li', list: 'ol',center:'div',left:'div',right:'div'},
和151-160附近的线路:

// as "span" with an attribute marker.
if ( part == 'email' || part == 'img' )
attribs[ 'bbcode' ] = part;

//adding this to deal with the align issues
if (part == 'center' || part == 'left' || part == 'right'){
styles ['text-align'] = part;
attribs.style = serializeStyleText( styles );
}

this.onTagOpen( tagName, attribs, CKEDITOR.dtd.$empty[ tagName ] );
最后一行从658开始:

if ( tagName in convertMap )
    tagName = convertMap[ tagName ];
//adding div element
else if (tagName == 'div'){
    if ( ( value = style['text-align'] ) ) {
        tagName = value;
        value = '';
    }
}
else if ( tagName == 'span' ) {
if ( ( value = style.color ) ) {
    tagName = 'color';
    value = CKEDITOR.tools.convertRgbToHex( value );
....
至少这对我有用


这有点奇怪,因为Justify插件添加了'div'元素而不是'span'。也许你也可以修改它来满足你的“span”要求。

我今天遇到了同样的问题,我通过修改bbcode plugin文件夹中的plugin.js使它工作

第29行:

var bbcodeMap = { b: 'strong', u: 'u', i: 'em', color: 'span', size: 'span', quote: 'blockquote', code: 'code', url: 'a', email: 'span', img: 'span', '*': 'li', list: 'ol',center:'div',left:'div',right:'div'},
和151-160附近的线路:

// as "span" with an attribute marker.
if ( part == 'email' || part == 'img' )
attribs[ 'bbcode' ] = part;

//adding this to deal with the align issues
if (part == 'center' || part == 'left' || part == 'right'){
styles ['text-align'] = part;
attribs.style = serializeStyleText( styles );
}

this.onTagOpen( tagName, attribs, CKEDITOR.dtd.$empty[ tagName ] );
最后一行从658开始:

if ( tagName in convertMap )
    tagName = convertMap[ tagName ];
//adding div element
else if (tagName == 'div'){
    if ( ( value = style['text-align'] ) ) {
        tagName = value;
        value = '';
    }
}
else if ( tagName == 'span' ) {
if ( ( value = style.color ) ) {
    tagName = 'color';
    value = CKEDITOR.tools.convertRgbToHex( value );
....
至少这对我有用


这有点奇怪,因为Justify插件添加了'div'元素而不是'span'。也许你也可以修改它来满足你的“span”要求。

我今天遇到了同样的问题,我通过修改bbcode plugin文件夹中的plugin.js使它工作

第29行:

var bbcodeMap = { b: 'strong', u: 'u', i: 'em', color: 'span', size: 'span', quote: 'blockquote', code: 'code', url: 'a', email: 'span', img: 'span', '*': 'li', list: 'ol',center:'div',left:'div',right:'div'},
和151-160附近的线路:

// as "span" with an attribute marker.
if ( part == 'email' || part == 'img' )
attribs[ 'bbcode' ] = part;

//adding this to deal with the align issues
if (part == 'center' || part == 'left' || part == 'right'){
styles ['text-align'] = part;
attribs.style = serializeStyleText( styles );
}

this.onTagOpen( tagName, attribs, CKEDITOR.dtd.$empty[ tagName ] );
最后一行从658开始:

if ( tagName in convertMap )
    tagName = convertMap[ tagName ];
//adding div element
else if (tagName == 'div'){
    if ( ( value = style['text-align'] ) ) {
        tagName = value;
        value = '';
    }
}
else if ( tagName == 'span' ) {
if ( ( value = style.color ) ) {
    tagName = 'color';
    value = CKEDITOR.tools.convertRgbToHex( value );
....
至少这对我有用


这有点奇怪,因为Justify插件添加了'div'元素而不是'span'。也许你也可以修改它来满足你的“span”要求。

我今天遇到了同样的问题,我通过修改bbcode plugin文件夹中的plugin.js使它工作

第29行:

var bbcodeMap = { b: 'strong', u: 'u', i: 'em', color: 'span', size: 'span', quote: 'blockquote', code: 'code', url: 'a', email: 'span', img: 'span', '*': 'li', list: 'ol',center:'div',left:'div',right:'div'},
和151-160附近的线路:

// as "span" with an attribute marker.
if ( part == 'email' || part == 'img' )
attribs[ 'bbcode' ] = part;

//adding this to deal with the align issues
if (part == 'center' || part == 'left' || part == 'right'){
styles ['text-align'] = part;
attribs.style = serializeStyleText( styles );
}

this.onTagOpen( tagName, attribs, CKEDITOR.dtd.$empty[ tagName ] );
最后一行从658开始:

if ( tagName in convertMap )
    tagName = convertMap[ tagName ];
//adding div element
else if (tagName == 'div'){
    if ( ( value = style['text-align'] ) ) {
        tagName = value;
        value = '';
    }
}
else if ( tagName == 'span' ) {
if ( ( value = style.color ) ) {
    tagName = 'color';
    value = CKEDITOR.tools.convertRgbToHex( value );
....
至少这对我有用

这有点奇怪,因为Justify插件添加了'div'元素而不是'span'。也许你也可以修改它来满足你的“跨度”要求