Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
164738777 opened this issue Aug 28, 2017 · 4 comments

Comments

@164738777
Copy link

164738777 commented Aug 28, 2017

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 164738777 changed the title How can I getText without any formatting from the editor? How can I get the 'pure' text without any formatting from the editor? Aug 28, 2017
@164738777 164738777 changed the title How can I get the 'pure' text without any formatting from the editor? How can I get the 'pure' text without any formatting from the editor? (如何获取不带格式的Text?) Aug 28, 2017
@164738777
Copy link
Author

164738777 commented Aug 28, 2017

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);
    }
  }

@zhangxi28
Copy link

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

@blackleexu
Copy link

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

@Yelamanmyrzahanov
Copy link

Awesome!!!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants