Remove ext tests from core module

This commit is contained in:
Dimitry Ivanov 2018-12-13 19:05:49 +03:00
parent 078d4dfc38
commit 5a18aa3a01
69 changed files with 188 additions and 958 deletions

View File

@ -38,21 +38,6 @@
android:host="*" android:host="*"
android:scheme="https" /> android:scheme="https" />
<!--<data-->
<!--android:host="*"-->
<!--android:scheme="http"-->
<!--android:mimeType="text/toMarkdown"/>-->
<!--<data-->
<!--android:host="*"-->
<!--android:scheme="file"-->
<!--android:mimeType="text/toMarkdown"/>-->
<!--<data-->
<!--android:host="*"-->
<!--android:scheme="https"-->
<!--android:mimeType="text/toMarkdown"/>-->
<data android:pathPattern=".*\\.markdown" /> <data android:pathPattern=".*\\.markdown" />
<data android:pathPattern=".*\\.mdown" /> <data android:pathPattern=".*\\.mdown" />
<data android:pathPattern=".*\\.mkdn" /> <data android:pathPattern=".*\\.mkdn" />

View File

@ -26,6 +26,8 @@ import ru.noties.markwon.syntax.Prism4jTheme;
import ru.noties.markwon.syntax.Prism4jThemeDarkula; import ru.noties.markwon.syntax.Prism4jThemeDarkula;
import ru.noties.markwon.syntax.Prism4jThemeDefault; import ru.noties.markwon.syntax.Prism4jThemeDefault;
import ru.noties.markwon.syntax.SyntaxHighlightPlugin; import ru.noties.markwon.syntax.SyntaxHighlightPlugin;
import ru.noties.markwon.urlprocessor.UrlProcessor;
import ru.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import ru.noties.prism4j.Prism4j; import ru.noties.prism4j.Prism4j;
@ActivityScope @ActivityScope

View File

