2016-12-05 13 views
0

私はckeditorを使用しています。現在、エディタに(I made a post on it here)のタグを置き換えるバグがあります。問題を説明したバグレポートを提出しましたが、修正を待つことができませんので、今のところ自分で実装したいと思います。私は<font>タグを<span>タグにシームレスに変換する信頼できる方法が何であるか疑問に思っています。フォントを変換するフォント

<font face="Raleway" size="18" color="blue" class="makers styles">Simple Text</font> 

スパン当量がこのようになります::このような

<span style="font-family:Raleway; size:18px; color:blue;" class="makers styles">Simple Text</span> 
+0

多分にそれをコピーして貼り付けるアイデアを、私は、次のしている場合たとえば、 regexの検索と置換を可能にするテキストエディタで、すべての属性をインラインスタイルに変換するための正規表現文字列を作成します。 regex101.comを使って正規表現をテストして構築することをお勧めします。 – MCMXCII

答えて

2

何かが動作するはずです:

$(function() { 

    // Your WYSIWYG content string 
    var content = ""; 

    $('font', content).each(function() { 

     // Append a new <span> after this <font> 
     $(this).after(function() { 
      var span = $('<span>').text($(this).text()); 

      if(this.hasAttribute('face')) { 
       span.css('font-family', $(this).attr('face')); 
      } 
      if(this.hasAttribute('size')) { 
       span.css('font-size', $(this).attr('size') + 'px'); 
      } 
      if(this.hasAttribute('color')) { 
       span.css('color', $(this).attr('color')); 
      } 
      if(this.hasAttribute('class')) { 
       span.attr('class', $(this).attr('class')); 
      } 

      return span; 
     }); 

     // Remove this <font> 
     $(this).remove(); 

    }); 

}); 
関連する問題