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("\"", "\\\"") + "\")"; + } +} 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..72bab1c --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java @@ -0,0 +1,29 @@ +package net.steppschuh.markdowngenerator.list; + +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..98c14f2 --- /dev/null +++ b/Source/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java @@ -0,0 +1,30 @@ +package net.steppschuh.markdowngenerator.list; + +import net.steppschuh.markdowngenerator.MarkdownSerializable; + +public class OrderedListBuilder extends ListBuilder { + + protected OrderedList list; + + @Override protected OrderedList createMarkdownElement() { + return list = new OrderedList(); + } + + @Override protected OrderedListBuilder getBuilder() { + return (OrderedListBuilder) super.getBuilder(); + } + + @Override public OrderedListBuilder append(Object value) { + list.add(new OrderedListItem(value)); + return this; + } + + @Override public OrderedListBuilder append(MarkdownSerializable value) { + list.add(new OrderedListItem(value)); + return this; + } + + @Override public OrderedList build() { + return (OrderedList) super.build(); + } +} 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 + ". "; + } +}