Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove underline for url link #193

Closed
crossle opened this issue Feb 14, 2020 · 12 comments
Closed

How to remove underline for url link #193

crossle opened this issue Feb 14, 2020 · 12 comments
Labels

Comments

@crossle
Copy link

crossle commented Feb 14, 2020

  • Markwon version: 4.2.1

The link style always have underline, how to remove the underline for the link?

@noties
Copy link
Owner

noties commented Feb 14, 2020

Hello @crossle !

There are at least 2 options:

  • override current styling (keep original link span)
  • provide own implementation of span for links

Anyway you start by creating a new plugin:

final Markwon markwon = Markwon.builder(context)
        .usePlugin(new AbstractMarkwonPlugin() {
            @Override
            public void configureSpansFactory(@NonNull MarkwonSpansFactory.Builder builder) {
                final SpanFactory original = builder.getFactory(Link.class);
                if (original != null) {
                    builder.setFactory(Link.class, (configuration, props) -> {
                        // reversed order
                        return new Object[] {
                                new RemoveUnderlineSpan(),
                                original.getSpans(configuration, props)
                        };
                    });
                }

                // or, you can provide own implementation for LinkSpan by calling:
//                builder.setFactory(Link.class, new SpanFactory() {
//                    @Nullable
//                    @Override
//                    public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps props) {
//                        TODO()
//                    }
//                });
            }
        })
        .build();

Please note that the first option needs to return spans in reversed order (added first will be processed last)

public class RemoveUnderlineSpan extends CharacterStyle implements UpdateAppearance {
    @Override
    public void updateDrawState(TextPaint tp) {
        tp.setUnderlineText(false);
    }
}

@crossle
Copy link
Author

crossle commented Feb 14, 2020

Coool, got it. Thanks

@crossle crossle closed this as completed Feb 14, 2020
@noties
Copy link
Owner

noties commented Feb 14, 2020

UPD: in 4.2.2-SNAPSHOT version (which should be soon available), there will be 2 new methods in MarkwonSpansFactory:

  • appendFactory
  • prependFactory

So, taking into consideration these additions, code could be rewritten as:

builder.appendFactory(Link.class, (configuration, props) -> new RemoveUnderlineSpan());

@crossle
Copy link
Author

crossle commented Feb 14, 2020

@noties BTW, RecyclerView does not support GitHub task list format ?

@noties
Copy link
Owner

noties commented Feb 14, 2020

@crossle Markwon supports task lists via ext-tasklist plugin. RecyclerView does not require any special handling for them to be displayed

@crossle
Copy link
Author

crossle commented Feb 14, 2020

@noties OK, thanks.

@crossle
Copy link
Author

crossle commented Feb 14, 2020

@noties Other question, How to support text selection in RecyclerView? I add markdown item TextView add android:textIsSelectable true, but it's conflict with the markdown url link.

@noties
Copy link
Owner

noties commented Feb 15, 2020

@crossle can you please explain the conflict, how is text selection conflicts with links?

@crossle
Copy link
Author

crossle commented Feb 15, 2020

IMG_202016_1738_428743478
I set android:textIsSelectable="true", but the url link does not click, it's just selected.

@noties
Copy link
Owner

noties commented Feb 15, 2020

@crossle the problem might be with the MovementMethod. Markwon will automatically apply one if it's missing after markdown is applied to a TextView. And this works in most cases. Until you have text selection enabled. So here you can try setting MovementMethod before markdown is applied:

// for example in `onCreateHolder`, so this is done once per `TextView`
holder.textView.setMovementMethod(LinkMovementMethod.getInstance());

// then in `onBind` apply your markdown as usual:
markwon.setMarkdown(holder.textView, markdown);

@crossle
Copy link
Author

crossle commented Feb 15, 2020

How to set on recyclerview?

@noties
Copy link
Owner

noties commented Feb 16, 2020

You don't set it on RecyclerView, you set it on the TextView with markdown content inside RecyclerView

@noties noties mentioned this issue Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants