Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 5e75c80

Browse files
authored
Merge pull request #65 from scijava/fix-map-converter
Fix MapToHTMLTableConverter
2 parents 90621f4 + 04dd6b9 commit 5e75c80

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

notebooks/Test.ipynb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,70 @@
116116
"assert(a_groovy_dict[\"a_string\"] == \"Hello\")\n",
117117
"assert(a_groovy_dict[\"a_number\"] == 87)"
118118
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 3,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"data": {
127+
"text/html": [
128+
"<style>table.converted {color: #333; font-family: Helvetica, Arial, sans-serif; border-collapse: collapse; border-spacing: 0;}table.converted td, table.converted th {border: 1px solid #C9C7C7;}table.converted th, table.converted td.rowLabel {background: #626262; color: #FFFFFF; font-weight: bold; text-align: left;}table.converted td {text-align: left;}table.converted tr:nth-child(even) {background: #F3F3F3;}table.converted tr:nth-child(odd) {background: #FFFFFF;}table.converted tbody tr:hover {background: #BDF4B5;}table.converted td.rowLabel, table.converted th.rowLabel {display: none;}</style><table class =\"converted\"><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody><tr><td>:a</td><td>4</td></tr><tr><td>:e</td><td>&lt;none&gt;</td></tr></tbody></table>"
129+
]
130+
},
131+
"execution_count": 3,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
136+
"source": [
137+
"#!clojure\n",
138+
"{:a 4, :e nil}"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": 4,
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"data": {
148+
"text/html": [
149+
"<style>table.converted {color: #333; font-family: Helvetica, Arial, sans-serif; border-collapse: collapse; border-spacing: 0;}table.converted td, table.converted th {border: 1px solid #C9C7C7;}table.converted th, table.converted td.rowLabel {background: #626262; color: #FFFFFF; font-weight: bold; text-align: left;}table.converted td {text-align: left;}table.converted tr:nth-child(even) {background: #F3F3F3;}table.converted tr:nth-child(odd) {background: #FFFFFF;}table.converted tbody tr:hover {background: #BDF4B5;}table.converted td.rowLabel, table.converted th.rowLabel {display: none;}</style><table class =\"converted\"><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody><tr><td>a</td><td>4</td></tr><tr><td>e</td><td>&lt;none&gt;</td></tr></tbody></table>"
150+
]
151+
},
152+
"execution_count": 4,
153+
"metadata": {},
154+
"output_type": "execute_result"
155+
}
156+
],
157+
"source": [
158+
"#!groovy\n",
159+
"[a:4, e: null]"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 5,
165+
"metadata": {},
166+
"outputs": [
167+
{
168+
"data": {
169+
"text/html": [
170+
"<style>table.converted {color: #333; font-family: Helvetica, Arial, sans-serif; border-collapse: collapse; border-spacing: 0;}table.converted td, table.converted th {border: 1px solid #C9C7C7;}table.converted th, table.converted td.rowLabel {background: #626262; color: #FFFFFF; font-weight: bold; text-align: left;}table.converted td {text-align: left;}table.converted tr:nth-child(even) {background: #F3F3F3;}table.converted tr:nth-child(odd) {background: #FFFFFF;}table.converted tbody tr:hover {background: #BDF4B5;}table.converted td.rowLabel, table.converted th.rowLabel {display: none;}</style><table class =\"converted\"><thead><tr><th>Salutation</th><th>Valediction</th></tr></thead><tbody><tr><td>hello</td><td>goodbye</td></tr><tr><td>hi</td><td>bye</td></tr><tr><td>hey</td><td>&lt;none&gt;</td></tr></tbody></table>"
171+
]
172+
},
173+
"execution_count": 5,
174+
"metadata": {},
175+
"output_type": "execute_result"
176+
}
177+
],
178+
"source": [
179+
"#!groovy\n",
180+
"[[\"Salutation\":\"hello\", \"Valediction\":\"goodbye\"], [\"Salutation\":\"hi\", \"Valediction\":\"bye\"], \n",
181+
" [\"Salutation\":\"hey\", \"Valediction\":null]]"
182+
]
119183
}
120184
],
121185
"metadata": {

src/main/java/org/scijava/notebook/converter/HTMLNotebookOutputConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public abstract class HTMLNotebookOutputConverter<I, O extends HTMLNotebookOutpu
3939

4040
/** Gets an HTML string representing the given object. */
4141
protected String asHTML(final Object o) {
42-
return convertService.convert(o, HTMLFriendlyNotebookOutput.class).toHTML();
42+
final HTMLFriendlyNotebookOutput converted = convertService.convert(o, HTMLFriendlyNotebookOutput.class);
43+
return converted == null ? "&lt;none&gt;" : converted.toHTML();
4344
}
4445

4546
}

src/main/java/org/scijava/notebook/converter/MapToHTMLTableNotebookConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public HTMLTableNotebookOutput convert(final Object object) {
6767

6868
// Append the rows
6969
for (final K key : table.keySet()) {
70-
final String k = (key != null) ? asHTML(key) : "";
71-
final String v = (key != null) ? asHTML(table.get(key)) : "";
70+
final String k = asHTML(key);
71+
final String v = asHTML(table.get(key));
7272
htmlTable += HTMLTableBuilder.appendData(k, true, false);
7373
htmlTable += HTMLTableBuilder.appendData(v, false, true);
7474
}

0 commit comments

Comments
 (0)