TinyMCE不为\ n插入换行符

时间:2019-02-06 11:14:16

标签: jquery tinymce

我有以下文字

“ 3座令人惊叹的私人别墅。\ n \ n海滩别墅,\ n \ n悬崖别墅,”

在TinyMCE中显示此文本,以下是TinyMCE js代码

 tinyMCE.init({
    mode: "specific_textareas",
    element: editorID,
    encoding: "xml",
    content_css: hostURL + editorcssURL,
    editor_selector: editorClass,
    height: 500,
    external_plugins: { "nanospell": "nanospell/plugin.js" },
    nanospell_autostart: true,
    plugins: ["code searchreplace link print preview charmap paste advlist image textcolor"],
    default_link_target: isgConstants.DefaultTargetTypeForTinyMCEEditorLink,
    link_class_list: [
    { title: 'Special link', value: 'simple-link' },
    { title: 'None', value: '' }
    ],
    nanospell_server: "asp.net", // choose "php" "asp" "asp.net" or "java"
    spellchecker_languages: "English=en",
    relative_urls: false,
    style_formats: styleformat || "",
    toolbar: "cut copy paste | undo redo | bold italic underline strikethrough | bullist numlist outdent indent | charmap link image subscript superscript nanospell | print preview  code | styleselect | forecolor | backcolor | " + EditorCustomButtons,
    forced_root_block: "",
    menubar: "file edit insert format",
    statusbar: false,
    toolbar_items_size: 'medium',
    valid_elements: '*[*]',
    setup: function (event) {
      event.on('keyup', function (e) {
        isgProductText.GetCharCount(event, editorID);
      });
      event.on('init', function (e) {
        var text = tinyMCE.get(editorID).getContent({ format: 'text' });
        var numOfChar = text.trim().length;
        $.trim($('#noOfURChar').text(numOfChar));
      });
      //Add special link button - mk
      event.addButton('addclasstolink', {
        text: 'Special link to all',
        title: 'Add/Remove class to all',
        onclick: function () {
          var anchor = event.dom.select('a');

          var activeState = this.active();

          if (activeState) {
            $(anchor).removeClass('simple-link');
            this.active(false);
          }
          else {
            $(anchor).addClass('simple-link');
            this.active(true);
          }
        }
      });
    },
    file_browser_callback: function (field_name, url, type, win) {
      if (type == 'image') {
        $("#" + field_name).append('<input id="editorFileInpt" type="file">');
        $('#editorFileInpt').click();
        $('#editorFileInpt').change(function () { me.UploadTinyMceImage(field_name) });
      }
    }
  }); 

tinyMCE编辑器在一行中显示“ 3座令人惊叹的私人别墅。海滩别墅,悬崖别墅”。

如何允许在\n存在的地方换行,

并且它也没有显示“。\ n \ n The”之间的空格

我已经尝试过,但是不起作用

    //force_p_newlines : false,
    //force_br_newlines : true,
    //convert_newlines_to_brs : false,
    //remove_linebreaks : false,
    //forced_root_block : false,

2 个答案:

答案 0 :(得分:1)

TinyMCE是HTML编辑器, // keydown condition to start animation with tonejs if(this.state.midiNoteOn === 'noteon'){ Tone.Transport.start() }); //moving notes function update () { const scaleHeight = 140; //vitesse de visualisation des notes let objGraphWhite = this.state.graphicsWhiteNote; objGraphWhite.y = (this.toneTransport.seconds * this.state.speedMidi * scaleHeight); let objGraphBlack = this.state.graphicsblackNote; objGraphBlack.y = (this.toneTransport.seconds * this.state.speedMidi * scaleHeight); requestAnimationFrame(this.update) } //playing song function with tone synth playnotes(time, event) { let newtime = time.toFixed(2) let duration = event.duration let midiNumber = event.midi this.synth.triggerAttackRelease(event.name, duration , newtime, event.velocity)} 字符在HTML中没有意义。如果要将其变成TinyMCE中的换行符,则需要先将\n转换为\n,然后再将数据加载到HTML中。

如果给TinyMCE一个文本字符串,而没有包装HTML标记,则整个字符串将被包装在一个段落(<br>)中,以确保您具有有效的格式正确的HTML。

答案 1 :(得分:-2)

当然,在 html 中,\n 不显示,但在代码模式下,\n 会出现...