Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HyperlinkedImage + OrderedList components #13

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -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("\"", "\\\"") + "\")";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.steppschuh.markdowngenerator.list;

import java.util.List;

public class OrderedList extends UnorderedList<OrderedListItem> {
Revxrsal marked this conversation as resolved.
Show resolved Hide resolved

private int elementCount;

public OrderedList() {
elementCount = 0;
}

public OrderedList(List<OrderedListItem> items) {
Revxrsal marked this conversation as resolved.
Show resolved Hide resolved
super(items);
items.forEach(i -> i.setIndex(++elementCount));
}

@Override public void setItems(List<OrderedListItem> items) {
super.setItems(items);
elementCount = items.size();
}

public OrderedList add(OrderedListItem item) {
item.setIndex(++elementCount);
getItems().add(item);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Revxrsal marked this conversation as resolved.
Show resolved Hide resolved
super(value);
}

public void setIndex(int index) {
this.index = index;
}

@Override public String getPredecessor() {
return index + ". ";
}
}