diff options
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java | 4 | ||||
-rw-r--r-- | markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java | 15 |
2 files changed, 16 insertions, 3 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java index 9305754f..54182475 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java @@ -101,12 +101,12 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa if (darkModeActive) { note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content_dark); note_content.setOnClickFillInIntent(R.id.single_note_content_tv_dark, fillInIntent); - note_content.setTextViewText(R.id.single_note_content_tv_dark, MarkdownUtil.renderForWidget(context, note.getContent())); + note_content.setTextViewText(R.id.single_note_content_tv_dark, MarkdownUtil.renderForRemoteView(context, note.getContent())); } else { note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content); note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent); - note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForWidget(context, note.getContent())); + note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForRemoteView(context, note.getContent())); } return note_content; diff --git a/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java b/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java index 2d5e1adb..b6d04b7d 100644 --- a/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java +++ b/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java @@ -1,12 +1,18 @@ package it.niedermann.android.markdown; import android.content.Context; +import android.text.Spanned; import android.text.TextUtils; +import android.widget.RemoteViews.RemoteView; import androidx.annotation.NonNull; +import androidx.core.text.HtmlCompat; import com.yydcdut.markdown.MarkdownProcessor; import com.yydcdut.markdown.syntax.text.TextFactory; +import com.yydcdut.rxmarkdown.RxMarkdown; + +import io.noties.markwon.Markwon; public class MarkdownUtil { private static final String MD_IMAGE_WITH_EMPTY_DESCRIPTION = "![]("; @@ -18,7 +24,14 @@ public class MarkdownUtil { // Util class } - public static CharSequence renderForWidget(@NonNull Context context, @NonNull CharSequence content) { + /** + * {@link RemoteView}s have a limited subset of supported classes to maintain compatibility with many different launchers. + * <p> + * Since {@link Markwon} makes heavy use of custom spans, this won't look nice e. g. at app widgets, because they simply won't be rendered. + * Therefore we currently fall back on {@link RxMarkdown} as the results will look better in this special case. + * We might change this in the future by utilizing {@link Markwon} and creating a {@link Spanned} from an {@link HtmlCompat} interemediate. + */ + public static CharSequence renderForRemoteView(@NonNull Context context, @NonNull CharSequence content) { final MarkdownProcessor markdownProcessor = new MarkdownProcessor(context); markdownProcessor.factory(TextFactory.create()); return parseCompat(markdownProcessor, content); |