richeditor-android icon indicating copy to clipboard operation
richeditor-android copied to clipboard

How can I get the 'pure' text without any formatting from the editor? (如何获取不带格式的Text?)

Open 164738777 opened this issue 8 years ago • 4 comments

I want to get the 'pure' text but not the html from the editor. How can I get it? I want to judge the length of the text.

Thanks~:D

164738777 avatar Aug 28 '17 08:08 164738777

Here is my code. But I can't get the callBack when the sdk < KITKAT.

  /**
   * The valueCallback is disposable,
   * so we need to put this method into the implement of OnTextChangeListener.
   *  这个回调是一次性的,  所以需要在 OnTextChangeListener 的实现方法里面调用此方法。
   */
  public void loadContentTextChangeListener() {
    loadCode("javascript:RE.getText();", new ValueCallback<String>() {
      @Override
      public void onReceiveValue(String value) {
        // The value text is within double quotation.
        // So we should deal with it and only return the text except the double quotation.
       //  返回的Value里面默认有双引号, 所以要进行相关处理除去双引号
        String text = value != null ? value.substring(1, value.length() - 1) : null;
        if (onContentTextChangeListener != null) {
          onContentTextChangeListener.onContentTextChange(text);
        }
      }
    });
  }

  private void loadCode(String JSCode, ValueCallback<String> valueCallback) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      evaluateJavascript(JSCode, valueCallback);
    } else {
      loadUrl(JSCode);
    }
  }

164738777 avatar Aug 28 '17 08:08 164738777

Document doc = Jsoup.parse(mEditor.getHtml()); String txt = doc.body().text();

zhangxi28 avatar Nov 29 '17 10:11 zhangxi28

@zhangxi28 it's work for me,thx! other attention : add this: dependencies { compile 'org.jsoup:jsoup:1.9.2' }

blackleexu avatar Jun 22 '18 07:06 blackleexu

Awesome!!!

@zhangxi28 it's work for me,thx! other attention : add this: dependencies { compile 'org.jsoup:jsoup:1.9.2' }

Yelamanmyrzahanov avatar Feb 19 '19 11:02 Yelamanmyrzahanov