-
Notifications
You must be signed in to change notification settings - Fork 45
Add HyperlinkedImage + OrderedList components #13
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Open
Revxrsal
wants to merge
7
commits into
Steppschuh:dev
Choose a base branch
from
Revxrsal:master
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8805be
Add HyperlinkedImage which can take tooltips and hyperlinks/redirects
Revxrsal 4826475
Add ordered list + ordered list builder
Revxrsal 1543347
Override #build() to automatically cast to OrderedList
Revxrsal 523d171
Override methods to automatically cast to OrderedListBuilder for bett…
Revxrsal 1bc239c
Override methods to automatically cast to OrderedListBuilder for bett…
Revxrsal e53b74b
Generify OrderedList
Revxrsal 31c6e4d
Update Source/MarkdownGenerator/src/main/java/net/steppschuh/markdown…
Revxrsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...kdownGenerator/src/main/java/net/steppschuh/markdowngenerator/image/HyperlinkedImage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "[ + " \"" + tooltip.replace("\"", "\\\"") + "\")](" + hyperlink + ")"; | ||
else | ||
return "[ + ")](" + hyperlink + ")"; | ||
if (tooltip == null) | ||
return super.serialize(); | ||
else | ||
return " + "\"" + tooltip.replace("\"", "\\\"") + "\")"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ce/MarkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<T extends Object> extends UnorderedList<T> { | ||
|
||
private int elementCount; | ||
|
||
public OrderedList() { | ||
elementCount = 0; | ||
} | ||
|
||
public OrderedList(List<T> items) { | ||
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; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...downGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...arkdownGenerator/src/main/java/net/steppschuh/markdowngenerator/list/OrderedListItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
super(value); | ||
} | ||
|
||
public void setIndex(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override public String getPredecessor() { | ||
return index + ". "; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.