use of org.commonmark.node.Node in project hippo by NHS-digital-website.
the class ListAttributeProviderTest method ignoresElementOtherThanList.
@Test
public void ignoresElementOtherThanList() {
// given
final Node nodeOtherThanTable = new Code();
// when
listAttributeProvider.setAttributes(nodeOtherThanTable, "tagName is ignored", attributes);
// then
then(attributes).shouldHaveZeroInteractions();
}
use of org.commonmark.node.Node in project PocketHub by pockethub.
the class MarkwonUtils method createMarkwon.
public static Markwon createMarkwon(Context context, String baseUrl) {
final Prism4j prism4j = new Prism4j(new GrammarLocatorDef());
return Markwon.builder(context).usePlugin(StrikethroughPlugin.create()).usePlugin(TaskListPlugin.create(context)).usePlugin(HtmlPlugin.create()).usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
builder.on(FencedCodeBlock.class, (visitor, fencedCodeBlock) -> {
// We actually won't be applying code spans here, as our custom view will
// draw background and apply mono typeface
//
// NB the `trim` operation on literal (as code will have a new line at the end)
final CharSequence code = visitor.configuration().syntaxHighlight().highlight(fencedCodeBlock.getInfo(), fencedCodeBlock.getLiteral().trim());
visitor.builder().append(code);
});
}
@Override
public void configureParser(@NonNull Parser.Builder builder) {
super.configureParser(builder);
builder.postProcessor(new PostProcessor() {
@Override
public Node process(Node node) {
Visitor t = new AbstractVisitor() {
@Override
public void visit(HtmlBlock htmlBlock) {
String literal = htmlBlock.getLiteral();
if (literal.startsWith("<!--")) {
htmlBlock.unlink();
} else {
super.visit(htmlBlock);
}
}
};
node.accept(t);
return node;
}
});
}
}).usePlugin(GlideImagesPlugin.create(new GifAwareGlideStore(context))).usePlugin(new SpanLinkPlugin(baseUrl)).usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configure(@NonNull Registry registry) {
registry.require(HtmlPlugin.class, htmlPlugin -> htmlPlugin.addHandler(new AlignHandler()));
}
}).usePlugin(TableEntryPlugin.create(TablePlugin.create(context))).usePlugin(SyntaxHighlightPlugin.create(prism4j, Prism4jThemeDefault.create())).usePlugin(new AsyncDrawableSchedulerPlugin()).build();
}
use of org.commonmark.node.Node in project Slide by ccrama.
the class DoEditorActions method doActions.
public static void doActions(final EditText editText, final View baseView, final FragmentManager fm, final Activity a, final String oldComment, @Nullable final String[] authors) {
baseView.findViewById(R.id.bold).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("**", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "**");
editText.getText().insert(pos + 1, "**");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
if (baseView.findViewById(R.id.author) != null) {
if (authors != null && authors.length > 0) {
baseView.findViewById(R.id.author).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (authors.length == 1) {
int pos = editText.getSelectionStart();
String author = "/u/" + authors[0];
editText.setText(editText.getText().toString() + author);
// put the cursor between the symbols
editText.setSelection(pos + author.length());
} else {
new AlertDialogWrapper.Builder(a).setTitle(R.string.authors_above).setItems(authors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int pos = editText.getSelectionStart();
String author = "/u/" + authors[which];
editText.setText(editText.getText().toString() + author);
// put the cursor between the symbols
editText.setSelection(pos + author.length());
}
}).setNeutralButton(R.string.btn_cancel, null).show();
}
}
});
} else {
baseView.findViewById(R.id.author).setVisibility(View.GONE);
}
}
baseView.findViewById(R.id.italics).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("*", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "*");
editText.getText().insert(pos + 1, "*");
// put the cursor between the symbols
editText.setSelection(pos + 1);
}
}
});
baseView.findViewById(R.id.strike).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("~~", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "~~");
editText.getText().insert(pos + 1, "~~");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
baseView.findViewById(R.id.savedraft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drafts.addDraft(editText.getText().toString());
Snackbar s = Snackbar.make(baseView.findViewById(R.id.savedraft), "Draft saved", Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.setAction(R.string.btn_discard, new View.OnClickListener() {
@Override
public void onClick(View view) {
Drafts.deleteDraft(Drafts.getDrafts().size() - 1);
}
});
s.show();
}
});
baseView.findViewById(R.id.draft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ArrayList<String> drafts = Drafts.getDrafts();
Collections.reverse(drafts);
final String[] draftText = new String[drafts.size()];
for (int i = 0; i < drafts.size(); i++) {
draftText[i] = drafts.get(i);
}
if (drafts.isEmpty()) {
new AlertDialogWrapper.Builder(a).setTitle(R.string.dialog_no_drafts).setMessage(R.string.dialog_no_drafts_msg).setPositiveButton(R.string.btn_ok, null).show();
} else {
new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setItems(draftText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
editText.setText(editText.getText().toString() + draftText[which]);
}
}).setNeutralButton(R.string.btn_cancel, null).setPositiveButton(R.string.manage_drafts, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final boolean[] selected = new boolean[drafts.size()];
new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setNeutralButton(R.string.btn_cancel, null).alwaysCallMultiChoiceCallback().setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AlertDialogWrapper.Builder(a).setTitle(R.string.really_delete_drafts).setCancelable(false).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ArrayList<String> draf = new ArrayList<>();
for (int i = 0; i < draftText.length; i++) {
if (!selected[i]) {
draf.add(draftText[i]);
}
}
Drafts.save(draf);
}
}).setNegativeButton(R.string.btn_no, null).show();
}
}).setMultiChoiceItems(draftText, selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
selected[which] = isChecked;
}
}).show();
}
}).show();
}
}
});
/*todo baseView.findViewById(R.id.strikethrough).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wrapString("~~", editText);
}
});*/
baseView.findViewById(R.id.imagerep).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(new TedBottomPicker.OnImageSelectedListener() {
@Override
public void onImageSelected(List<Uri> uri) {
handleImageIntent(uri, editText, a);
}
}).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
tedBottomPicker.show(fm);
InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});
baseView.findViewById(R.id.draw).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SettingValues.tabletUI) {
doDraw(a, editText, fm);
} else {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(a).setTitle(R.string.general_cropdraw_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
a.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
a.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (SettingValues.previews > 0) {
b.setNeutralButton(a.getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
doDraw(a, editText, fm);
}
});
}
b.show();
}
}
});
/*todo baseView.findViewById(R.id.superscript).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("^", editText);
}
});*/
baseView.findViewById(R.id.size).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("#", editText);
}
});
baseView.findViewById(R.id.quote).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (oldComment != null) {
final TextView showText = new TextView(a);
showText.setText(oldComment);
showText.setTextIsSelectable(true);
int sixteen = Reddit.dpToPxVertical(24);
showText.setPadding(sixteen, 0, sixteen, 0);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
builder.setView(showText).setTitle(R.string.editor_actions_quote_comment).setCancelable(true).setPositiveButton(a.getString(R.string.btn_select), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
if (selected.equals("")) {
insertBefore("> " + oldComment, editText);
} else {
insertBefore("> " + selected + "\n\n", editText);
}
}
}).setNegativeButton(a.getString(R.string.btn_cancel), null).show();
} else {
insertBefore("> ", editText);
}
}
});
baseView.findViewById(R.id.bulletlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("* ", editText);
}
});
baseView.findViewById(R.id.numlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("1. ", editText);
}
});
baseView.findViewById(R.id.preview).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
Node document = parser.parse(editText.getText().toString());
String html = renderer.render(document);
LayoutInflater inflater = a.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
setViews(html, "NO sub", (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
builder.setView(dialoglayout);
builder.show();
}
});
baseView.findViewById(R.id.link).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final LayoutInflater inflater = LayoutInflater.from(a);
final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.insert_link, null);
int[] attrs = { R.attr.fontColor };
TypedArray ta = baseView.getContext().obtainStyledAttributes(new ColorPreferences(baseView.getContext()).getFontStyle().getBaseId(), attrs);
ta.recycle();
String selectedText = "";
// if the user highlighted text before inputting a URL, use that text for the descriptionBox
if (editText.hasSelection()) {
final int startSelection = editText.getSelectionStart();
final int endSelection = editText.getSelectionEnd();
selectedText = editText.getText().toString().substring(startSelection, endSelection);
}
final boolean selectedTextNotEmpty = !selectedText.isEmpty();
final MaterialDialog dialog = new MaterialDialog.Builder(editText.getContext()).title(R.string.editor_title_link).customView(layout, false).positiveColorAttr(R.attr.tintColor).positiveText(R.string.editor_action_link).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
final EditText urlBox = (EditText) dialog.findViewById(R.id.url_box);
final EditText textBox = (EditText) dialog.findViewById(R.id.text_box);
dialog.dismiss();
final String s = "[".concat(textBox.getText().toString()).concat("](").concat(urlBox.getText().toString()).concat(")");
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
editText.getText().insert(Math.max(start, end), s);
// delete the selected text to avoid duplication
if (selectedTextNotEmpty) {
editText.getText().delete(start, end);
}
}
}).build();
// Tint the hint text if the base theme is Sepia
if (SettingValues.currentTheme == 5) {
((EditText) dialog.findViewById(R.id.url_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
((EditText) dialog.findViewById(R.id.text_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
}
// use the selected text as the text for the link
if (!selectedText.isEmpty()) {
((EditText) dialog.findViewById(R.id.text_box)).setText(selectedText);
}
dialog.show();
}
});
try {
((ImageInsertEditText) editText).setImageSelectedCallback(new ImageInsertEditText.ImageSelectedCallback() {
@Override
public void onImageSelected(final Uri content, String mimeType) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
handleImageIntent(new ArrayList<Uri>() {
{
add(content);
}
}, editText, a);
}
});
} catch (Exception e) {
// if thrown, there is likely an issue implementing this on the user's version of Android. There shouldn't be an issue, but just in case
}
}
use of org.commonmark.node.Node in project xian by happyyangyuan.
the class MdToHtml method mdToHtml.
/**
* @param md the markdown string.
* @return converted html
*/
public static String mdToHtml(String md) {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
use of org.commonmark.node.Node in project lavagna by digitalfondue.
the class MailTicketService method sendEmail.
private void sendEmail(String to, String name, Card createdCard, Board board, ProjectMailTicketConfig config, ProjectMailTicket ticketConfig) {
String cardId = board.getShortName() + "-" + createdCard.getSequence();
String subjectTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getSubject() : config.getSubject());
String bodyTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getBody() : config.getBody());
String subject = subjectTemplate.replaceAll("\\{\\{card}}", cardId);
String body = bodyTemplate.replaceAll("\\{\\{card}}", cardId).replaceAll("\\{\\{name}}", name != null ? name : to);
Parser parser = Parser.builder().build();
Node document = parser.parse(body);
HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
TextContentRenderer textRendered = TextContentRenderer.builder().build();
String htmlText = htmlRenderer.render(document);
String plainText = textRendered.render(document);
ProjectMailTicketConfigData configData = config.getConfig();
MailConfig mailConfig = new MailConfig(configData.getOutboundServer(), configData.getOutboundPort(), configData.getOutboundProtocol(), configData.getOutboundUser(), configData.getOutboundPassword(), ticketConfig.getSendByAlias() ? ticketConfig.getAlias() : configData.getOutboundAddress(), configData.getOutboundProperties());
mailConfig.send(to, subject, plainText, htmlText);
}
Aggregations