Skip to content
Browse files

improve nested microformat value parsing

fixes HEntryTests.ImpliedValueNested and 5 others
  • Loading branch information...
1 parent 7ca8ebe commit 86752d845d90babd69fdc228ccfdc3e2700bbb9f @notenoughneon notenoughneon committed Mar 13, 2016
Showing with 22 additions and 3 deletions.
  1. +22 −3 src/main/java/com/kylewm/mf2j/Mf2Parser.java
View
25 src/main/java/com/kylewm/mf2j/Mf2Parser.java
@@ -211,6 +211,26 @@ private JsonDict parseMicroformat(Element elem, URI baseUri) {
return itemDict;
}
+ private Object parseChildValue(String className, JsonDict valueObj, Object value) {
+ JsonDict properties = (JsonDict) valueObj.get("properties");
+ //if it's a p-* property element, use the first p-name of the h-* child
+ if (className.startsWith("p-") && properties.containsKey("name")) {
+ JsonList names = (JsonList) properties.get("name");
+ if (names.size() > 0)
+ return names.get(0);
+ }
+ //else if it's an e-* property element, re-use its { } structure with existing value: inside.
+ //TODO: implement this or find out if its handled by default case below
+ //else if it's a u-* property element and the h-* child has a u-url, use the first such u-url
+ if (className.startsWith("u-") && properties.containsKey("url")) {
+ JsonList urls = (JsonList) properties.get("url");
+ if (urls.size() > 0)
+ return urls.get(0);
+ }
+ //else use the parsed property value per p-*,u-*,dt-* parsing respectively
+ return value;
+ }
+
private void parseProperties(Element elem, URI baseUri, JsonDict itemDict) {
boolean isProperty = false, isMicroformat = false;
@@ -246,9 +266,8 @@ else if (className.startsWith("e-")) {
if (propName != null) {
if (isMicroformat && valueObj != null) {
- JsonDict copy = new JsonDict(valueObj);
- copy.put("value", value);
- value = copy;
+ valueObj.put("value", parseChildValue(className, valueObj, value));
+ value = valueObj;
}
itemDict.getDict("properties").getOrCreateList(propName).add(value);
}

0 comments on commit 86752d8

Please sign in to comment.
Something went wrong with that request. Please try again.