diff --git a/app-sample/samples.json b/app-sample/samples.json index 1b4c5275..c5623142 100644 --- a/app-sample/samples.json +++ b/app-sample/samples.json @@ -39,6 +39,19 @@ "image" ] }, + { + "javaClassName": "io.noties.markwon.app.samples.html.HtmlOrderedListNumbersSample", + "id": "20210201140502", + "title": "HTML Ordered list numbers", + "description": "", + "artifacts": [ + "HTML" + ], + "tags": [ + "rendering", + "html" + ] + }, { "javaClassName": "io.noties.markwon.app.samples.html.InspectHtmlTextSample", "id": "20210201140501", diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/html/HtmlOrderedListNumbersSample.java b/app-sample/src/main/java/io/noties/markwon/app/samples/html/HtmlOrderedListNumbersSample.java new file mode 100644 index 00000000..717d6615 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/html/HtmlOrderedListNumbersSample.java @@ -0,0 +1,35 @@ +package io.noties.markwon.app.samples.html; + +import io.noties.markwon.Markwon; +import io.noties.markwon.app.sample.ui.MarkwonTextViewSample; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.sample.annotations.MarkwonArtifact; +import io.noties.markwon.sample.annotations.MarkwonSampleInfo; +import io.noties.markwon.sample.annotations.Tag; + +@MarkwonSampleInfo( + id = "20210201140502", + title = "HTML Ordered list numbers", + artifacts = MarkwonArtifact.HTML, + tags = {Tag.rendering, Tag.html} +) +public class HtmlOrderedListNumbersSample extends MarkwonTextViewSample { + @Override + public void render() { + final String md = "# HTML Ordered lists\n\n" + + "
    " + + "
  1. July
  2. \n" + + "
  3. August
  4. \n" + + "
  5. September
  6. \n" + + "
  7. October
  8. \n" + + "
  9. November
  10. \n" + + "
  11. December
  12. \n" + + "
\n" + + ""; + + final Markwon markwon = Markwon.builder(context) + .usePlugin(HtmlPlugin.create()) + .build(); + markwon.setMarkdown(textView, md); + } +} diff --git a/markwon-html/src/main/java/io/noties/markwon/html/tag/ListHandler.java b/markwon-html/src/main/java/io/noties/markwon/html/tag/ListHandler.java index 33499b6c..1a19519d 100644 --- a/markwon-html/src/main/java/io/noties/markwon/html/tag/ListHandler.java +++ b/markwon-html/src/main/java/io/noties/markwon/html/tag/ListHandler.java @@ -19,6 +19,8 @@ public class ListHandler extends TagHandler { + private static final String START_KEY = "start"; + @Override public void handle( @NonNull MarkwonVisitor visitor, @@ -41,7 +43,7 @@ public void handle( final RenderProps renderProps = visitor.renderProps(); final SpanFactory spanFactory = configuration.spansFactory().get(ListItem.class); - int number = 1; + int number = Integer.parseInt(block.attributes().containsKey(START_KEY) ? block.attributes().get(START_KEY) : "1"); final int bulletLevel = currentBulletListLevel(block); for (HtmlTag.Block child : block.children()) {