@ -4,6 +4,9 @@ import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import ru.noties.markwon.urlprocessor.UrlProcessor;
import ru.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
class UrlProcessorInitialReadme implements UrlProcessor { class UrlProcessorInitialReadme implements UrlProcessor {
private static final String GITHUB_BASE = "https://github.com/noties/Markwon/raw/master/"; private static final String GITHUB_BASE = "https://github.com/noties/Markwon/raw/master/";

View File

@ -7,8 +7,8 @@ import ru.noties.markwon.SpannableFactoryDef;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.image.ImageSize; import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.image.ImageSizeResolver; import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.spans.AsyncDrawableSpan; import ru.noties.markwon.core.spans.AsyncDrawableSpan;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
public class GifAwareSpannableFactory extends SpannableFactoryDef { public class GifAwareSpannableFactory extends SpannableFactoryDef {

View File

@ -9,7 +9,7 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import pl.droidsonroids.gif.GifDrawable; import pl.droidsonroids.gif.GifDrawable;
import ru.noties.markwon.spans.AsyncDrawableSpan; import ru.noties.markwon.core.spans.AsyncDrawableSpan;
public abstract class GifProcessor { public abstract class GifProcessor {

View File

@ -7,7 +7,7 @@ import android.support.annotation.NonNull;
import android.text.Layout; import android.text.Layout;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.utils.LeadingMarginUtils; import ru.noties.markwon.utils.LeadingMarginUtils;
/** /**

View File

@ -5,7 +5,6 @@ import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import ru.noties.markwon.SyntaxHighlight;
import ru.noties.prism4j.Prism4j; import ru.noties.prism4j.Prism4j;
public class Prism4jSyntaxHighlight implements SyntaxHighlight { public class Prism4jSyntaxHighlight implements SyntaxHighlight {

View File

@ -6,8 +6,8 @@ import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import ru.noties.markwon.spans.EmphasisSpan; import ru.noties.markwon.core.spans.EmphasisSpan;
import ru.noties.markwon.spans.StrongEmphasisSpan; import ru.noties.markwon.core.spans.StrongEmphasisSpan;
public class Prism4jThemeDarkula extends Prism4jThemeBase { public class Prism4jThemeDarkula extends Prism4jThemeBase {

View File

@ -7,8 +7,8 @@ import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.BackgroundColorSpan; import android.text.style.BackgroundColorSpan;
import ru.noties.markwon.spans.EmphasisSpan; import ru.noties.markwon.core.spans.EmphasisSpan;
import ru.noties.markwon.spans.StrongEmphasisSpan; import ru.noties.markwon.core.spans.StrongEmphasisSpan;
public class Prism4jThemeDefault extends Prism4jThemeBase { public class Prism4jThemeDefault extends Prism4jThemeBase {

View File

@ -5,7 +5,7 @@ import android.support.annotation.Nullable;
import ru.noties.markwon.AbstractMarkwonPlugin; import ru.noties.markwon.AbstractMarkwonPlugin;
import ru.noties.markwon.MarkwonConfiguration; import ru.noties.markwon.MarkwonConfiguration;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.prism4j.Prism4j; import ru.noties.prism4j.Prism4j;
public class SyntaxHighlightPlugin extends AbstractMarkwonPlugin { public class SyntaxHighlightPlugin extends AbstractMarkwonPlugin {

View File

@ -4,7 +4,7 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import ru.noties.markwon.MarkwonConfiguration; import ru.noties.markwon.MarkwonConfiguration;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.view.IMarkwonView; import ru.noties.markwon.view.IMarkwonView;
public class DebugConfigurationProvider implements IMarkwonView.ConfigurationProvider { public class DebugConfigurationProvider implements IMarkwonView.ConfigurationProvider {

View File

@ -60,7 +60,7 @@ public class MarkwonViewHelper implements IMarkwonView {
this.provider = provider; this.provider = provider;
this.configuration = provider.provide(textView.getContext()); this.configuration = provider.provide(textView.getContext());
if (!TextUtils.isEmpty(markdown)) { if (!TextUtils.isEmpty(markdown)) {
// invalidate rendered toMarkdown // invalidate rendered markdown
setMarkdown(markdown); setMarkdown(markdown);
} }
} }

View File

@ -7,7 +7,7 @@ import org.commonmark.node.Node;
import org.commonmark.parser.Parser; import org.commonmark.parser.Parser;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
public abstract class AbstractMarkwonPlugin implements MarkwonPlugin { public abstract class AbstractMarkwonPlugin implements MarkwonPlugin {
@Override @Override

View File

@ -9,7 +9,7 @@ import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import ru.noties.markwon.spans.LinkSpan; import ru.noties.markwon.core.spans.LinkSpan;
public class LinkResolverDef implements LinkSpan.Resolver { public class LinkResolverDef implements LinkSpan.Resolver {
@Override @Override

View File

@ -11,7 +11,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
class MarkwonBuilderImpl implements Markwon.Builder { class MarkwonBuilderImpl implements Markwon.Builder {

View File

@ -3,11 +3,15 @@ package ru.noties.markwon;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.core.spans.LinkSpan;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.image.ImageSizeResolver; import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.image.ImageSizeResolverDef; import ru.noties.markwon.image.ImageSizeResolverDef;
import ru.noties.markwon.spans.LinkSpan; import ru.noties.markwon.syntax.SyntaxHighlight;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.syntax.SyntaxHighlightNoOp;
import ru.noties.markwon.urlprocessor.UrlProcessor;
import ru.noties.markwon.urlprocessor.UrlProcessorNoOp;
/** /**
* since 3.0.0 renamed `SpannableConfiguration` -&gt; `MarkwonConfiguration` * since 3.0.0 renamed `SpannableConfiguration` -&gt; `MarkwonConfiguration`
@ -27,7 +31,6 @@ public class MarkwonConfiguration {
return new Builder(context); return new Builder(context);
} }
private final MarkwonTheme theme; private final MarkwonTheme theme;
private final AsyncDrawableLoader asyncDrawableLoader; private final AsyncDrawableLoader asyncDrawableLoader;
private final SyntaxHighlight syntaxHighlight; private final SyntaxHighlight syntaxHighlight;
@ -46,14 +49,6 @@ public class MarkwonConfiguration {
this.factory = builder.factory; this.factory = builder.factory;
} }
/**
* Returns a new builder based on this configuration
*/
@NonNull
public Builder newBuilder(@NonNull Context context) {
return new Builder(context, this);
}
@NonNull @NonNull
public MarkwonTheme theme() { public MarkwonTheme theme() {
return theme; return theme;
@ -106,17 +101,6 @@ public class MarkwonConfiguration {
this.context = context; this.context = context;
} }
Builder(@NonNull Context context, @NonNull MarkwonConfiguration configuration) {
this(context);
this.theme = configuration.theme;
this.asyncDrawableLoader = configuration.asyncDrawableLoader;
this.syntaxHighlight = configuration.syntaxHighlight;
this.linkResolver = configuration.linkResolver;
this.urlProcessor = configuration.urlProcessor;
this.imageSizeResolver = configuration.imageSizeResolver;
this.factory = configuration.factory;
}
@NonNull @NonNull
public Builder syntaxHighlight(@NonNull SyntaxHighlight syntaxHighlight) { public Builder syntaxHighlight(@NonNull SyntaxHighlight syntaxHighlight) {
this.syntaxHighlight = syntaxHighlight; this.syntaxHighlight = syntaxHighlight;

View File

@ -7,7 +7,7 @@ import org.commonmark.node.Node;
import org.commonmark.parser.Parser; import org.commonmark.parser.Parser;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
public interface MarkwonPlugin { public interface MarkwonPlugin {

View File

@ -6,7 +6,7 @@ import android.support.annotation.Nullable;
import org.commonmark.node.Node; import org.commonmark.node.Node;
import org.commonmark.node.Visitor; import org.commonmark.node.Visitor;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
public interface MarkwonVisitor extends Visitor { public interface MarkwonVisitor extends Visitor {

View File

@ -31,7 +31,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
class MarkwonVisitorImpl implements MarkwonVisitor { class MarkwonVisitorImpl implements MarkwonVisitor {
@ -43,7 +43,7 @@ class MarkwonVisitorImpl implements MarkwonVisitor {
private final SpannableBuilder builder = new SpannableBuilder(); private final SpannableBuilder builder = new SpannableBuilder();
private MarkwonVisitorImpl( MarkwonVisitorImpl(
@NonNull MarkwonConfiguration configuration, @NonNull MarkwonConfiguration configuration,
@NonNull Map<Class<? extends Node>, NodeVisitor<? extends Node>> nodes) { @NonNull Map<Class<? extends Node>, NodeVisitor<? extends Node>> nodes) {
this.configuration = configuration; this.configuration = configuration;

View File

@ -6,8 +6,8 @@ import android.support.annotation.Nullable;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.image.ImageSize; import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.image.ImageSizeResolver; import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.spans.LinkSpan; import ru.noties.markwon.core.spans.LinkSpan;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
/** /**
* Each method can return null or a Span object or an array of spans * Each method can return null or a Span object or an array of spans

View File

@ -7,17 +7,17 @@ import ru.noties.markwon.image.AsyncDrawable;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.image.ImageSize; import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.image.ImageSizeResolver; import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.spans.AsyncDrawableSpan; import ru.noties.markwon.core.spans.AsyncDrawableSpan;
import ru.noties.markwon.spans.BlockQuoteSpan; import ru.noties.markwon.core.spans.BlockQuoteSpan;
import ru.noties.markwon.spans.BulletListItemSpan; import ru.noties.markwon.core.spans.BulletListItemSpan;
import ru.noties.markwon.spans.CodeSpan; import ru.noties.markwon.core.spans.CodeSpan;
import ru.noties.markwon.spans.EmphasisSpan; import ru.noties.markwon.core.spans.EmphasisSpan;
import ru.noties.markwon.spans.HeadingSpan; import ru.noties.markwon.core.spans.HeadingSpan;
import ru.noties.markwon.spans.LinkSpan; import ru.noties.markwon.core.spans.LinkSpan;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.spans.OrderedListItemSpan; import ru.noties.markwon.core.spans.OrderedListItemSpan;
import ru.noties.markwon.spans.StrongEmphasisSpan; import ru.noties.markwon.core.spans.StrongEmphasisSpan;
import ru.noties.markwon.spans.ThematicBreakSpan; import ru.noties.markwon.core.spans.ThematicBreakSpan;
/** /**
* @since 1.1.0 * @since 1.1.0

View File

@ -36,7 +36,7 @@ import ru.noties.markwon.core.visitor.SoftLineBreakNodeVisitor;
import ru.noties.markwon.core.visitor.StrongEmphasisNodeVisitor; import ru.noties.markwon.core.visitor.StrongEmphasisNodeVisitor;
import ru.noties.markwon.core.visitor.TextNodeVisitor; import ru.noties.markwon.core.visitor.TextNodeVisitor;
import ru.noties.markwon.core.visitor.ThematicBreakNodeVisitor; import ru.noties.markwon.core.visitor.ThematicBreakNodeVisitor;
import ru.noties.markwon.spans.OrderedListItemSpan; import ru.noties.markwon.core.spans.OrderedListItemSpan;
public class CorePlugin extends AbstractMarkwonPlugin { public class CorePlugin extends AbstractMarkwonPlugin {

View File

@ -1,9 +1,8 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core;
import android.content.Context; import android.content.Context;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.FloatRange; import android.support.annotation.FloatRange;
import android.support.annotation.IntRange; import android.support.annotation.IntRange;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -12,6 +12,7 @@ import android.text.style.ReplacementSpan;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.image.AsyncDrawable; import ru.noties.markwon.image.AsyncDrawable;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -7,6 +7,8 @@ import android.support.annotation.NonNull;
import android.text.Layout; import android.text.Layout;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import ru.noties.markwon.core.MarkwonTheme;
public class BlockQuoteSpan implements LeadingMarginSpan { public class BlockQuoteSpan implements LeadingMarginSpan {
private final MarkwonTheme theme; private final MarkwonTheme theme;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -9,6 +9,7 @@ import android.support.annotation.NonNull;
import android.text.Layout; import android.text.Layout;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.utils.LeadingMarginUtils; import ru.noties.markwon.utils.LeadingMarginUtils;
public class BulletListItemSpan implements LeadingMarginSpan { public class BulletListItemSpan implements LeadingMarginSpan {

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -9,6 +9,8 @@ import android.text.TextPaint;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import android.text.style.MetricAffectingSpan; import android.text.style.MetricAffectingSpan;
import ru.noties.markwon.core.MarkwonTheme;
public class CodeSpan extends MetricAffectingSpan implements LeadingMarginSpan { public class CodeSpan extends MetricAffectingSpan implements LeadingMarginSpan {
private final MarkwonTheme theme; private final MarkwonTheme theme;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.MetricAffectingSpan; import android.text.style.MetricAffectingSpan;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -10,6 +10,7 @@ import android.text.TextPaint;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import android.text.style.MetricAffectingSpan; import android.text.style.MetricAffectingSpan;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.utils.LeadingMarginUtils; import ru.noties.markwon.utils.LeadingMarginUtils;
public class HeadingSpan extends MetricAffectingSpan implements LeadingMarginSpan { public class HeadingSpan extends MetricAffectingSpan implements LeadingMarginSpan {

View File

@ -1,10 +1,12 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.view.View; import android.view.View;
import ru.noties.markwon.core.MarkwonTheme;
public class LinkSpan extends URLSpan { public class LinkSpan extends URLSpan {
public interface Resolver { public interface Resolver {

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -9,6 +9,7 @@ import android.text.TextPaint;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import android.widget.TextView; import android.widget.TextView;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.utils.LeadingMarginUtils; import ru.noties.markwon.utils.LeadingMarginUtils;
public class OrderedListItemSpan implements LeadingMarginSpan { public class OrderedListItemSpan implements LeadingMarginSpan {
@ -20,8 +21,8 @@ public class OrderedListItemSpan implements LeadingMarginSpan {
* NB, this method must be called <em>before</em> setting text to a TextView (`TextView#setText` * NB, this method must be called <em>before</em> setting text to a TextView (`TextView#setText`
* internally can trigger new Layout creation which will ask for leading margins right away) * internally can trigger new Layout creation which will ask for leading margins right away)
* *
* @param textView to which toMarkdown will be applied * @param textView to which markdown will be applied
* @param text parsed toMarkdown to process * @param text parsed markdown to process
* @since 2.0.1 * @since 2.0.1
*/ */
public static void measure(@NonNull TextView textView, @NonNull CharSequence text) { public static void measure(@NonNull TextView textView, @NonNull CharSequence text) {

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.MetricAffectingSpan; import android.text.style.MetricAffectingSpan;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.core.spans;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
@ -7,6 +7,8 @@ import android.support.annotation.NonNull;
import android.text.Layout; import android.text.Layout;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import ru.noties.markwon.core.MarkwonTheme;
public class ThematicBreakSpan implements LeadingMarginSpan { public class ThematicBreakSpan implements LeadingMarginSpan {
private final MarkwonTheme theme; private final MarkwonTheme theme;

View File

@ -15,7 +15,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import ru.noties.markwon.renderer.R; import ru.noties.markwon.renderer.R;
import ru.noties.markwon.spans.AsyncDrawableSpan; import ru.noties.markwon.core.spans.AsyncDrawableSpan;
public abstract class AsyncDrawableScheduler { public abstract class AsyncDrawableScheduler {

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.syntax;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;

View File

@ -1,9 +1,9 @@
package ru.noties.markwon; package ru.noties.markwon.syntax;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
class SyntaxHighlightNoOp implements SyntaxHighlight { public class SyntaxHighlightNoOp implements SyntaxHighlight {
@NonNull @NonNull
@Override @Override
public CharSequence highlight(@Nullable String info, @NonNull String code) { public CharSequence highlight(@Nullable String info, @NonNull String code) {

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;

View File

@ -3,8 +3,6 @@ package ru.noties.markwon.utils;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import ru.noties.markwon.spans.MarkwonTheme;
public class Dip { public class Dip {
@NonNull @NonNull

View File

@ -0,0 +1,16 @@
package ru.noties.markwon;
import android.support.annotation.NonNull;
import org.commonmark.node.Node;
import java.util.Map;
public class AbstractMarkwonVisitorImpl extends MarkwonVisitorImpl {
public AbstractMarkwonVisitorImpl(
@NonNull MarkwonConfiguration configuration,
@NonNull Map<Class<? extends Node>, NodeVisitor<? extends Node>> nodes) {
super(configuration, nodes);
}
}

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.spans; package ru.noties.markwon.image;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
@ -13,10 +13,6 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import ru.noties.markwon.renderer.ImageSize;
import ru.noties.markwon.renderer.ImageSizeResolver;
import ru.noties.markwon.renderer.ImageSizeResolverDef;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -40,7 +36,7 @@ public class AsyncDrawableTest {
// when drawable have no known dimensions yet, it will await for them // when drawable have no known dimensions yet, it will await for them
final AsyncDrawable drawable = new AsyncDrawable("", final AsyncDrawable drawable = new AsyncDrawable("",
mock(AsyncDrawable.Loader.class), mock(AsyncDrawableLoader.class),
imageSizeResolver, imageSizeResolver,
new ImageSize(new ImageSize.Dimension(100.F, "%"), null)); new ImageSize(new ImageSize.Dimension(100.F, "%"), null));
@ -65,7 +61,7 @@ public class AsyncDrawableTest {
// when result is present it will be detached (setCallback(null)) // when result is present it will be detached (setCallback(null))
final AsyncDrawable drawable = new AsyncDrawable("", final AsyncDrawable drawable = new AsyncDrawable("",
mock(AsyncDrawable.Loader.class), mock(AsyncDrawableLoader.class),
imageSizeResolver, imageSizeResolver,
null); null);

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.renderer; package ru.noties.markwon.image;
import android.graphics.Rect; import android.graphics.Rect;

View File

@ -1,53 +0,0 @@
package ru.noties.markwon.renderer;
import org.junit.Test;
import ru.noties.markwon.MarkwonConfiguration;
import ru.noties.markwon.SpannableFactory;
import ru.noties.markwon.SyntaxHighlight;
import ru.noties.markwon.UrlProcessor;
import ru.noties.markwon.html.api.MarkwonHtmlParser;
import ru.noties.markwon.html.MarkwonHtmlRenderer;
import ru.noties.markwon.image.AsyncDrawable;
import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.spans.LinkSpan;
import ru.noties.markwon.spans.MarkwonTheme;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
public class MarkwonConfigurationTest {
@Test
public void testNewBuilder() {
final MarkwonConfiguration configuration = MarkwonConfiguration
.builder(null)
.theme(mock(MarkwonTheme.class))
.asyncDrawableLoader(mock(AsyncDrawable.Loader.class))
.syntaxHighlight(mock(SyntaxHighlight.class))
.linkResolver(mock(LinkSpan.Resolver.class))
.urlProcessor(mock(UrlProcessor.class))
.imageSizeResolver(mock(ImageSizeResolver.class))
.factory(mock(SpannableFactory.class))
.softBreakAddsNewLine(true)
.htmlParser(mock(MarkwonHtmlParser.class))
.htmlRenderer(mock(MarkwonHtmlRenderer.class))
.htmlAllowNonClosedTags(true)
.build();
final MarkwonConfiguration newConfiguration = configuration
.newBuilder(null)
.build();
assertEquals(configuration.theme(), newConfiguration.theme());
assertEquals(configuration.asyncDrawableLoader(), newConfiguration.asyncDrawableLoader());
assertEquals(configuration.syntaxHighlight(), newConfiguration.syntaxHighlight());
assertEquals(configuration.linkResolver(), newConfiguration.linkResolver());
assertEquals(configuration.urlProcessor(), newConfiguration.urlProcessor());
assertEquals(configuration.imageSizeResolver(), newConfiguration.imageSizeResolver());
assertEquals(configuration.factory(), newConfiguration.factory());
assertEquals(configuration.softBreakAddsNewLine(), newConfiguration.softBreakAddsNewLine());
assertEquals(configuration.htmlParser(), newConfiguration.htmlParser());
assertEquals(configuration.htmlRenderer(), newConfiguration.htmlRenderer());
assertEquals(configuration.htmlAllowNonClosedTags(), newConfiguration.htmlAllowNonClosedTags());
}
}

View File

@ -1,239 +0,0 @@
package ru.noties.markwon.renderer.html2;
import android.support.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ix.Ix;
import ix.IxFunction;
import ru.noties.markwon.test.TestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static ru.noties.markwon.test.TestUtils.with;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class CssInlineStyleParserTest {
private CssInlineStyleParser.Impl impl;
@Before
public void before() {
impl = new CssInlineStyleParser.Impl();
}
@Test
public void simple_single_pair() {
final String input = "key: value;";
final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key());
assertEquals("value", cssProperty.value());
}
});
}
@Test
public void simple_two_pairs() {
final String input = "key1: value1; key2: value2;";
final List<CssProperty> list = listProperties(input);
assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key());
assertEquals("value1", cssProperty.value());
}
});
with(list.get(1), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key2", cssProperty.key());
assertEquals("value2", cssProperty.value());
}
});
}
@Test
public void one_pair_eof() {
final String input = "key: value";
final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key());
assertEquals("value", cssProperty.value());
}
});
}
@Test
public void one_pair_eof_whitespaces() {
final String input = "key: value \n\n\t";
final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key());
assertEquals("value", cssProperty.value());
}
});
}
@Test
public void white_spaces() {
final String input = "\n\n\n\t \t key1 \n\n\n\t : \n\n\n\n \t value1 \n\n\n\n ; \n key2\n : \n value2 \n ; ";
final List<CssProperty> list = listProperties(input);
assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key());
assertEquals("value1", cssProperty.value());
}
});
with(list.get(1), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key2", cssProperty.key());
assertEquals("value2", cssProperty.value());
}
});
}
@Test
public void list_of_keys() {
final String input = "key1 key2 key3 key4";
final List<CssProperty> list = listProperties(input);
assertEquals(0, list.size());
}
@Test
public void list_of_keys_and_value() {
final String input = "key1 key2 key3 key4: value4";
final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key4", cssProperty.key());
assertEquals("value4", cssProperty.value());
}
});
}
@Test
public void list_of_keys_separated_by_semi_colon() {
final String input = "key1;key2;key3;key4;";
final List<CssProperty> list = listProperties(input);
assertEquals(0, list.size());
}
@Test
public void key_value_with_invalid_between() {
final String input = "key1: value1; key2 key3: value3;";
final List<CssProperty> list = listProperties(input);
assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key());
assertEquals("value1", cssProperty.value());
}
});
with(list.get(1), new TestUtils.Action<CssProperty>() {
@Override
public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key3", cssProperty.key());
assertEquals("value3", cssProperty.value());
}
});
}
@Test
public void css_functions() {
final Map<String, String> map = new HashMap<String, String>() {{
put("attr", "\" (\" attr(href) \")\"");
put("calc", "calc(100% - 100px)");
put("cubic-bezier", "cubic-bezier(0.1, 0.7, 1.0, 0.1)");
put("hsl", "hsl(120,100%,50%)");
put("hsla", "hsla(120,100%,50%,0.3)");
put("linear-gradient", "linear-gradient(red, yellow, blue)");
put("radial-gradient", "radial-gradient(red, green, blue)");
put("repeating-linear-gradient", "repeating-linear-gradient(red, yellow 10%, green 20%)");
put("repeating-radial-gradient", "repeating-radial-gradient(red, yellow 10%, green 15%)");
put("rgb", "rgb(255,0,0)");
put("rgba", "rgba(255,0,0,0.3)");
put("var", "var(--some-variable)");
put("url", "url(\"url.gif\")");
}};
final StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> entry: map.entrySet()) {
builder.append(entry.getKey())
.append(':')
.append(entry.getValue())
.append(';');
}
for (CssProperty cssProperty: impl.parse(builder.toString())) {
final String value = map.remove(cssProperty.key());
assertNotNull(cssProperty.key(), value);
assertEquals(cssProperty.key(), value, cssProperty.value());
}
assertEquals(0, map.size());
}
@NonNull
private List<CssProperty> listProperties(@NonNull String input) {
return Ix.from(impl.parse(input))
.map(new IxFunction<CssProperty, CssProperty>() {
@Override
public CssProperty apply(CssProperty cssProperty) {
return cssProperty.mutate();
}
})
.toList();
}
}

View File

@ -1,186 +0,0 @@
package ru.noties.markwon.renderer.html2.tag;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.renderer.html2.CssInlineStyleParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ImageSizeParserImplTest {
private static final float DELTA = 1e-7F;
private ImageSizeParserImpl impl;
@Before
public void before() {
impl = new ImageSizeParserImpl(CssInlineStyleParser.create());
}
@Test
public void nothing() {
assertNull(impl.parse(Collections.<String, String>emptyMap()));
}
@Test
public void width_height_from_style() {
final String style = "width: 123; height: 321";
assertImageSize(
new ImageSize(dimension(123, null), dimension(321, null)),
impl.parse(Collections.singletonMap("style", style))
);
}
@Test
public void style_has_higher_priority_width() {
// if property is found in styles, do not lookup raw attribute
final Map<String, String> attributes = new HashMap<String, String>() {{
put("style", "width: 43");
put("width", "991");
}};
assertImageSize(
new ImageSize(dimension(43, null), null),
impl.parse(attributes)
);
}
@Test
public void style_has_higher_priority_height() {
// if property is found in styles, do not lookup raw attribute
final Map<String, String> attributes = new HashMap<String, String>() {{
put("style", "height: 177");
put("height", "8");
}};
assertImageSize(
new ImageSize(null, dimension(177, null)),
impl.parse(attributes)
);
}
@Test
public void width_style_height_attributes() {
final Map<String, String> attributes = new HashMap<String, String>() {{
put("style", "width: 99");
put("height", "7");
}};
assertImageSize(
new ImageSize(dimension(99, null), dimension(7, null)),
impl.parse(attributes)
);
}
@Test
public void height_style_width_attributes() {
final Map<String, String> attributes = new HashMap<String, String>() {{
put("style", "height: 15");
put("width", "88");
}};
assertImageSize(
new ImageSize(dimension(88, null), dimension(15, null)),
impl.parse(attributes)
);
}
@Test
public void non_empty_styles_width_height_attributes() {
final Map<String, String> attributes = new HashMap<String, String>() {{
put("style", "key1: value1; width0: 123; height0: 99");
put("width", "40");
put("height", "77");
}};
assertImageSize(
new ImageSize(dimension(40, null), dimension(77, null)),
impl.parse(attributes)
);
}
@Test
public void dimension_units() {
final Map<String, ImageSize.Dimension> map = new HashMap<String, ImageSize.Dimension>() {{
put("100", dimension(100, null));
put("100%", dimension(100, "%"));
put("1%", dimension(1, "%"));
put("0.2em", dimension(0.2F, "em"));
put("155px", dimension(155, "px"));
put("67blah", dimension(67, "blah"));
put("-1", dimension(-1, null));
put("-0.01pt", dimension(-0.01F, "pt"));
}};
for (Map.Entry<String, ImageSize.Dimension> entry : map.entrySet()) {
assertDimension(entry.getKey(), entry.getValue(), impl.dimension(entry.getKey()));
}
}
@Test
public void bad_dimension() {
final String[] dimensions = {
"calc(5px + 10rem)",
"whataver6",
"165 165",
"!@#$%^&*(%"
};
for (String dimension: dimensions) {
assertNull(dimension, impl.dimension(dimension));
}
}
private static void assertImageSize(@Nullable ImageSize expected, @Nullable ImageSize actual) {
if (expected == null) {
assertNull(actual);
} else {
assertNotNull(actual);
assertDimension("width", expected.width, actual.width);
assertDimension("height", expected.height, actual.height);
}
}
private static void assertDimension(
@NonNull String name,
@Nullable ImageSize.Dimension expected,
@Nullable ImageSize.Dimension actual) {
if (expected == null) {
assertNull(name, actual);
} else {
assertNotNull(name, actual);
assertEquals(name, expected.value, actual.value, DELTA);
assertEquals(name, expected.unit, actual.unit);
}
}
@NonNull
private static ImageSize.Dimension dimension(float value, @Nullable String unit) {
return new ImageSize.Dimension(value, unit);
}
}

View File

@ -1,25 +1,23 @@
package ru.noties.markwon.renderer.visitor; package ru.noties.markwon.renderer.visitor;
import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import org.commonmark.node.Node;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner; import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import ru.noties.markwon.LinkResolverDef; import ru.noties.markwon.AbstractMarkwonPlugin;
import ru.noties.markwon.Markwon; import ru.noties.markwon.Markwon;
import ru.noties.markwon.MarkwonConfiguration; import ru.noties.markwon.MarkwonConfiguration;
import ru.noties.markwon.SpannableBuilder; import ru.noties.markwon.core.CorePlugin;
import ru.noties.markwon.SpannableFactory; import ru.noties.markwon.image.ImagesPlugin;
import ru.noties.markwon.html.api.MarkwonHtmlParser;
import ru.noties.markwon.renderer.SpannableMarkdownVisitor;
import ru.noties.markwon.spans.MarkwonTheme;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -43,14 +41,11 @@ public class SpannableMarkdownVisitorTest {
public void test() { public void test() {
final TestData data = TestDataReader.readTest(file); final TestData data = TestDataReader.readTest(file);
final Markwon markwon = markwon(data.config());
final MarkwonConfiguration configuration = configuration(data.config()); // okay we must thing about it... casting?
final SpannableBuilder builder = new SpannableBuilder(); final SpannableStringBuilder stringBuilder = (SpannableStringBuilder) markwon.toMarkdown(data.input());
final SpannableMarkdownVisitor visitor = new SpannableMarkdownVisitor(configuration, builder);
final Node node = Markwon.createParser().parse(data.input());
node.accept(visitor);
final SpannableStringBuilder stringBuilder = builder.spannableStringBuilder();
final TestValidator validator = TestValidator.create(file); final TestValidator validator = TestValidator.create(file);
@ -71,25 +66,18 @@ public class SpannableMarkdownVisitorTest {
assertEquals(Arrays.toString(spans), validator.processedSpanNodesCount(), length); assertEquals(Arrays.toString(spans), validator.processedSpanNodesCount(), length);
} }
@SuppressWarnings("ConstantConditions")
@NonNull @NonNull
private MarkwonConfiguration configuration(@NonNull TestConfig config) { private Markwon markwon(@NonNull final TestConfig config) {
return Markwon.builder(RuntimeEnvironment.application)
final SpannableFactory factory = new TestFactory(config.hasOption(TestConfig.USE_PARAGRAPHS)); .use(CorePlugin.create(config.hasOption(TestConfig.SOFT_BREAK_ADDS_NEW_LINE)))
final MarkwonHtmlParser htmlParser = config.hasOption(TestConfig.USE_HTML) .use(ImagesPlugin.create(mock(Context.class)))
? null .use(new AbstractMarkwonPlugin() {
: MarkwonHtmlParser.noOp(); @Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
final boolean softBreakAddsNewLine = config.hasOption(TestConfig.SOFT_BREAK_ADDS_NEW_LINE); builder.factory(new TestFactory(config.hasOption(TestConfig.USE_PARAGRAPHS)));
final boolean htmlAllowNonClosedTags = config.hasOption(TestConfig.HTML_ALLOW_NON_CLOSED_TAGS); }
})
return MarkwonConfiguration.builder(null)
.theme(mock(MarkwonTheme.class))
.linkResolver(mock(LinkResolverDef.class))
.htmlParser(htmlParser)
.factory(factory)
.softBreakAddsNewLine(softBreakAddsNewLine)
.htmlAllowNonClosedTags(htmlAllowNonClosedTags)
.build(); .build();
} }
} }

