Closed baptistejamin closed 6 years ago
Hey @mywaystar !
Glad you find this library useful!
Yeah, it seems that 2 new lines are added. I have checked the code and found that even one line is considered a paragraph. And following commonmark spec each paragraph must be separated... It makes sense for big amount of text, but can be annoying for the small one (and especially at the end).
I think that library should handle extra new lines at the end internally, so I will schedule a fix for the next release.
Meanwhile, as a workaround, I suggest trimming parsed markdown manually. The most ugly solution would be casting to SpannableStringBuilder
and doing something like this:
final SpannableStringBuilder builder = (SpannableStringBuilder) Markwon.markdown(configuration, markdown);
final int length = builder.length();
int amount = 0;
for (int i = length - 1; i >= 0; i--) {
if (Character.isWhitespace(builder.charAt(i))) {
amount += 1;
} else {
break;
}
}
if (amount > 0) {
builder.replace(length - amount, length, "");
}
As a thought, maybe, returned from Markwon calls CharSequence
must be changed to SpannableStringBuilder
to allow maybe some modifications...
Thank you for the workaround! and our quick aswner.
This was causing me problems too. Thanks for the tip. Here is my replacement setMarkdown() function, if it helps anyone else.
public static void setMarkdown(@NonNull TextView textView, @NonNull String markdown) {
final SpannableConfiguration configuration = SpannableConfiguration.create(textView.getContext());
final SpannableStringBuilder builder = (SpannableStringBuilder) Markwon.markdown(configuration, markdown);
final int length = builder.length();
int amount = 0;
for (int i = length - 1; i >= 0; i--) {
if (Character.isWhitespace(builder.charAt(i))) {
amount += 1;
} else {
break;
}
}
if (amount > 0) {
builder.replace(length - amount, length, "");
}
Markwon.setText(textView, builder);
}
This is fixed in 1.0.2
release
Hey!
Thank you for building this library.
We are trying to use your library at Crisp (Messaging App), to replace the previous one witch our users didn't like.
It works great so far, but we noticed that it's adding an extra space at the end: