Add softBreakAddsNewLine option for SpannableConfiguration
This commit is contained in:
parent
d08d158e7f
commit
9765deb787
@ -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 SpannableConfiguration(@NonNull Builder builder) {
|
||||
this.theme = builder.theme;
|
||||
@ -42,6 +43,7 @@ public class SpannableConfiguration {
|
||||
this.htmlParser = builder.htmlParser;
|
||||
this.imageSizeResolver = builder.imageSizeResolver;
|
||||
this.factory = builder.factory;
|
||||
this.softBreakAddsNewLine = builder.softBreakAddsNewLine;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -84,6 +86,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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Builder {
|
||||
|
||||
@ -95,7 +106,8 @@ public class SpannableConfiguration {
|
||||
private UrlProcessor urlProcessor;
|
||||
private SpannableHtmlParser htmlParser;
|
||||
private ImageSizeResolver imageSizeResolver;
|
||||
private SpannableFactory factory;
|
||||
private SpannableFactory factory; // @since 1.1.0
|
||||
private boolean softBreakAddsNewLine; // @since 1.1.1
|
||||
|
||||
Builder(@NonNull Context context) {
|
||||
this.context = context;
|
||||
@ -155,6 +167,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 <a href="https://spec.commonmark.org/0.28/#soft-line-breaks">spec</a>
|
||||
* @since 1.1.1
|
||||
*/
|
||||
@NonNull
|
||||
public Builder softBreakAddsNewLine(boolean softBreakAddsNewLine) {
|
||||
this.softBreakAddsNewLine = softBreakAddsNewLine;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public SpannableConfiguration build() {
|
||||
|
||||
|
@ -256,9 +256,13 @@ 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
|
||||
// @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
|
||||
public void visit(HardLineBreak hardLineBreak) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user