Java源码示例:ru.noties.markwon.Markwon

示例1
private void showCommonQuestionsDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyDialogTheme);
    builder.setTitle("常见问题");
    View view = View.inflate(this, R.layout.layout_common_questions, null);
    commonQuestionTextView = view.findViewById(R.id.tv_common_question);
    Markwon.setMarkdown(commonQuestionTextView, "**加载中...**");
    builder.setView(view);
    builder.setCancelable(false);
    builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            commonQuestionTextView=null;
            dialog.dismiss();
        }
    });
    builder.show();
    presenter.commonQuestions();
}
 
示例2
private void showCommonQuestionsDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyDialogTheme);
    builder.setTitle("常见问题");
    View view = View.inflate(this, R.layout.layout_common_questions, null);
    commonQuestionTextView = view.findViewById(R.id.tv_common_question);
    Markwon.setMarkdown(commonQuestionTextView, "**加载中...**");
    builder.setView(view);
    builder.setCancelable(false);
    builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            commonQuestionTextView=null;
            dialog.dismiss();
        }
    });
    builder.show();
    presenter.commonQuestions();
}
 
示例3
@Override
protected void initData() {
    updateInfo = getIntent().getParcelableExtra("updateInfo");
    if (updateInfo != null) {
        Markwon.create(this).setMarkdown(tvMarkdown, updateInfo.getDetail());
    }
}
 
示例4
/**
 * 显示asset Markdown
 */
public void showAssetMarkdown(String assetFileName) {
    removeAllViews();
    LayoutInflater.from(getContext()).inflate(R.layout.mo_dialog_markdown, this, true);
    TextView tvMarkdown = findViewById(R.id.tv_markdown);
    String aa = ReadAssets.getText(context, assetFileName);
    aa = aa.substring(aa.indexOf("## 更新日志"));
    Markwon.create(tvMarkdown.getContext()).setMarkdown(tvMarkdown, aa);
}
 
示例5
@Override
public void loadCommonQuestionsSuccess(String mdString) {
    Logger.t(TAG).d(mdString);
    if (commonQuestionTextView != null) {
        Markwon.setMarkdown(commonQuestionTextView, mdString);
    }
}
 
示例6
@Override
public void loadCommonQuestionsSuccess(String mdString) {
    Logger.t(TAG).d(mdString);
    if (commonQuestionTextView != null) {
        Markwon.setMarkdown(commonQuestionTextView, mdString);
    }
}
 
示例7
/**
 * 显示asset Markdown
 */
public void showAssetMarkdown(String assetFileName) {
    removeAllViews();
    LayoutInflater.from(getContext()).inflate(R.layout.mo_dialog_markdown, this, true);
    TextView tvMarkdown = findViewById(R.id.tv_markdown);
    Markwon.create(tvMarkdown.getContext()).setMarkdown(tvMarkdown, ReadAssets.getText(context, assetFileName));
}
 
示例8
/**
 * Temporary work-around for Markwon.setMarkdown(view, script); while LinkMovementMethod
 * crashes during selection.
 * See https://github.com/noties/Markwon/issues/41
 * and https://github.com/noties/Markwon/tree/v1.0.6#quick-start.
 */
public static void setUpScript(TextView view, String script, Context context) {
    // create a Parser instance (can be done manually)
    // internally creates default Parser instance & registers `strike-through` & `tables` extension
    final Parser parser = Markwon.createParser();

    // core class to display markdown, can be obtained via this method,
    // which creates default instance (no images handling though),
    // or via `builder` method, which lets you to configure this instance
    //
    // `this` refers to a Context instance
    final SpannableConfiguration configuration = SpannableConfiguration.create(context);

    // it's better **not** to re-use this class between multiple calls
    final SpannableRenderer renderer = new SpannableRenderer();

    final Node node = parser.parse(script);
    final CharSequence text = renderer.render(configuration, node);

    // for links in markdown to be clickable
    view.setMovementMethod(BetterLinkMovementMethod.getInstance());

    // we need these due to the limited nature of Spannables to invalidate TextView
    Markwon.unscheduleDrawables(view);
    Markwon.unscheduleTableRows(view);

    view.setText(text);

    Markwon.scheduleDrawables(view);
    Markwon.scheduleTableRows(view);
}
 
示例9
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	ActivityChangelogBinding binding = ActivityChangelogBinding.inflate(getLayoutInflater());
	setContentView(binding.getRoot());

	try (InputStream inputStream = getResources().openRawResource(R.raw.changelog)) {
		String markdown = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
		Markwon.setMarkdown(binding.txtChangelog, markdown);
	} catch (IOException e) {
		Timber.e(e);
	}
}
 
示例10
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	ActivityFaqBinding binding = ActivityFaqBinding.inflate(getLayoutInflater());
	setContentView(binding.getRoot());

	try (InputStream inputStream = getResources().openRawResource(R.raw.faq)) {
		String markdown = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
		Markwon.setMarkdown(binding.txtFaq, markdown);
	} catch (IOException e) {
		Timber.e(e);
	}
}
 
示例11
private static CharSequence generateMarkdown(Context c, String message) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        return trimTrailingWhitespace(
                new Bypass(c).markdownToSpannable(convertCharacterEncodings(message)));
    }
    return trimTrailingWhitespace(
            Markwon.markdown(c, convertCharacterEncodings(message)));
}