1

ランダムな Web ページからコンテンツをコピーし、SharePoint 2010 RTE に貼り付けるユーザーがいます。彼らは知らないうちに、RTE がスタイル付きスパン タグに変換する元の Web ページからスタイルをコピーしており、これらのスパン タグはページのデフォルトのテキスト スタイルを上書きしています。貼り付け時に、任意またはすべてのスパン タグを自動的に削除し、残りのマークアップを保持したいと考えています。他にも関連する問題があることは承知していますが、span タグを削除すると、必要な場所にずっと近づくことができます。

ここで、貼り付け時にすべてのマークアップを削除するコード スニペットを見つけました。

//Disable the RTE paste option. Restricts to "Paste Plain Text" 
function disableMarkupPasteForRTE()
{
 Type.registerNamespace("RTE");
 if (RTE)
 {
  if(RTE.RichTextEditor != null)
  {
   RTE.RichTextEditor.paste = function() { RTE.Cursor.paste(true); }
   // Handle Ctrl+V short cut options in rich text editor
   RTE.Cursor.$3C_0 = true;
  }
 }
}

_spBodyOnLoadFunctionNames.push("disableMarkupPasteForRTE");

上記のコードを変更して、スパンタグのみを削除できる人はいますか?

4

2 に答える 2

0

SharePoint RTE は、強化された ContentEditable div にすぎません。解決策は、関数 onpaste をエディターにバインドしてから、html を直接操作することです。

$(document).ready(function() {
    $(".ms-rtestate-write").bind('paste', function(e) {
        var text = $(this).html();
        $(this).html(text.replace( /<\s*span.*?>/gi,"").replace( /<\s*\/\s*span\s*.*?>/gi,""));
    });
});
于 2012-08-01T19:07:58.093 に答える
0

Sharepoint の貼り付け方法を使用して、次のように html を変更できます。

RTE.Cursor.$1u_0--;
RTE.Cursor.$1G_0 = true;
RTE.Cursor.$A2();
RTE.Cursor.$S_0.style.display = '';
var $v_0 = RTE.Cursor.$S_0.contentWindow.document;
var $v_1 = $v_0.body;
var $v_2 = RTE.DomHelper.createRange($v_0);
var $v_3 = new RTE.Range($v_2);
$v_3.moveToElementText($v_1);
$v_3.select();
$v_0.execCommand('paste', false, null);

html = $v_2.htmlText;
//modify the html source

//paste back your new html
$v_2.pasteHTML(newhtml);

RTE.Cursor.updateRangeToCurrentSelectionWithOptions(true);
var $v_4 = RTE.Cursor.get_range();
var $v_5 = $v_4.$1N();
$v_4.deleteContent();
$v_5.select();
RTE.Cursor.$S_0.style.display = 'none';
RTE.Cursor.$2U_0 = true;
RTE.Cursor.$28_0 = true;
RTE.Cursor.$Ei_0();
RTE.Cursor.$59();
RTE.Cursor.$A2();
window.setTimeout(RTE.Cursor.$9w, 0);
if (RTE.Cursor.$1u_0 > 0) {
    window.setTimeout(RTE.Cursor.$5p_0, 10);
}
于 2013-03-05T07:59:19.867 に答える