use of im.actor.runtime.markdown.MarkdownParser in project actor-platform by actorapp.
the class AndroidMarkdown method processText.
private static Spannable processText(String markdown, int mode) {
MDDocument doc = new MarkdownParser(mode).processDocument(markdown);
SpannableStringBuilder builder = new SpannableStringBuilder();
boolean isFirst = true;
for (MDSection s : doc.getSections()) {
if (isFirst) {
isFirst = false;
} else {
builder.append("\n");
}
if (s.getType() == MDSection.TYPE_CODE) {
int start = builder.length();
builder.append("View Source Code");
final String text = s.getCode().getCode();
builder.setSpan(new RelativeSizeSpan(1.1f), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(Color.RED), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
AndroidContext.getContext().startActivity(new Intent(AndroidContext.getContext(), CodePreviewActivity.class).putExtra("source_code", text).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (s.getType() == MDSection.TYPE_TEXT) {
writeText(s.getText(), builder);
} else {
throw new RuntimeException("Unknown section type: " + s.getType());
}
}
return builder;
}
Aggregations