View File

@ -7,9 +7,9 @@ import java.util.Map;
class TestConfig { class TestConfig {
static final String USE_PARAGRAPHS = "use-paragraphs"; static final String USE_PARAGRAPHS = "use-paragraphs";
static final String USE_HTML = "use-html"; // static final String USE_HTML = "use-html";
static final String SOFT_BREAK_ADDS_NEW_LINE = "soft-break-adds-new-line"; static final String SOFT_BREAK_ADDS_NEW_LINE = "soft-break-adds-new-line";
static final String HTML_ALLOW_NON_CLOSED_TAGS = "html-allow-non-closed-tags"; // static final String HTML_ALLOW_NON_CLOSED_TAGS = "html-allow-non-closed-tags";
private final Map<String, Boolean> map; private final Map<String, Boolean> map;

View File

@ -30,7 +30,6 @@ import java.util.Set;
import ix.Ix; import ix.Ix;
import ix.IxFunction; import ix.IxFunction;
import ix.IxPredicate; import ix.IxPredicate;
import ru.noties.markwon.table.TableRowSpan;
import static ru.noties.markwon.renderer.visitor.TestSpan.BLOCK_QUOTE; import static ru.noties.markwon.renderer.visitor.TestSpan.BLOCK_QUOTE;
import static ru.noties.markwon.renderer.visitor.TestSpan.BULLET_LIST; import static ru.noties.markwon.renderer.visitor.TestSpan.BULLET_LIST;
@ -42,14 +41,8 @@ import static ru.noties.markwon.renderer.visitor.TestSpan.IMAGE;
import static ru.noties.markwon.renderer.visitor.TestSpan.LINK; import static ru.noties.markwon.renderer.visitor.TestSpan.LINK;
import static ru.noties.markwon.renderer.visitor.TestSpan.ORDERED_LIST; import static ru.noties.markwon.renderer.visitor.TestSpan.ORDERED_LIST;
import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH; import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH;
import static ru.noties.markwon.renderer.visitor.TestSpan.STRIKE_THROUGH;
import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS; import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS;
import static ru.noties.markwon.renderer.visitor.TestSpan.SUB_SCRIPT;
import static ru.noties.markwon.renderer.visitor.TestSpan.SUPER_SCRIPT;
import static ru.noties.markwon.renderer.visitor.TestSpan.TABLE_ROW;
import static ru.noties.markwon.renderer.visitor.TestSpan.TASK_LIST;
import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK; import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK;
import static ru.noties.markwon.renderer.visitor.TestSpan.UNDERLINE;
abstract class TestDataReader { abstract class TestDataReader {
@ -103,7 +96,7 @@ abstract class TestDataReader {
static class Reader { static class Reader {
private static final String TEXT = "text"; private static final String TEXT = "text";
private static final String CELLS = "cells"; // private static final String CELLS = "cells";
private static final Set<String> TAGS; private static final Set<String> TAGS;
@ -118,15 +111,9 @@ abstract class TestDataReader {
BULLET_LIST, BULLET_LIST,
THEMATIC_BREAK, THEMATIC_BREAK,
HEADING, HEADING,
STRIKE_THROUGH,
TASK_LIST,
TABLE_ROW,
PARAGRAPH, PARAGRAPH,
IMAGE, IMAGE,
LINK, LINK,
SUPER_SCRIPT,
SUB_SCRIPT,
UNDERLINE,
HEADING + "1", HEADING + "1",
HEADING + "2", HEADING + "2",
HEADING + "3", HEADING + "3",
@ -251,24 +238,27 @@ abstract class TestDataReader {
if (valueElement.isJsonNull()) { if (valueElement.isJsonNull()) {
value = null; value = null;
} else { } else {
// another special case: table cell value = valueElement.getAsString();
// this is not so good
if (CELLS.equals(key)) {
final JsonArray cells = valueElement.getAsJsonArray();
final int length = cells.size();
final List<TableRowSpan.Cell> list = new ArrayList<>(length);
for (int k = 0; k < length; k++) {
final JsonObject cell = cells.get(k).getAsJsonObject();
list.add(new TableRowSpan.Cell(
cell.get("alignment").getAsInt(),
cell.get("text").getAsString()
));
}
value = list.toString();
} else {
value = valueElement.getAsString();
}
} }
// else {
// // another special case: table cell
// // this is not so good
// if (CELLS.equals(key)) {
// final JsonArray cells = valueElement.getAsJsonArray();
// final int length = cells.size();
// final List<TableRowSpan.Cell> list = new ArrayList<>(length);
// for (int k = 0; k < length; k++) {
// final JsonObject cell = cells.get(k).getAsJsonObject();
// list.add(new TableRowSpan.Cell(
// cell.get("alignment").getAsInt(),
// cell.get("text").getAsString()
// ));
// }
// value = list.toString();
// } else {
// value = valueElement.getAsString();
// }
// }
attributes.put(key, value); attributes.put(key, value);
} }
} }

View File

@ -5,16 +5,14 @@ import android.support.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import ru.noties.markwon.SpannableFactory; import ru.noties.markwon.SpannableFactory;
import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.core.spans.LinkSpan;
import ru.noties.markwon.image.AsyncDrawableLoader;
import ru.noties.markwon.image.ImageSize; import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.image.ImageSizeResolver; import ru.noties.markwon.image.ImageSizeResolver;
import ru.noties.markwon.image.AsyncDrawable;
import ru.noties.markwon.spans.LinkSpan;
import ru.noties.markwon.spans.MarkwonTheme;
import ru.noties.markwon.table.TableRowSpan;
import static ru.noties.markwon.renderer.visitor.TestSpan.BLOCK_QUOTE; import static ru.noties.markwon.renderer.visitor.TestSpan.BLOCK_QUOTE;
import static ru.noties.markwon.renderer.visitor.TestSpan.BULLET_LIST; import static ru.noties.markwon.renderer.visitor.TestSpan.BULLET_LIST;
@ -26,14 +24,8 @@ import static ru.noties.markwon.renderer.visitor.TestSpan.IMAGE;
import static ru.noties.markwon.renderer.visitor.TestSpan.LINK; import static ru.noties.markwon.renderer.visitor.TestSpan.LINK;
import static ru.noties.markwon.renderer.visitor.TestSpan.ORDERED_LIST; import static ru.noties.markwon.renderer.visitor.TestSpan.ORDERED_LIST;
import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH; import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH;
import static ru.noties.markwon.renderer.visitor.TestSpan.STRIKE_THROUGH;
import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS; import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS;
import static ru.noties.markwon.renderer.visitor.TestSpan.SUB_SCRIPT;
import static ru.noties.markwon.renderer.visitor.TestSpan.SUPER_SCRIPT;
import static ru.noties.markwon.renderer.visitor.TestSpan.TABLE_ROW;
import static ru.noties.markwon.renderer.visitor.TestSpan.TASK_LIST;
import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK; import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK;
import static ru.noties.markwon.renderer.visitor.TestSpan.UNDERLINE;
class TestFactory implements SpannableFactory { class TestFactory implements SpannableFactory {
@ -94,31 +86,6 @@ class TestFactory implements SpannableFactory {
return new TestSpan(HEADING + level); return new TestSpan(HEADING + level);
} }
@Nullable
@Override
public Object strikethrough() {
return new TestSpan(STRIKE_THROUGH);
}
@Nullable
@Override
public Object taskListItem(@NonNull MarkwonTheme theme, int blockIndent, boolean isDone) {
return new TestSpan(TASK_LIST, map(
Pair.of("blockIdent", blockIndent),
Pair.of("done", isDone)
));
}
@Nullable
@Override
public Object tableRow(@NonNull MarkwonTheme theme, @NonNull List<TableRowSpan.Cell> cells, boolean isHeader, boolean isOdd) {
return new TestSpan(TABLE_ROW, map(
Pair.of("cells", cells),
Pair.of("header", isHeader),
Pair.of("odd", isOdd)
));
}
@Nullable @Nullable
@Override @Override
public Object paragraph(boolean inTightList) { public Object paragraph(boolean inTightList) {
@ -129,7 +96,7 @@ class TestFactory implements SpannableFactory {
@Nullable @Nullable
@Override @Override
public Object image(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull AsyncDrawable.Loader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) { public Object image(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull AsyncDrawableLoader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) {
return new TestSpan(IMAGE, map( return new TestSpan(IMAGE, map(
Pair.of("src", destination), Pair.of("src", destination),
Pair.of("imageSize", imageSize), Pair.of("imageSize", imageSize),
@ -143,24 +110,6 @@ class TestFactory implements SpannableFactory {
return new TestSpan(LINK, map("href", destination)); return new TestSpan(LINK, map("href", destination));
} }
@Nullable
@Override
public Object superScript(@NonNull MarkwonTheme theme) {
return new TestSpan(SUPER_SCRIPT);
}
@Nullable
@Override
public Object subScript(@NonNull MarkwonTheme theme) {
return new TestSpan(SUB_SCRIPT);
}
@Nullable
@Override
public Object underline() {
return new TestSpan(UNDERLINE);
}
@NonNull @NonNull
private static Map<String, String> map(@NonNull String key, @Nullable Object value) { private static Map<String, String> map(@NonNull String key, @Nullable Object value) {
return Collections.singletonMap(key, String.valueOf(value)); return Collections.singletonMap(key, String.valueOf(value));

View File

@ -16,15 +16,15 @@ class TestSpan {
static final String BULLET_LIST = "ul"; static final String BULLET_LIST = "ul";
static final String THEMATIC_BREAK = "hr"; static final String THEMATIC_BREAK = "hr";
static final String HEADING = "h"; static final String HEADING = "h";
static final String STRIKE_THROUGH = "s"; // static final String STRIKE_THROUGH = "s";
static final String TASK_LIST = "task-list"; // static final String TASK_LIST = "task-list";
static final String TABLE_ROW = "tr"; // static final String TABLE_ROW = "tr";
static final String PARAGRAPH = "p"; static final String PARAGRAPH = "p";
static final String IMAGE = "img"; static final String IMAGE = "img";
static final String LINK = "a"; static final String LINK = "a";
static final String SUPER_SCRIPT = "sup"; // static final String SUPER_SCRIPT = "sup";
static final String SUB_SCRIPT = "sub"; // static final String SUB_SCRIPT = "sub";
static final String UNDERLINE = "u"; // static final String UNDERLINE = "u";
private final String name; private final String name;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.renderer; package ru.noties.markwon.syntax;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
@ -8,16 +8,23 @@ import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import org.commonmark.node.FencedCodeBlock; import org.commonmark.node.FencedCodeBlock;
import org.commonmark.node.Node;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import java.util.HashMap;
import java.util.Map;
import ru.noties.markwon.AbstractMarkwonVisitorImpl;
import ru.noties.markwon.MarkwonConfiguration; import ru.noties.markwon.MarkwonConfiguration;
import ru.noties.markwon.MarkwonVisitor;
import ru.noties.markwon.SpannableBuilder; import ru.noties.markwon.SpannableBuilder;
import ru.noties.markwon.SpannableFactory; import ru.noties.markwon.SpannableFactory;
import ru.noties.markwon.SyntaxHighlight; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.visitor.CodeBlockNodeVisitor;
import ru.noties.markwon.image.AsyncDrawableLoader;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -32,6 +39,8 @@ import static org.mockito.Mockito.when;
Build.VERSION_CODES.M, Build.VERSION_CODES.M,
Build.VERSION_CODES.O Build.VERSION_CODES.O
}) })
// although it is called SyntaxHighlightTest all it does is check that spans are in the correct order
// and syntax highlight is the primary user of this functionality
public class SyntaxHighlightTest { public class SyntaxHighlightTest {
// codeSpan must be before actual highlight spans (true reverse of builder) // codeSpan must be before actual highlight spans (true reverse of builder)
@ -68,10 +77,16 @@ public class SyntaxHighlightTest {
final MarkwonConfiguration configuration = MarkwonConfiguration.builder(mock(Context.class)) final MarkwonConfiguration configuration = MarkwonConfiguration.builder(mock(Context.class))
.syntaxHighlight(highlight) .syntaxHighlight(highlight)
.factory(factory) .factory(factory)
.theme(mock(MarkwonTheme.class)) .build(mock(MarkwonTheme.class), mock(AsyncDrawableLoader.class));
.build();
final SpannableBuilder builder = new SpannableBuilder(); final Map<Class<? extends Node>, MarkwonVisitor.NodeVisitor<? extends Node>> visitorMap = new HashMap<>(1);
visitorMap.put(FencedCodeBlock.class, new CodeBlockNodeVisitor.Fenced());
final MarkwonVisitor visitor = new AbstractMarkwonVisitorImpl(
configuration,
visitorMap);
final SpannableBuilder builder = visitor.builder();
append(builder, "# Header 1\n", new Object()); append(builder, "# Header 1\n", new Object());
append(builder, "## Header 2\n", new Object()); append(builder, "## Header 2\n", new Object());
@ -79,11 +94,15 @@ public class SyntaxHighlightTest {
final int start = builder.length(); final int start = builder.length();
final SpannableMarkdownVisitor visitor = new SpannableMarkdownVisitor(configuration, builder);
final FencedCodeBlock fencedCodeBlock = new FencedCodeBlock(); final FencedCodeBlock fencedCodeBlock = new FencedCodeBlock();
fencedCodeBlock.setLiteral("{code}"); fencedCodeBlock.setLiteral("{code}");
visitor.visit(fencedCodeBlock); CodeBlockNodeVisitor.visitCodeBlock(
visitor,
null,
"{code}",
fencedCodeBlock
);
final int end = builder.length(); final int end = builder.length();

View File

@ -1,4 +1,4 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -6,8 +6,10 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import ru.noties.markwon.urlprocessor.UrlProcessorAndroidAssets;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static ru.noties.markwon.UrlProcessorAndroidAssets.BASE; import static ru.noties.markwon.urlprocessor.UrlProcessorAndroidAssets.BASE;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)

View File

@ -1,10 +1,12 @@
package ru.noties.markwon; package ru.noties.markwon.urlprocessor;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import ru.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)

View File

@ -1,15 +1,12 @@
input: |- input: |-
**bold *bold italic ~~bold italic strike `bold italic strike code` bold italic strike~~ bold italic* bold** normal **bold *bold italic `bold italic code` bold italic* bold** normal
output: output:
- b: - b:
- "bold " - "bold "
- i: - i:
- "bold italic " - "bold italic "
- s: - code: "bold italic code"
- "bold italic strike "
- code: "bold italic strike code"
- " bold italic strike"
- " bold italic" - " bold italic"
- " bold" - " bold"
- " normal" - " normal"

View File

@ -1,18 +0,0 @@
input: |-
<i>italic
<b>bold italic
<u>underline bold italic
<s>strike underline bold italic
config:
use-html: true
html-allow-non-closed-tags: true
output:
- i:
- "italic "
- b:
- "bold italic "
- u:
- "underline bold italic "
- s: "strike underline bold italic"

View File

@ -1,12 +0,0 @@
input: |-
<i>no italic here
<b>bold yeah</b>
<u>no underline
config:
use-html: true
output:
- "no italic here "
- b: "bold yeah"
- " no underline"

View File

@ -1,105 +0,0 @@
input: |-
<h1>html</h1>
<h2>emphasis</h2>
<i>i</i><em>em</em><cite>cite</cite><dfn>dfn</dfn>
<h2>strong-emphasis</h2>
<b>b</b><strong>strong</strong>
<h2>super-script</h2>
<sup>sup</sup>
<h2>sub-script</h2>
<sub>sub</sub>
<h2>underline</h2>
<u>u</u><ins>ins</ins>
<h2>strike</h2>
<s>s</s><del>del</del>
<h2>link</h2>
<a href="a://href">a</a>
<h2>unordered-list</h2>
<ul><li>ul1<li>ul2</ul>
<h2>ordered-list</h2>
<ol><li>ol1<li>ol2</ol>
<h2>image</h2>
<img src="img://src" alt="img">
<h2>blockquote</h2>
<blockquote>blockquote</blockquote>
<h3>3</h3>
<h4>4</h4>
<h5>5</h5>
<h6>6</h6>
config:
use-html: true
output:
- h1: "html"
- "\n"
- h2: "emphasis"
- "\n"
- i: "i"
- i: "em"
- i: "cite"
- i: "dfn"
- "\n"
- h2: "strong-emphasis"
- "\n"
- b: "b"
- b: "strong"
- "\n"
- h2: "super-script"
- "\n"
- sup: "sup"
- "\n"
- h2: "sub-script"
- "\n"
- sub: "sub"
- "\n"
- h2: "underline"
- "\n"
- u: "u"
- u: "ins"
- "\n"
- h2: "strike"
- "\n"
- s: "s"
- s: "del"
- "\n"
- h2: "link"
- "\n"
- a: "a"
href: "a://href"
- "\n"
- h2: "unordered-list"
- "\n"
- ul: "ul1"
level: 0
- "\n"
- ul: "ul2"
level: 0
- "\n"
- h2: "ordered-list"
- "\n"
- ol: "ol1"
start: 1
- "\n"
- ol: "ol2"
start: 2
- "\n"
- h2: "image"
- "\n"
- img: "img"
src: "img://src"
imageSize: null
replacementTextIsLink: false
- "\n"
- h2: "blockquote"
- "\n"
- blockquote: "blockquote"
- "\n"
- h3: "3"
- "\n"
- h4: "4"
- "\n"
- h5: "5"
- "\n"
- h6: "6"

View File

@ -1,6 +1,5 @@
input: |- input: |-
First **line** is *always* First **line** is *always*
~~strike~~ down
> Some quote here! > Some quote here!
@ -18,9 +17,7 @@ output:
- b: "line" - b: "line"
- text: " is " - text: " is "
- i: "always" - i: "always"
- text: " " - text: "\n\n"
- s: "strike"
- text: " down\n\n"
- blockquote: "Some quote here!" - blockquote: "Some quote here!"
- text: "\n\n" - text: "\n\n"
- h1: "Header 1" - h1: "Header 1"

View File

@ -1,4 +0,0 @@
input: "~~strike~~"
output:
- s: "strike"

View File

@ -1,7 +0,0 @@
input: "<sub>sub</sub>"
config:
use-html: true
output:
- sub: "sub"

View File

@ -1,7 +0,0 @@
input: "<sup>sup</sup>"
config:
use-html: true
output:
- sup: "sup"

View File

@ -1,6 +0,0 @@
input: "- [ ] task-list"
output:
- task-list: "task-list"
blockIdent: 1
done: false

View File

@ -1,13 +0,0 @@
input: "col1|col2|col3\n---|---|---|"
output:
- tr: "\u00a0"
header: true
odd: false
cells:
- alignment: 0
text: "col1"
- alignment: 0
text: "col2"
- alignment: 0
text: "col3"

View File

@ -1,7 +0,0 @@
input: "<u>underline</u>"
config:
use-html: true
output:
- u: "underline"

View File

@ -1,51 +0,0 @@
input: |-
head1|head2|head3
---|:---:|---:
row1-col1|row1-col2|row1-col3
row2-col1|row2-col2|row2-col3
row3-col1|row3-col2|row3-col3
output:
- tr: "\u00a0"
header: true
odd: false
cells:
- alignment: 0
text: "head1"
- alignment: 1
text: "head2"
- alignment: 2
text: "head3"
- text: "\n"
- tr: "\u00a0"
header: false
odd: false
cells:
- alignment: 0
text: "row1-col1"
- alignment: 1
text: "row1-col2"
- alignment: 2
text: "row1-col3"
- text: "\n"
- tr: "\u00a0"
header: false
odd: true
cells:
- alignment: 0
text: "row2-col1"
- alignment: 1
text: "row2-col2"
- alignment: 2
text: "row2-col3"
- text: "\n"
- tr: "\u00a0"
header: false
odd: false
cells:
- alignment: 0
text: "row3-col1"
- alignment: 1
text: "row3-col2"
- alignment: 2
text: "row3-col3"

View File

@ -8,7 +8,7 @@ import android.widget.TextView;
import ru.noties.markwon.AbstractMarkwonPlugin; import ru.noties.markwon.AbstractMarkwonPlugin;
import ru.noties.markwon.Markwon; import ru.noties.markwon.Markwon;
import ru.noties.markwon.spans.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
public class MainActivity extends Activity { public class MainActivity extends Activity {