From d8805bee9223c2fbf5771c40a78d60d0def8dbcd Mon Sep 17 00:00:00 2001 From: Reflxction Dev Date: Mon, 13 Jul 2020 23:13:24 +0300 Subject: [PATCH 1/7] Add HyperlinkedImage which can take tooltips and hyperlinks/redirects --- .../image/HyperlinkedImage.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/image/HyperlinkedImage.java diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/image/HyperlinkedImage.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/image/HyperlinkedImage.java new file mode 100644 index 0000000..436ad34 --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/image/HyperlinkedImage.java @@ -0,0 +1,33 @@ +package net.steppschuh.markdowngenerator.image; + +import net.steppschuh.markdowngenerator.MarkdownSerializationException; + +public class HyperlinkedImage extends Image { + + private String hyperlink; + private String tooltip; + + public HyperlinkedImage(Object text, String url, /*@Nullable*/ String hyperlink,/*@Nullable*/ String tooltip) { + super(text, url); + this.hyperlink = hyperlink; + this.tooltip = tooltip; + } + + public HyperlinkedImage(String url, /*@Nullable*/ String hyperlink, /*@Nullable*/ String tooltip) { + super(url); + this.hyperlink = hyperlink; + this.tooltip = tooltip; + } + + @Override public String serialize() throws MarkdownSerializationException { + if (hyperlink != null) + if (tooltip != null) + return "[![" + getText() + "](" + getUrl() + " \"" + tooltip.replace("\"", "\\\"") + "\")](" + hyperlink + ")"; + else + return "[![" + getText() + "](" + getUrl() + ")](" + hyperlink + ")"; + if (tooltip == null) + return super.serialize(); + else + return "![" + getText() + "](" + getUrl() + "\"" + tooltip.replace("\"", "\\\"") + "\")"; + } +} From 482647593e54a6e1d3a3663cca930ffcd93c3ca9 Mon Sep 17 00:00:00 2001 From: Reflxction Dev Date: Mon, 13 Jul 2020 23:16:28 +0300 Subject: [PATCH 2/7] Add ordered list + ordered list builder --- .../markdowngenerator/list/OrderedList.java | 31 +++++++++++++++++++ .../list/OrderedListBuilder.java | 8 +++++ .../list/OrderedListItem.java | 20 ++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java create mode 100644 Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java create mode 100644 Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListItem.java diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java new file mode 100644 index 0000000..c42ba2e --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java @@ -0,0 +1,31 @@ +package net.steppschuh.markdowngenerator.list; + +import net.steppschuh.markdowngenerator.list.UnorderedList; + +import java.util.List; + +public class OrderedList extends UnorderedList { + + private int elementCount; + + public OrderedList() { + elementCount = 0; + } + + public OrderedList(List items) { + super(items); + items.forEach(i -> i.setIndex(++elementCount)); + } + + @Override public void setItems(List items) { + super.setItems(items); + elementCount = items.size(); + } + + public OrderedList add(OrderedListItem item) { + item.setIndex(++elementCount); + getItems().add(item); + return this; + } + +} diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java new file mode 100644 index 0000000..abe20d9 --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java @@ -0,0 +1,8 @@ +package net.steppschuh.markdowngenerator.list; + +public class OrderedListBuilder extends ListBuilder { + + @Override protected UnorderedList createMarkdownElement() { + return new OrderedList(); + } +} diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListItem.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListItem.java new file mode 100644 index 0000000..e06337f --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListItem.java @@ -0,0 +1,20 @@ +package net.steppschuh.markdowngenerator.list; + +import net.steppschuh.markdowngenerator.list.UnorderedListItem; + +public class OrderedListItem extends UnorderedListItem { + + private int index = 1; + + public OrderedListItem(Object value) { + super(value); + } + + public void setIndex(int index) { + this.index = index; + } + + @Override public String getPredecessor() { + return index + ". "; + } +} From 1543347591a65e08881699da2e33939937ae908f Mon Sep 17 00:00:00 2001 From: Reflxction Dev Date: Mon, 13 Jul 2020 23:41:49 +0300 Subject: [PATCH 3/7] Override #build() to automatically cast to OrderedList --- .../markdowngenerator/list/OrderedListBuilder.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java index abe20d9..90029f3 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java @@ -1,8 +1,19 @@ package net.steppschuh.markdowngenerator.list; +import net.steppschuh.markdowngenerator.MarkdownBuilder; + public class OrderedListBuilder extends ListBuilder { @Override protected UnorderedList createMarkdownElement() { return new OrderedList(); } + + /** + * Returns the root {@link MarkdownBuilder#markdownElement} + * + * @return {@link MarkdownBuilder#markdownElement} + */ + @Override public OrderedList build() { + return (OrderedList) super.build(); + } } From 523d1716e93aeb79de9cd63151ba0559adac9270 Mon Sep 17 00:00:00 2001 From: Reflxction Dev Date: Mon, 13 Jul 2020 23:44:00 +0300 Subject: [PATCH 4/7] Override methods to automatically cast to OrderedListBuilder for better chaining --- .../list/OrderedListBuilder.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java index 90029f3..9bd1bae 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java @@ -1,18 +1,26 @@ package net.steppschuh.markdowngenerator.list; import net.steppschuh.markdowngenerator.MarkdownBuilder; +import net.steppschuh.markdowngenerator.MarkdownSerializable; public class OrderedListBuilder extends ListBuilder { - @Override protected UnorderedList createMarkdownElement() { + @Override protected OrderedList createMarkdownElement() { return new OrderedList(); } - /** - * Returns the root {@link MarkdownBuilder#markdownElement} - * - * @return {@link MarkdownBuilder#markdownElement} - */ + @Override protected OrderedListBuilder getBuilder() { + return (OrderedListBuilder) super.getBuilder(); + } + + @Override public OrderedListBuilder append(Object value) { + return (OrderedListBuilder) super.append(value); + } + + @Override public OrderedListBuilder append(MarkdownSerializable value) { + return (OrderedListBuilder) super.append(value); + } + @Override public OrderedList build() { return (OrderedList) super.build(); } From 1bc239cc22550b0d3802c86fc26b9d5e0d64773e Mon Sep 17 00:00:00 2001 From: Reflxction Dev Date: Mon, 13 Jul 2020 23:51:31 +0300 Subject: [PATCH 5/7] Override methods to automatically cast to OrderedListBuilder for better chaining --- .../markdowngenerator/list/OrderedList.java | 2 -- .../markdowngenerator/list/OrderedListBuilder.java | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java index c42ba2e..2262554 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java @@ -1,7 +1,5 @@ package net.steppschuh.markdowngenerator.list; -import net.steppschuh.markdowngenerator.list.UnorderedList; - import java.util.List; public class OrderedList extends UnorderedList { diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java index 9bd1bae..98c14f2 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java @@ -1,12 +1,13 @@ package net.steppschuh.markdowngenerator.list; -import net.steppschuh.markdowngenerator.MarkdownBuilder; import net.steppschuh.markdowngenerator.MarkdownSerializable; public class OrderedListBuilder extends ListBuilder { + protected OrderedList list; + @Override protected OrderedList createMarkdownElement() { - return new OrderedList(); + return list = new OrderedList(); } @Override protected OrderedListBuilder getBuilder() { @@ -14,11 +15,13 @@ public class OrderedListBuilder extends ListBuilder { } @Override public OrderedListBuilder append(Object value) { - return (OrderedListBuilder) super.append(value); + list.add(new OrderedListItem(value)); + return this; } @Override public OrderedListBuilder append(MarkdownSerializable value) { - return (OrderedListBuilder) super.append(value); + list.add(new OrderedListItem(value)); + return this; } @Override public OrderedList build() { From e53b74bd7d6d4d497a3ad7d4f66cd4659e09833c Mon Sep 17 00:00:00 2001 From: Reflxction Date: Wed, 15 Jul 2020 13:28:36 +0300 Subject: [PATCH 6/7] Generify OrderedList Co-authored-by: Stephan Schultz --- .../java/net/steppschuh/markdowngenerator/list/OrderedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java index 2262554..0fb49ec 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java @@ -10,7 +10,7 @@ public OrderedList() { elementCount = 0; } - public OrderedList(List items) { + public OrderedList(List items) { super(items); items.forEach(i -> i.setIndex(++elementCount)); } From 31c6e4d442ada342a19247c53ccee4e4766d1bb1 Mon Sep 17 00:00:00 2001 From: Revxrsal Date: Fri, 2 Sep 2022 18:10:10 +0300 Subject: [PATCH 7/7] Update Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java Co-authored-by: Stephan Schultz --- .../java/net/steppschuh/markdowngenerator/list/OrderedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java index 0fb49ec..72bab1c 100644 --- a/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java @@ -2,7 +2,7 @@ import java.util.List; -public class OrderedList extends UnorderedList { +public class OrderedList extends UnorderedList { private int elementCount;