* Removing trailing new lines from parsed markdown

* Fix for heading break height and thematic break height

* Tables can have no borders (0)
This commit is contained in:
Dimitry 2017-11-24 12:04:32 +03:00 committed by GitHub
parent 6e2dd36e4f
commit 7a318527d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 25 deletions

View File

@ -6,7 +6,7 @@ org.gradle.configureondemand=true
android.enableBuildCache=true android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache android.buildCacheDir=build/pre-dex-cache
VERSION_NAME=1.0.1 VERSION_NAME=1.0.2
GROUP=ru.noties GROUP=ru.noties
POM_DESCRIPTION=Markwon POM_DESCRIPTION=Markwon

View File

@ -160,6 +160,24 @@ public class SpannableBuilder {
impl.setSpan(span.what, span.start, span.end, span.flags); impl.setSpan(span.what, span.start, span.end, span.flags);
} }
// now, let's remove trailing newLines (so small amounts of text are displayed correctly)
// @since 1.0.2
final int length = impl.length();
if (length > 0) {
int amount = 0;
for (int i = length - 1; i >=0 ; i--) {
if (Character.isWhitespace(impl.charAt(i))) {
amount += 1;
} else {
break;
}
}
if (amount > 0) {
impl.replace(length - amount, length, "");
}
}
return impl; return impl;
} }

View File

@ -53,6 +53,9 @@ public class HeadingSpan extends MetricAffectingSpan implements LeadingMarginSpa
theme.applyHeadingBreakStyle(paint); theme.applyHeadingBreakStyle(paint);
final float height = paint.getStrokeWidth(); final float height = paint.getStrokeWidth();
if (height > .0F) {
final int b = (int) (bottom - height + .5F); final int b = (int) (bottom - height + .5F);
final int left; final int left;
@ -70,3 +73,4 @@ public class HeadingSpan extends MetricAffectingSpan implements LeadingMarginSpa
} }
} }
} }
}

View File

@ -336,7 +336,7 @@ public class SpannableTheme {
} }
paint.setColor(color); paint.setColor(color);
paint.setStyle(Paint.Style.FILL); paint.setStyle(Paint.Style.FILL);
if (headingBreakHeight != 0) { if (headingBreakHeight >= 0) {
//noinspection SuspiciousNameCombination //noinspection SuspiciousNameCombination
paint.setStrokeWidth(headingBreakHeight); paint.setStrokeWidth(headingBreakHeight);
} }
@ -374,7 +374,7 @@ public class SpannableTheme {
paint.setColor(color); paint.setColor(color);
paint.setStyle(Paint.Style.FILL); paint.setStyle(Paint.Style.FILL);
if (thematicBreakHeight != 0) { if (thematicBreakHeight >= 0) {
//noinspection SuspiciousNameCombination //noinspection SuspiciousNameCombination
paint.setStrokeWidth(thematicBreakHeight); paint.setStrokeWidth(thematicBreakHeight);
} }
@ -384,6 +384,16 @@ public class SpannableTheme {
return tableCellPadding; return tableCellPadding;
} }
public int tableBorderWidth(@NonNull Paint paint) {
final int out;
if (tableBorderWidth == -1) {
out = (int) (paint.getStrokeWidth() + .5F);
} else {
out = tableBorderWidth;
}
return out;
}
public void applyTableBorderStyle(@NonNull Paint paint) { public void applyTableBorderStyle(@NonNull Paint paint) {
final int color; final int color;
@ -393,10 +403,6 @@ public class SpannableTheme {
color = tableBorderColor; color = tableBorderColor;
} }
if (tableBorderWidth != 0) {
paint.setStrokeWidth(tableBorderWidth);
}
paint.setColor(color); paint.setColor(color);
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
} }
@ -435,14 +441,14 @@ public class SpannableTheme {
private int codeMultilineMargin; private int codeMultilineMargin;
private Typeface codeTypeface; private Typeface codeTypeface;
private int codeTextSize; private int codeTextSize;
private int headingBreakHeight; private int headingBreakHeight = -1;
private int headingBreakColor; private int headingBreakColor;
private float scriptTextSizeRatio; private float scriptTextSizeRatio;
private int thematicBreakColor; private int thematicBreakColor;
private int thematicBreakHeight; private int thematicBreakHeight = -1;
private int tableCellPadding; private int tableCellPadding;
private int tableBorderColor; private int tableBorderColor;
private int tableBorderWidth; private int tableBorderWidth = -1;
private int tableOddRowBackgroundColor; private int tableOddRowBackgroundColor;
private Drawable taskListDrawable; private Drawable taskListDrawable;

View File

@ -169,10 +169,14 @@ public class TableRowSpan extends ReplacementSpan {
} }
} }
rect.set(0, 0, w, bottom - top);
theme.applyTableBorderStyle(this.paint); theme.applyTableBorderStyle(this.paint);
final int borderWidth = theme.tableBorderWidth(paint);
final boolean drawBorder = borderWidth > 0;
if (drawBorder) {
rect.set(0, 0, w, bottom - top);
}
StaticLayout layout; StaticLayout layout;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
layout = layouts.get(i); layout = layouts.get(i);
@ -180,7 +184,10 @@ public class TableRowSpan extends ReplacementSpan {
try { try {
canvas.translate(x + (i * w), top - heightDiff); canvas.translate(x + (i * w), top - heightDiff);
if (drawBorder) {
canvas.drawRect(rect, this.paint); canvas.drawRect(rect, this.paint);
}
canvas.translate(padding, padding + heightDiff); canvas.translate(padding, padding + heightDiff);
layout.draw(canvas); layout.draw(canvas);