diff --git a/docs/README.md b/docs/README.md index cb2be873..2fdd75ac 100644 --- a/docs/README.md +++ b/docs/README.md @@ -46,6 +46,7 @@ listed in are supported (including support for * * Lists (`ul`, `ol`) * Images (`img` will require configured image loader) * Blockquote (`blockquote`) + * Heading (`h1`, `h2`, `h3`, `h4`, `h5`, `h6`) * there is support to render any HTML tags, but it will require to create a special `TagHandler`, more information can be found in [HTML section](/docs/html.md#custom-tag-handler) * Task lists: diff --git a/docs/docs/configure.md b/docs/docs/configure.md index aa638a6d..056d4a72 100644 --- a/docs/docs/configure.md +++ b/docs/docs/configure.md @@ -231,15 +231,15 @@ SpannableConfiguration.builder(context) If not provided explicitly, default `MarkwonHtmlRenderer` implementation will be used. It is documented [here](/docs/html.md#renderer) -### HTML ignore non-closed tags +### HTML allow non-closed tags -`htmlIgnoreNonClosedTags` option is used to control whether or not to +`htmlAllowNonClosedTags` option is used to control whether or not to render non-closed HTML tags ```java SpannableConfiguration.builder(context) - .htmlIgnoreNonClosedTags(boolean) + .htmlAllowNonClosedTags(boolean) .build(); ``` -If not provided explicitly, default value `true` will be used (non-closed tags **won't** be rendered). +If not provided explicitly, default value `false` will be used (non-closed tags **won't** be rendered). diff --git a/docs/docs/html.md b/docs/docs/html.md index d08fe2eb..6130db36 100644 --- a/docs/docs/html.md +++ b/docs/docs/html.md @@ -143,13 +143,13 @@ but if you wish to get a bit closer to a web-browser experience, you can allow t ```java{2} SpannableConfiguration.builder(context) - .htmlIgnoreNonClosedTags(false) + .htmlAllowNonClosedTags(true) .build(); ``` :::warning Note If there is (for example) an `` tag at the start of a document and it's not closed -and `Markwon` is configured to **not** ignore non-closed tags (`.htmlIgnoreNonClosedTags(false)`), +and `Markwon` is configured to **not** ignore non-closed tags (`.htmlAllowNonClosedTags(true)`), it will make the whole document in italics ::: @@ -195,6 +195,7 @@ Default instance have these tags _handled_: * `ol` (ordered list) * `img` (image) * `blockquote` (block quote) +* `h{1-6}` (heading) If you wish to _extend_ default handling (or override existing), `#builderWithDefaults` factory method can be used: diff --git a/markwon/src/main/java/ru/noties/markwon/SpannableConfiguration.java b/markwon/src/main/java/ru/noties/markwon/SpannableConfiguration.java index e7715e3f..319698ea 100644 --- a/markwon/src/main/java/ru/noties/markwon/SpannableConfiguration.java +++ b/markwon/src/main/java/ru/noties/markwon/SpannableConfiguration.java @@ -37,7 +37,7 @@ public class SpannableConfiguration { private final boolean trimWhiteSpaceEnd; // @since 2.0.0 private final MarkwonHtmlParser htmlParser; // @since 2.0.0 private final MarkwonHtmlRenderer htmlRenderer; // @since 2.0.0 - private final boolean htmlIgnoreNonClosedTags; // @since 2.0.0 + private final boolean htmlAllowNonClosedTags; // @since 2.0.0 private SpannableConfiguration(@NonNull Builder builder) { this.theme = builder.theme; @@ -51,7 +51,7 @@ public class SpannableConfiguration { this.trimWhiteSpaceEnd = builder.trimWhiteSpaceEnd; this.htmlParser = builder.htmlParser; this.htmlRenderer = builder.htmlRenderer; - this.htmlIgnoreNonClosedTags = builder.htmlIgnoreNonClosedTags; + this.htmlAllowNonClosedTags = builder.htmlAllowNonClosedTags; } @NonNull @@ -124,8 +124,8 @@ public class SpannableConfiguration { /** * @since 2.0.0 */ - public boolean htmlIgnoreNonClosedTags() { - return htmlIgnoreNonClosedTags; + public boolean htmlAllowNonClosedTags() { + return htmlAllowNonClosedTags; } @SuppressWarnings("unused") @@ -143,7 +143,7 @@ public class SpannableConfiguration { private boolean trimWhiteSpaceEnd = true; // @since 2.0.0 private MarkwonHtmlParser htmlParser; // @since 2.0.0 private MarkwonHtmlRenderer htmlRenderer; // @since 2.0.0 - private boolean htmlIgnoreNonClosedTags = true; // @since 2.0.0 + private boolean htmlAllowNonClosedTags; // @since 2.0.0 Builder(@NonNull Context context) { this.context = context; @@ -241,15 +241,15 @@ public class SpannableConfiguration { } /** - * @param htmlIgnoreNonClosedTags that indicates if non-closed html tags should be kept open. - * If this argument is false then all non-closed HTML tags + * @param htmlAllowNonClosedTags that indicates if non-closed html tags should be rendered. + * If this argument is true then all non-closed HTML tags * will be closed at the end of a document. Otherwise they will * be delivered non-closed {@code HtmlTag#isClosed()} * @since 2.0.0 */ @NonNull - public Builder htmlIgnoreNonClosedTags(boolean htmlIgnoreNonClosedTags) { - this.htmlIgnoreNonClosedTags = htmlIgnoreNonClosedTags; + public Builder htmlAllowNonClosedTags(boolean htmlAllowNonClosedTags) { + this.htmlAllowNonClosedTags = htmlAllowNonClosedTags; return this; } diff --git a/markwon/src/main/java/ru/noties/markwon/renderer/html2/MarkwonHtmlRendererImpl.java b/markwon/src/main/java/ru/noties/markwon/renderer/html2/MarkwonHtmlRendererImpl.java index 9cb67baa..6de698f5 100644 --- a/markwon/src/main/java/ru/noties/markwon/renderer/html2/MarkwonHtmlRendererImpl.java +++ b/markwon/src/main/java/ru/noties/markwon/renderer/html2/MarkwonHtmlRendererImpl.java @@ -27,7 +27,7 @@ class MarkwonHtmlRendererImpl extends MarkwonHtmlRenderer { @NonNull MarkwonHtmlParser parser) { final int end; - if (configuration.htmlIgnoreNonClosedTags()) { + if (!configuration.htmlAllowNonClosedTags()) { end = HtmlTag.NO_END; } else { end = builder.length();