Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,7 @@ private static void withinBlockIndividual(StringBuilder out, Spanned text, int s
String tagType = isList ? "li" : "p";
out.append("<");

if (isUlListItem) {
out.append("li");
} else if (isOlListItem) {
out.append("li index=").append(index);
} else {
out.append("p");
}
out.append(tagType);

out.append(">");
withinParagraph(out, text, i, next);
Expand Down Expand Up @@ -571,6 +565,9 @@ class HtmlToSpannedConverter implements ContentHandler {
*/
private static final Map<String, Integer> sColorMap;

private static Integer currentOrderedListItemIndex = 0;
private static Boolean isInOrderedList = false;

static {
sColorMap = new HashMap<>();
sColorMap.put("darkgray", 0xFFA9A9A9);
Expand Down Expand Up @@ -666,6 +663,11 @@ private void handleStartTag(String tag, Attributes attributes) {
startBlockElement(mSpannableStringBuilder, attributes, getMarginParagraph());
startCssStyle(mSpannableStringBuilder, attributes);
} else if (tag.equalsIgnoreCase("ul")) {
isInOrderedList = false;
startBlockElement(mSpannableStringBuilder, attributes, getMarginList());
} else if (tag.equalsIgnoreCase("ol")) {
isInOrderedList = true;
currentOrderedListItemIndex = 0;
startBlockElement(mSpannableStringBuilder, attributes, getMarginList());
} else if (tag.equalsIgnoreCase("li")) {
startLi(mSpannableStringBuilder, attributes);
Expand Down Expand Up @@ -844,17 +846,9 @@ private static void handleBr(Editable text) {
private void startLi(Editable text, Attributes attributes) {
startBlockElement(text, attributes, getMarginListItem());

// assumption, ordered list includes index as their index attribute
// unordered lists does not define index
String value = attributes.getValue("", "index");

if (value != null) {
try {
int index = Integer.parseInt(value);
start(text, new List("ol", index));
} catch (NumberFormatException e) {
start(text, new List("ul", 0));
}
if (isInOrderedList) {
currentOrderedListItemIndex++;
start(text, new List("ol", currentOrderedListItemIndex));
} else {
start(text, new List("ul", 0));
}
Expand Down
Loading