Skip to content

Commit 640a7f2

Browse files
node type url/src
1 parent 32f3ba8 commit 640a7f2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/com/contentstack/utils/render/DefaultOption.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
6363
case "p":
6464
return "<p>" + children + "</p>";
6565
case "a":
66-
return "<a href=\"" + nodeObject.optJSONObject("attrs").optString("href") + "\">" + children + "</a>";
66+
return "<a href=\"" + getNodeStr(nodeObject, "href") + "\">" + children + "</a>";
6767
case "img":
68-
return "<img src=\"" + nodeObject.optJSONObject("attrs").optString("src") + "\" />" + children;
68+
return "<img src=\"" + getNodeStr(nodeObject, "src") + "\" />" + children;
6969
case "embed":
70-
return "<iframe src=\"" + nodeObject.optJSONObject("attrs").optString("src") + "\"" + children + "</iframe>";
70+
return "<iframe src=\"" + getNodeStr(nodeObject, "src") + "\"" + children + "</iframe>";
7171
case "h1":
7272
return "<h1>" + children + "</h1>";
7373
case "h2":
@@ -113,6 +113,16 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
113113
}
114114
}
115115

116+
117+
private String getNodeStr(JSONObject nodeObject, String key) {
118+
String herf = nodeObject.optJSONObject("attrs").optString(key);
119+
String url = nodeObject.optJSONObject("attrs").optString("url");
120+
if (herf == null || herf.isEmpty()) {
121+
herf = url;
122+
}
123+
return herf;
124+
}
125+
116126
/**
117127
* Returns Title From The Embedded Object of type entry
118128
*

0 commit comments

Comments
 (0)