Merge pull request #270 from seatgeek/dallas/add_link_underline_option

Adding support for disabling the underlining of links
This commit is contained in:
Dimitry 2020-07-29 11:52:31 +03:00 committed by GitHub
commit 6ec7132273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ import io.noties.markwon.utils.Dip;
/** /**
* Class to hold <i>theming</i> information for rending of markdown. * Class to hold <i>theming</i> information for rending of markdown.
* <p> * <p>
* Since version 3.0.0 this class should be considered as <em>CoreTheme</em> as it\'s * Since version 3.0.0 this class should be considered as <em>CoreTheme</em> as its
* information holds data for core features only. But based on this other components can still use it * information holds data for core features only. But based on this other components can still use it
* to display markdown consistently. * to display markdown consistently.
* <p> * <p>
@ -117,6 +117,10 @@ public class MarkwonTheme {
protected final int linkColor; protected final int linkColor;
// specifies whether we underline links, by default is true
// @since 4.4.1
protected final boolean isLinkedUnderlined;
// used in quote, lists // used in quote, lists
protected final int blockMargin; protected final int blockMargin;
@ -185,6 +189,7 @@ public class MarkwonTheme {
protected MarkwonTheme(@NonNull Builder builder) { protected MarkwonTheme(@NonNull Builder builder) {
this.linkColor = builder.linkColor; this.linkColor = builder.linkColor;
this.isLinkedUnderlined = builder.isLinkUnderlined;
this.blockMargin = builder.blockMargin; this.blockMargin = builder.blockMargin;
this.blockQuoteWidth = builder.blockQuoteWidth; this.blockQuoteWidth = builder.blockQuoteWidth;
this.blockQuoteColor = builder.blockQuoteColor; this.blockQuoteColor = builder.blockQuoteColor;
@ -212,7 +217,7 @@ public class MarkwonTheme {
* @since 1.0.5 * @since 1.0.5
*/ */
public void applyLinkStyle(@NonNull TextPaint paint) { public void applyLinkStyle(@NonNull TextPaint paint) {
paint.setUnderlineText(true); paint.setUnderlineText(isLinkedUnderlined);
if (linkColor != 0) { if (linkColor != 0) {
paint.setColor(linkColor); paint.setColor(linkColor);
} else { } else {
@ -222,7 +227,7 @@ public class MarkwonTheme {
} }
public void applyLinkStyle(@NonNull Paint paint) { public void applyLinkStyle(@NonNull Paint paint) {
paint.setUnderlineText(true); paint.setUnderlineText(isLinkedUnderlined);
if (linkColor != 0) { if (linkColor != 0) {
// by default we will be using text color // by default we will be using text color
paint.setColor(linkColor); paint.setColor(linkColor);
@ -457,6 +462,7 @@ public class MarkwonTheme {
public static class Builder { public static class Builder {
private int linkColor; private int linkColor;
private boolean isLinkUnderlined = true; // @since 4.4.1
private int blockMargin; private int blockMargin;
private int blockQuoteWidth; private int blockQuoteWidth;
private int blockQuoteColor; private int blockQuoteColor;
@ -484,6 +490,7 @@ public class MarkwonTheme {
Builder(@NonNull MarkwonTheme theme) { Builder(@NonNull MarkwonTheme theme) {
this.linkColor = theme.linkColor; this.linkColor = theme.linkColor;
this.isLinkUnderlined = theme.isLinkedUnderlined;
this.blockMargin = theme.blockMargin; this.blockMargin = theme.blockMargin;
this.blockQuoteWidth = theme.blockQuoteWidth; this.blockQuoteWidth = theme.blockQuoteWidth;
this.blockQuoteColor = theme.blockQuoteColor; this.blockQuoteColor = theme.blockQuoteColor;
@ -511,6 +518,12 @@ public class MarkwonTheme {
return this; return this;
} }
@NonNull
public Builder isLinkUnderlined(boolean isLinkUnderlined) {
this.isLinkUnderlined = isLinkUnderlined;
return this;
}
@NonNull @NonNull
public Builder blockMargin(@Px int blockMargin) { public Builder blockMargin(@Px int blockMargin) {
this.blockMargin = blockMargin; this.blockMargin = blockMargin;