Как сохранить тот же формат текста в текстовой области - PullRequest
0 голосов
/ 18 мая 2019

Я вставляю текст с помощью textarea. Я хочу подстроку textarea, как только он достигнет предела и установить содержимое в тот же редактор. Но его удаление форматирования перед тем, как текстовые сообщения и установка простого текста. Я хочу с тем же форматом.

   tinyMCE.init({
        mode: "textareas",
        theme: "advanced",
        editor_selector: "mceEditor",
        paste_auto_cleanup_on_paste: 'true',
        theme_advanced_disable: 'justifyleft,justifyright,justifyfull,justifycenter,indent,image,anchor,sub,sup,unlink,outdent,help,removeformat,link,fontselect,hr,styleselect,formatselect,charmap,separator,code,visualaid,strikethrough,fullscreen',
        theme_advanced_buttons1: 'bold,italic,underline,numlist,bullist,undo,redo,cleanup,spellchecker',
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        plugins: 'spellchecker,fullscreen,paste',
        spellchecker_languages: '+English=en-us',
        spellchecker_rpc_url: '<%out.print(request.getContextPath());%>/jazzy-spellchecker',
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_path: false,
        statusbar: true,
        setup: function (editor) {
            editor.onKeyUp.add(function (evt) {
                var inputRichTextArea = $(editor.getBody()).text();
                var maxLengthRichTextArea = document.getElementById(editor.id).maxLength;
                var inputRichTextAreaLength = inputRichTextArea.length;
                if (inputRichTextAreaLength > maxLengthRichTextArea) {
                    inputRichTextAreaLength = maxLengthRichTextArea;
                    editor.setContent("");
                    tinyMCE.activeEditor.selection.setContent(inputRichTextArea.substring(0, maxLengthRichTextArea));
                }
                var value = maxLengthRichTextArea - inputRichTextAreaLength;
                if (value >= 0) {
                    $(editor.getContainer()).find("#" + editor.id + "_path_row").html("Remaining characters: " + (value));
                }
                if (inputRichTextAreaLength >= maxLengthRichTextArea) {
                    $(editor.getBody()).keypress(function (e) {
                        inputRichTextAreaLength = $(editor.getBody()).text().length;
                        if (inputRichTextAreaLength >= maxLengthRichTextArea) {
                            e.stopPropagation();
                            return false;
                        }
                        var value = maxLengthRichTextArea - inputRichTextAreaLength;
                        if (value >= 0) {
                            $(tinyMCE.activeEditor.getContainer()).find("#" + editor.id + "_path_row").html("Remaining characters: " + (value));
                        }
                    });
                }
            });
        }

    });
<textarea maxlength = 50 rows="4" cols="50"></textarea

Как сохранить одинаковое форматирование.

Вставка текста

Форматирование текста

1 Ответ

0 голосов
/ 20 мая 2019

В вашем примере вы используете функцию .text(), чтобы получить контент, который выделяет только текст без формата. Попробуйте вместо этого использовать .getContent(), так как он выделяет весь контент.

Здесь уже есть вопрос и ответы по нему на StackOverflow . Пожалуйста, следуйте инструкциям там.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...