Skip to content

Commit

Permalink
Merge pull request #248 from noties/v4.4.0
Browse files Browse the repository at this point in the history
V4.4.0
  • Loading branch information
noties committed May 19, 2020
2 parents a26c13c + c2c5904 commit 3ab0151
Show file tree
Hide file tree
Showing 54 changed files with 1,757 additions and 211 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

# 4.4.0
* `TextViewSpan` to obtain `TextView` in which markdown is displayed (applied by `CorePlugin`)
* `TextLayoutSpan` to obtain `Layout` in which markdown is displayed (applied by `TablePlugin`, more specifically `TableRowSpan` to propagate layout in which cell content is displayed)
* `HtmlEmptyTagReplacement` now is configurable by `HtmlPlugin`, `iframe` handling ([#235])
* `AsyncDrawable` now uses `TextView` width without padding instead of width of canvas
* Support for images inside table cells (`ext-tables` module)
* Expose `enabledBlockTypes` in `CorePlugin`
* Update `jlatexmath-android` dependency ([#225])
* Update `image-coil` module (Coil version `0.10.1`) ([#244])<br>Thanks to [@tylerbwong]
* Rename `UrlProcessor` to `ImageDestinationProcessor` (`io.noties.markwon.urlprocessor` -&gt; `io.noties.markwon.image.destination`) and limit its usage to process **only** destination URL of images (was used to also process links before)
* `fallbackToRawInputWhenEmpty` `Markwon.Builder` configuration to fallback to raw input if rendered markdown is empty ([#242])

[#235]: https://github.com/noties/Markwon/issues/235
[#225]: https://github.com/noties/Markwon/issues/225
[#244]: https://github.com/noties/Markwon/pull/244
[#242]: https://github.com/noties/Markwon/issues/242
[@tylerbwong]: https://github.com/tylerbwong


# 4.3.1
* Fix DexGuard optimization issue ([#216])<br>Thanks [@francescocervone]
* module `images`: `GifSupport` and `SvgSupport` use `Class.forName` instead access to full qualified class name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import androidx.annotation.NonNull;

import io.noties.markwon.urlprocessor.UrlProcessor;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import io.noties.markwon.image.destination.ImageDestinationProcessor;
import io.noties.markwon.image.destination.ImageDestinationProcessorRelativeToAbsolute;

class UrlProcessorInitialReadme implements UrlProcessor {
class ImageDestinationProcessorInitialReadme extends ImageDestinationProcessor {

private static final String GITHUB_BASE = "https://github.com/noties/Markwon/raw/master/";

private final UrlProcessorRelativeToAbsolute processor
= new UrlProcessorRelativeToAbsolute(GITHUB_BASE);
private final ImageDestinationProcessorRelativeToAbsolute processor
= new ImageDestinationProcessorRelativeToAbsolute(GITHUB_BASE);

@NonNull
@Override
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import io.noties.markwon.ext.tasklist.TaskListPlugin;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.destination.ImageDestinationProcessor;
import io.noties.markwon.image.destination.ImageDestinationProcessorRelativeToAbsolute;
import io.noties.markwon.image.file.FileSchemeHandler;
import io.noties.markwon.image.gif.GifMediaDecoder;
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler;
import io.noties.markwon.syntax.Prism4jTheme;
import io.noties.markwon.syntax.Prism4jThemeDarkula;
import io.noties.markwon.syntax.Prism4jThemeDefault;
import io.noties.markwon.syntax.SyntaxHighlightPlugin;
import io.noties.markwon.urlprocessor.UrlProcessor;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import io.noties.prism4j.Prism4j;

@ActivityScope
Expand Down Expand Up @@ -86,11 +86,11 @@ public void run() {
}

private void execute() {
final UrlProcessor urlProcessor;
final ImageDestinationProcessor imageDestinationProcessor;
if (uri == null) {
urlProcessor = new UrlProcessorInitialReadme();
imageDestinationProcessor = new ImageDestinationProcessorInitialReadme();
} else {
urlProcessor = new UrlProcessorRelativeToAbsolute(uri.toString());
imageDestinationProcessor = new ImageDestinationProcessorRelativeToAbsolute(uri.toString());
}

final Prism4jTheme prism4jTheme = isLightTheme
Expand Down Expand Up @@ -119,7 +119,7 @@ public void configureImages(@NonNull ImagesPlugin plugin) {
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.urlProcessor(urlProcessor);
builder.imageDestinationProcessor(imageDestinationProcessor);
}
})
.build();
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ ext {
'commonmark-table' : "com.atlassian.commonmark:commonmark-ext-gfm-tables:$commonMarkVersion",
'android-svg' : 'com.caverock:androidsvg:1.4',
'android-gif' : 'pl.droidsonroids.gif:android-gif-drawable:1.2.15',
'jlatexmath-android' : 'ru.noties:jlatexmath-android:0.1.1',
'jlatexmath-android' : 'ru.noties:jlatexmath-android:0.2.0',
'okhttp' : 'com.squareup.okhttp3:okhttp:3.9.0',
'prism4j' : 'io.noties:prism4j:2.0.0',
'debug' : 'io.noties:debug:5.0.0@jar',
'adapt' : 'io.noties:adapt:2.0.0',
'dagger' : "com.google.dagger:dagger:$daggerVersion",
'picasso' : 'com.squareup.picasso:picasso:2.71828',
'glide' : 'com.github.bumptech.glide:glide:4.9.0',
'coil' : 'io.coil-kt:coil:0.8.0'
'coil' : 'io.coil-kt:coil:0.10.1'
]

deps['annotationProcessor'] = [
Expand Down
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ and 2 themes included: Light &amp; Dark. It can be downloaded from [releases](ht
## # Awesome Markwon

</div>

<u>Applications using Markwon</u>:

* [Partico](https://partiko.app/) - Partiko is a censorship free social network.
* [FairNote](https://play.google.com/store/apps/details?id=com.rgiskard.fairnote) - simple and intuitive notepad app. It gives you speed and efficiency when you write notes, to-do lists, e-mails, or jot down quick ideas.
* [Boxcryptor](https://www.boxcryptor.com) - A software that adds AES-256 and RSA encryption to Dropbox, Google Drive, OneDrive and many other clouds.
<br>

<AwesomeGroup :apps="[
{name: 'Nextcloud', image: $withBase(`/assets/apps/nextcloud.png`), link: 'https://github.com/nextcloud/android', description: 'A safe home for all your data. Access & share your files, calendars, contacts, mail & more from any device, on your terms.'},
Expand All @@ -113,6 +108,11 @@ and 2 themes included: Light &amp; Dark. It can be downloaded from [releases](ht
{name: 'Pure Writer', image: $withBase(`/assets/apps/purewriter.png`), link: 'https://play.google.com/store/apps/details?id=com.drakeet.purewriter', description: 'Never lose content editor & Markdown'}
]" />

* [Partico](https://partiko.app/) - Partiko is a censorship free social network.
* [FairNote](https://play.google.com/store/apps/details?id=com.rgiskard.fairnote) - simple and intuitive notepad app. It gives you speed and efficiency when you write notes, to-do lists, e-mails, or jot down quick ideas.
* [Boxcryptor](https://www.boxcryptor.com) - A software that adds AES-256 and RSA encryption to Dropbox, Google Drive, OneDrive and many other clouds.
* [Senstone Portable Voice Assistant](https://play.google.com/store/apps/details?id=com.senstone) - Senstone is a tiny wearable personal assistant powered by this App. It lets you capture your ideas, notes and reminders handsfree without pulling out your phone.


<u>Extension/plugins</u>:

Expand Down
27 changes: 14 additions & 13 deletions docs/docs/v4/core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ These are _configurable_ properties:
* `AsyncDrawableLoader` (back here since <Badge text="4.0.0" />)
* `SyntaxHighlight`
* `LinkResolver` (since <Badge text="4.0.0" />, before &mdash; `LinkSpan.Resolver`)
* `UrlProcessor`
* `ImageDestinationProcessor` (since <Badge text="4.4.0" />, before &mdash; `UrlProcessor`)
* `ImageSizeResolver`

:::tip
Expand Down Expand Up @@ -36,10 +36,11 @@ final Markwon markwon = Markwon.builder(context)
.build();
```

Currently `Markwon` provides 3 implementations for loading images:
Currently `Markwon` provides 4 implementations for loading images:
* [markwon implementation](/docs/v4/image/) with SVG, GIF, data uri and android_assets support
* [based on Picasso](/docs/v4/image-picasso/)
* [based on Glide](/docs/v4/image-glide/)
* [base on Coil](/docs/v4/image-coil/)

## SyntaxHighlight

Expand Down Expand Up @@ -87,32 +88,32 @@ if there is none registered. if you wish to register own instance of a `Movement
apply it directly to a TextView or use [MovementMethodPlugin](/docs/v4/core/movement-method-plugin.md)
:::

## UrlProcessor
## ImageDestinationProcessor

Process URLs in your markdown (for links and images). If not provided explicitly,
Process destinations (URLs) of images in your markdown. If not provided explicitly,
default **no-op** implementation will be used, which does not modify URLs (keeping them as-is).

`Markwon` provides 2 implementations of `UrlProcessor`:
* `UrlProcessorRelativeToAbsolute`
* `UrlProcessorAndroidAssets`
* `ImageDestinationProcessorRelativeToAbsolute`
* `ImageDestinationProcessorAssets`

### UrlProcessorRelativeToAbsolute
### ImageDestinationProcessorRelativeToAbsolute

`UrlProcessorRelativeToAbsolute` can be used to make relative URL absolute. For example if an image is
defined like this: `![img](./art/image.JPG)` and `UrlProcessorRelativeToAbsolute`
`ImageDestinationProcessorRelativeToAbsolute` can be used to make relative URL absolute. For example if an image is
defined like this: `![img](./art/image.JPG)` and `ImageDestinationProcessorRelativeToAbsolute`
is created with `https://github.com/noties/Markwon/raw/master/` as the base:
`new UrlProcessorRelativeToAbsolute("https://github.com/noties/Markwon/raw/master/")`,
`new ImageDestinationProcessorRelativeToAbsolute("https://github.com/noties/Markwon/raw/master/")`,
then final image will have `https://github.com/noties/Markwon/raw/master/art/image.JPG`
as the destination.

### UrlProcessorAndroidAssets
### ImageDestinationProcessorAssets

`UrlProcessorAndroidAssets` can be used to make processed links to point to Android assets folder.
`ImageDestinationProcessorAssets` can be used to make processed destinations to point to Android assets folder.
So an image: `![img](./art/image.JPG)` will have `file:///android_asset/art/image.JPG` as the
destination.

:::tip
Please note that `UrlProcessorAndroidAssets` will process only URLs that have no `scheme` information,
Please note that `ImageDestinationProcessorAssets` will process only URLs that have no `scheme` information,
so a `./art/image.png` will become `file:///android_asset/art/image.JPG` whilst `https://so.me/where.png`
will be kept as-is.
:::
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android.enableJetifier=true
android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache

VERSION_NAME=4.3.1
VERSION_NAME=4.4.0

GROUP=io.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android
Expand Down
11 changes: 11 additions & 0 deletions markwon-core/src/main/java/io/noties/markwon/Markwon.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ public interface Builder {
@NonNull
Builder usePlugins(@NonNull Iterable<? extends MarkwonPlugin> plugins);

/**
* Control if small chunks of non-finished markdown sentences (for example, a single `*` character)
* should be displayed/rendered as raw input instead of an empty string.
* <p>
* Since 4.4.0 {@code true} by default, versions prior - {@code false}
*
* @since 4.4.0
*/
@NonNull
Builder fallbackToRawInputWhenEmpty(boolean fallbackToRawInputWhenEmpty);

@NonNull
Markwon build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class MarkwonBuilderImpl implements Markwon.Builder {

private Markwon.TextSetter textSetter;

// @since 4.4.0
private boolean fallbackToRawInputWhenEmpty = true;

MarkwonBuilderImpl(@NonNull Context context) {
this.context = context;
}
Expand Down Expand Up @@ -71,6 +74,13 @@ public Markwon.Builder usePlugins(@NonNull Iterable<? extends MarkwonPlugin> plu
return this;
}

@NonNull
@Override
public Markwon.Builder fallbackToRawInputWhenEmpty(boolean fallbackToRawInputWhenEmpty) {
this.fallbackToRawInputWhenEmpty = fallbackToRawInputWhenEmpty;
return this;
}

@NonNull
@Override
public Markwon build() {
Expand Down Expand Up @@ -114,7 +124,8 @@ public Markwon build() {
parserBuilder.build(),
visitorFactory,
configuration,
Collections.unmodifiableList(plugins)
Collections.unmodifiableList(plugins),
fallbackToRawInputWhenEmpty
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import io.noties.markwon.image.AsyncDrawableLoader;
import io.noties.markwon.image.ImageSizeResolver;
import io.noties.markwon.image.ImageSizeResolverDef;
import io.noties.markwon.image.destination.ImageDestinationProcessor;
import io.noties.markwon.syntax.SyntaxHighlight;
import io.noties.markwon.syntax.SyntaxHighlightNoOp;
import io.noties.markwon.urlprocessor.UrlProcessor;
import io.noties.markwon.urlprocessor.UrlProcessorNoOp;

/**
* since 3.0.0 renamed `SpannableConfiguration` -&gt; `MarkwonConfiguration`
*/
@SuppressWarnings("WeakerAccess")
public class MarkwonConfiguration {

@NonNull
Expand All @@ -26,7 +24,8 @@ public static Builder builder() {
private final AsyncDrawableLoader asyncDrawableLoader;
private final SyntaxHighlight syntaxHighlight;
private final LinkResolver linkResolver;
private final UrlProcessor urlProcessor;
// @since 4.4.0
private final ImageDestinationProcessor imageDestinationProcessor;
private final ImageSizeResolver imageSizeResolver;

// @since 3.0.0
Expand All @@ -37,7 +36,7 @@ private MarkwonConfiguration(@NonNull Builder builder) {
this.asyncDrawableLoader = builder.asyncDrawableLoader;
this.syntaxHighlight = builder.syntaxHighlight;
this.linkResolver = builder.linkResolver;
this.urlProcessor = builder.urlProcessor;
this.imageDestinationProcessor = builder.imageDestinationProcessor;
this.imageSizeResolver = builder.imageSizeResolver;
this.spansFactory = builder.spansFactory;
}
Expand All @@ -62,9 +61,12 @@ public LinkResolver linkResolver() {
return linkResolver;
}

/**
* @since 4.4.0
*/
@NonNull
public UrlProcessor urlProcessor() {
return urlProcessor;
public ImageDestinationProcessor imageDestinationProcessor() {
return imageDestinationProcessor;
}

@NonNull
Expand All @@ -87,7 +89,8 @@ public static class Builder {
private AsyncDrawableLoader asyncDrawableLoader;
private SyntaxHighlight syntaxHighlight;
private LinkResolver linkResolver;
private UrlProcessor urlProcessor;
// @since 4.4.0
private ImageDestinationProcessor imageDestinationProcessor;
private ImageSizeResolver imageSizeResolver;
private MarkwonSpansFactory spansFactory;

Expand Down Expand Up @@ -115,9 +118,12 @@ public Builder linkResolver(@NonNull LinkResolver linkResolver) {
return this;
}

/**
* @since 4.4.0
*/
@NonNull
public Builder urlProcessor(@NonNull UrlProcessor urlProcessor) {
this.urlProcessor = urlProcessor;
public Builder imageDestinationProcessor(@NonNull ImageDestinationProcessor imageDestinationProcessor) {
this.imageDestinationProcessor = imageDestinationProcessor;
return this;
}

Expand Down Expand Up @@ -151,8 +157,9 @@ public MarkwonConfiguration build(
linkResolver = new LinkResolverDef();
}

if (urlProcessor == null) {
urlProcessor = new UrlProcessorNoOp();
// @since 4.4.0
if (imageDestinationProcessor == null) {
imageDestinationProcessor = ImageDestinationProcessor.noOp();
}

if (imageSizeResolver == null) {
Expand Down

0 comments on commit 3ab0151

Please sign in to comment.