diff --git a/README.md b/README.md index cf7ea17b..1bd0c545 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ allprojects { and then in your module `build.gradle`: ```groovy -implementation 'ru.noties:markwon:1.1.0-SNAPSHOT' +implementation 'ru.noties:markwon:1.1.1-SNAPSHOT' ``` Please note that `markwon-image-loader`, `markwon-syntax` and `markwon-view` are also present in `SNAPSHOT` repository and share the same version as main `markwon` artifact. diff --git a/build.gradle b/build.gradle index 31ab153d..11bf488a 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,14 @@ task wrapper(type: Wrapper) { distributionType 'all' } +if (hasProperty('local')) { + if (!hasProperty('LOCAL_MAVEN_URL')) { + throw new RuntimeException('Cannot publish to local maven as no such property exists: LOCAL_MAVEN_URL') + } + ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL + ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL +} + ext { // Config diff --git a/gradle.properties b/gradle.properties index c9111b02..c9a46e33 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.configureondemand=true android.enableBuildCache=true android.buildCacheDir=build/pre-dex-cache -VERSION_NAME=1.1.0 +VERSION_NAME=2.0.0-SNAPSHOT GROUP=ru.noties POM_DESCRIPTION=Markwon diff --git a/library-image-loader/build.gradle b/library-image-loader/build.gradle index 062f09d1..9d655ea3 100644 --- a/library-image-loader/build.gradle +++ b/library-image-loader/build.gradle @@ -30,9 +30,5 @@ afterEvaluate { } if (hasProperty('release')) { - if (hasProperty('local')) { - ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL - ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL - } apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle' } diff --git a/library-syntax/build.gradle b/library-syntax/build.gradle index 70988485..2d6a2a67 100644 --- a/library-syntax/build.gradle +++ b/library-syntax/build.gradle @@ -24,9 +24,5 @@ afterEvaluate { } if (hasProperty('release')) { - if (hasProperty('local')) { - ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL - ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL - } apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle' } diff --git a/library-view/build.gradle b/library-view/build.gradle index 6982037a..fb709db9 100644 --- a/library-view/build.gradle +++ b/library-view/build.gradle @@ -23,9 +23,5 @@ afterEvaluate { } if (hasProperty('release')) { - if (hasProperty('local')) { - ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL - ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL - } apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle' } diff --git a/library/build.gradle b/library/build.gradle index 795f7407..a9bc3ee2 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -25,9 +25,5 @@ afterEvaluate { } if (hasProperty('release')) { - if (hasProperty('local')) { - ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL - ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL - } apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle' } diff --git a/library/src/main/java/ru/noties/markwon/SpannableConfiguration.java b/library/src/main/java/ru/noties/markwon/SpannableConfiguration.java index c25d009d..a14dac95 100644 --- a/library/src/main/java/ru/noties/markwon/SpannableConfiguration.java +++ b/library/src/main/java/ru/noties/markwon/SpannableConfiguration.java @@ -32,6 +32,7 @@ public class SpannableConfiguration { private final SpannableHtmlParser htmlParser; private final ImageSizeResolver imageSizeResolver; private final SpannableFactory factory; // @since 1.1.0 + private final boolean softBreakAddsNewLine; // @since 1.1.1 private final boolean trimWhiteSpaceEnd; // @since 2.0.0 private SpannableConfiguration(@NonNull Builder builder) { @@ -43,6 +44,7 @@ public class SpannableConfiguration { this.htmlParser = builder.htmlParser; this.imageSizeResolver = builder.imageSizeResolver; this.factory = builder.factory; + this.softBreakAddsNewLine = builder.softBreakAddsNewLine; this.trimWhiteSpaceEnd = builder.trimWhiteSpaceEnd; } @@ -86,6 +88,15 @@ public class SpannableConfiguration { return factory; } + /** + * @return a flag indicating if soft break should be treated as a hard + * break and thus adding a new line instead of adding a white space + * @since 1.1.1 + */ + public boolean softBreakAddsNewLine() { + return softBreakAddsNewLine; + } + /** * @since 2.0.0 */ @@ -104,8 +115,9 @@ public class SpannableConfiguration { private UrlProcessor urlProcessor; private SpannableHtmlParser htmlParser; private ImageSizeResolver imageSizeResolver; - private SpannableFactory factory; - private boolean trimWhiteSpaceEnd = true; + private SpannableFactory factory; // @since 1.1.0 + private boolean softBreakAddsNewLine; // @since 1.1.1 + private boolean trimWhiteSpaceEnd = true; // @since 2.0.0 Builder(@NonNull Context context) { this.context = context; @@ -165,6 +177,19 @@ public class SpannableConfiguration { return this; } + /** + * @param softBreakAddsNewLine a flag indicating if soft break should be treated as a hard + * break and thus adding a new line instead of adding a white space + * @return self + * @see spec + * @since 1.1.1 + */ + @NonNull + public Builder softBreakAddsNewLine(boolean softBreakAddsNewLine) { + this.softBreakAddsNewLine = softBreakAddsNewLine; + return this; + } + /** * Will trim white space(s) from the end from resulting text. * By default `true` diff --git a/library/src/main/java/ru/noties/markwon/SpannableFactory.java b/library/src/main/java/ru/noties/markwon/SpannableFactory.java index 4cd6b947..472261a4 100644 --- a/library/src/main/java/ru/noties/markwon/SpannableFactory.java +++ b/library/src/main/java/ru/noties/markwon/SpannableFactory.java @@ -56,6 +56,12 @@ public interface SpannableFactory { boolean isHeader, boolean isOdd); + /** + * @since 1.1.1 + */ + @Nullable + Object paragraph(boolean inTightList); + @Nullable Object image( @NonNull SpannableTheme theme, diff --git a/library/src/main/java/ru/noties/markwon/SpannableFactoryDef.java b/library/src/main/java/ru/noties/markwon/SpannableFactoryDef.java index f7672ac7..ee553329 100644 --- a/library/src/main/java/ru/noties/markwon/SpannableFactoryDef.java +++ b/library/src/main/java/ru/noties/markwon/SpannableFactoryDef.java @@ -103,6 +103,15 @@ public class SpannableFactoryDef implements SpannableFactory { return new TableRowSpan(theme, cells, isHeader, isOdd); } + /** + * @since 1.1.1 + */ + @Nullable + @Override + public Object paragraph(boolean inTightList) { + return null; + } + @Nullable @Override public Object image(@NonNull SpannableTheme theme, @NonNull String destination, @NonNull AsyncDrawable.Loader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) { diff --git a/library/src/main/java/ru/noties/markwon/renderer/SpannableMarkdownVisitor.java b/library/src/main/java/ru/noties/markwon/renderer/SpannableMarkdownVisitor.java index efb6426d..993c62b0 100644 --- a/library/src/main/java/ru/noties/markwon/renderer/SpannableMarkdownVisitor.java +++ b/library/src/main/java/ru/noties/markwon/renderer/SpannableMarkdownVisitor.java @@ -266,8 +266,12 @@ public class SpannableMarkdownVisitor extends AbstractVisitor { @Override public void visit(SoftLineBreak softLineBreak) { - // at first here was a new line, but here should be a space char - builder.append(' '); + // @since 1.1.1 there is an option to treat soft break as a hard break (thus adding new line) + if (configuration.softBreakAddsNewLine()) { + newLine(); + } else { + builder.append(' '); + } } @Override @@ -386,15 +390,18 @@ public class SpannableMarkdownVisitor extends AbstractVisitor { @Override public void visit(Paragraph paragraph) { - final boolean inTightList = isInTightList(paragraph); if (!inTightList) { newLine(); } + final int length = builder.length(); visitChildren(paragraph); + // @since 1.1.1 apply paragraph span + setSpan(length, factory.paragraph(inTightList)); + if (!inTightList) { newLine(); diff --git a/library/src/main/java/ru/noties/markwon/spans/CanvasUtils.java b/library/src/main/java/ru/noties/markwon/spans/CanvasUtils.java index b55783b8..0851e855 100644 --- a/library/src/main/java/ru/noties/markwon/spans/CanvasUtils.java +++ b/library/src/main/java/ru/noties/markwon/spans/CanvasUtils.java @@ -6,7 +6,8 @@ import android.support.annotation.NonNull; abstract class CanvasUtils { static float textCenterY(int top, int bottom, @NonNull Paint paint) { - return (int) (bottom - ((bottom - top) / 2) - ((paint.descent() + paint.ascent()) / 2.F + .5F)); + // @since 1.1.1 it's `top +` and not `bottom -` + return (int) (top + ((bottom - top) / 2) - ((paint.descent() + paint.ascent()) / 2.F + .5F)); } private CanvasUtils() { diff --git a/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java b/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java index 194f7676..16e9895f 100644 --- a/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java +++ b/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java @@ -59,8 +59,7 @@ public class OrderedListItemSpan implements LeadingMarginSpan { left = x + (width * dir) + (width - numberWidth); } - final float numberY = CanvasUtils.textCenterY(top, bottom, p); - - c.drawText(number, left, numberY, p); + // @since 1.1.1 we are using `baseline` argument to position text + c.drawText(number, left, baseline, p); } } diff --git a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java index 10c4c762..e82d0d8b 100644 --- a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java +++ b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java @@ -206,6 +206,14 @@ public class SpannableTheme { // by default paint.color * TABLE_ODD_ROW_DEF_ALPHA protected final int tableOddRowBackgroundColor; + // @since 1.1.1 + // by default no background + protected final int tableEventRowBackgroundColor; + + // @since 1.1.1 + // by default no background + protected final int tableHeaderRowBackgroundColor; + // drawable that will be used to render checkbox (should be stateful) // TaskListDrawable can be used protected final Drawable taskListDrawable; @@ -236,6 +244,8 @@ public class SpannableTheme { this.tableBorderColor = builder.tableBorderColor; this.tableBorderWidth = builder.tableBorderWidth; this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor; + this.tableEventRowBackgroundColor = builder.tableEvenRowBackgroundColor; + this.tableHeaderRowBackgroundColor = builder.tableHeaderRowBackgroundColor; this.taskListDrawable = builder.taskListDrawable; } @@ -493,6 +503,23 @@ public class SpannableTheme { paint.setStyle(Paint.Style.FILL); } + /** + * @since 1.1.1 + */ + public void applyTableEvenRowStyle(@NonNull Paint paint) { + // by default to background to even row + paint.setColor(tableEventRowBackgroundColor); + paint.setStyle(Paint.Style.FILL); + } + + /** + * @since 1.1.1 + */ + public void applyTableHeaderRowStyle(@NonNull Paint paint) { + paint.setColor(tableHeaderRowBackgroundColor); + paint.setStyle(Paint.Style.FILL); + } + /** * @return a Drawable to be used as a checkbox indication in task lists * @since 1.0.1 @@ -530,6 +557,8 @@ public class SpannableTheme { private int tableBorderColor; private int tableBorderWidth = -1; private int tableOddRowBackgroundColor; + private int tableEvenRowBackgroundColor; // @since 1.1.1 + private int tableHeaderRowBackgroundColor; // @since 1.1.1 private Drawable taskListDrawable; Builder() { @@ -733,6 +762,24 @@ public class SpannableTheme { return this; } + /** + * @since 1.1.1 + */ + @NonNull + public Builder tableEvenRowBackgroundColor(@ColorInt int tableEvenRowBackgroundColor) { + this.tableEvenRowBackgroundColor = tableEvenRowBackgroundColor; + return this; + } + + /** + * @since 1.1.1 + */ + @NonNull + public Builder tableHeaderRowBackgroundColor(int tableHeaderRowBackgroundColor) { + this.tableHeaderRowBackgroundColor = tableHeaderRowBackgroundColor; + return this; + } + /** * Supplied Drawable must be stateful ({@link Drawable#isStateful()} returns true). If a task * is marked as done, then this drawable will be updated with an {@code int[] { android.R.attr.state_checked }} diff --git a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java index 552af486..4d3a35fb 100644 --- a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java +++ b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java @@ -157,18 +157,35 @@ public class TableRowSpan extends ReplacementSpan { // feels like magic... final int heightDiff = (bottom - top - height) / 4; - if (odd) { - final int save = canvas.save(); - try { - rect.set(0, 0, width, bottom - top); + // @since 1.1.1 + // draw backgrounds + { + if (header) { + theme.applyTableHeaderRowStyle(this.paint); + } else if (odd) { theme.applyTableOddRowStyle(this.paint); - canvas.translate(x, top - heightDiff); - canvas.drawRect(rect, this.paint); - } finally { - canvas.restoreToCount(save); + } else { + // even + theme.applyTableEvenRowStyle(this.paint); + } + + // if present (0 is transparent) + if (this.paint.getColor() != 0) { + final int save = canvas.save(); + try { + rect.set(0, 0, width, bottom - top); + canvas.translate(x, top - heightDiff); + canvas.drawRect(rect, this.paint); + } finally { + canvas.restoreToCount(save); + } } } + // @since 1.1.1 reset after applying background color + // as background changes color attribute and if not specific tableBorderColor + // is specified then after this row all borders will have color of this row (plus alpha) + this.paint.set(paint); theme.applyTableBorderStyle(this.paint); final int borderWidth = theme.tableBorderWidth(paint);