TinyMce p和br替换为\ r \ n

时间:2018-01-03 07:14:20

标签: wordpress tinymce

使用以下init配置, p br 标记将替换为编辑器输出中的\ r \ n。尝试了几个配置配置似乎没有工作。 我试图在WordPress中创建额外的可视化编辑器,是否有任何可以直接应用的预设wp tinymce配置,我的编辑器也缺少我在主wp编辑器中创建的一些按钮。

 tinymce.init({


    remove_linebreaks : false,
    forced_root_block : 'p', 
    mode : "specific_textareas",
    apply_source_formatting : 'true',

    formats: {
        bold : {inline : 'b' },
        italic : {inline : 'i' }
    }, 
     ,
    selector: 'textarea.textarea_ct', 
    setup: function (editor) {
        editor.on('change', function () {

            tinymce.triggerSave();

        })
    },
})

1 个答案:

答案 0 :(得分:0)

但您不需要安装建议的插件。只需添加此迷你插件即可设置:

function WTSQuerySessionInformation(
  hServer: THandle; SessionId: Cardinal; WTSInfoClass: Integer; var pBuffer: DWord;
  var BytesReturned: DWord): Boolean;
  external 'WTSQuerySessionInformationW@wtsapi32.dll stdcall';

procedure WTSFreeMemory(pMemory: DWord);
  external 'WTSFreeMemory@wtsapi32.dll stdcall';

procedure RtlMoveMemoryAsString(Dest: string; Source: DWord; Len: Integer);
  external 'RtlMoveMemory@kernel32.dll stdcall';

const
  WTS_CURRENT_SERVER_HANDLE = 0;
  WTS_CURRENT_SESSION = -1;
  WTSUserName = 5;

function GetCurrentSessionUserName: string;
var
  Buffer: DWord;
  BytesReturned: DWord;
  QueryResult: Boolean;
begin
  QueryResult :=
    WTSQuerySessionInformation(
      WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, Buffer,
      BytesReturned);

  if not QueryResult then
  begin
    Log('Failed to retrieve username');
    Result := '';
  end
    else
  begin
    SetLength(Result, (BytesReturned div 2) - 1);
    RtlMoveMemoryAsString(Result, Buffer, BytesReturned);
    WTSFreeMemory(Buffer);
    Log(Format('Retrieved username "%s"', [Result]));
  end;
end;

现在当您按Enter键时,将插入标签而不是创建新段落。但请注意,如果您创建两个连续的换行符,则[

]会将文本拆分为段落

<?php
defined( 'ABSPATH' ) OR exit;
/* Plugin Name: TinyMCE break instead of paragraph */
function mytheme_tinymce_settings( $tinymce_init_settings ) {
    $tinymce_init_settings['forced_root_block'] = false;
    return $tinymce_init_settings;
}
add_filter( 'tiny_mce_before_init', 'mytheme_tinymce_settings' );

] 1过滤器已应用于您的帖子内容。您需要先删除此过滤器并创建一个新过滤器,以使用
标签替换所有换行符。将这样的内容添加到functions.php中以在模板中显示<标签: