(cell_contents, read_only)
| 203 | |
| 204 | |
| 205 | def convert_to_cells(cell_contents, read_only): |
| 206 | cells = [] |
| 207 | for stuff in cell_contents: |
| 208 | if stuff["type"] == "markdown": |
| 209 | # todo add metadata later |
| 210 | cells.append( |
| 211 | { |
| 212 | "cell_type": "markdown", |
| 213 | "metadata": {}, |
| 214 | "source": stuff["value"] |
| 215 | } |
| 216 | ) |
| 217 | elif stuff["type"] == "code": |
| 218 | if read_only: |
| 219 | # Skip read only |
| 220 | # TODO: Fix |
| 221 | cells.append( |
| 222 | { |
| 223 | "cell_type": "markdown", |
| 224 | "metadata": {}, |
| 225 | "source": ["```py\n"] + stuff["statements"] + ["```\n"] + ["```py\n"] + stuff['output'] + ["```\n"] |
| 226 | } |
| 227 | ) |
| 228 | continue |
| 229 | |
| 230 | is_print_present, sanitized_code = inspect_and_sanitize_code_lines(stuff["statements"]) |
| 231 | if is_print_present: |
| 232 | cells.append( |
| 233 | { |
| 234 | "cell_type": "code", |
| 235 | "metadata": { |
| 236 | "collapsed": True, |
| 237 | |
| 238 | }, |
| 239 | "execution_count": None, |
| 240 | "outputs": [{ |
| 241 | "name": "stdout", |
| 242 | "output_type": "stream", |
| 243 | "text": stuff["output"] |
| 244 | }], |
| 245 | "source": sanitized_code |
| 246 | } |
| 247 | ) |
| 248 | else: |
| 249 | cells.append( |
| 250 | { |
| 251 | "cell_type": "code", |
| 252 | "execution_count": None, |
| 253 | "metadata": { |
| 254 | "collapsed": True |
| 255 | }, |
| 256 | "outputs": [{ |
| 257 | "data": { |
| 258 | "text/plain": stuff["output"] |
| 259 | }, |
| 260 | "output_type": "execute_result", |
| 261 | "metadata": {}, |
| 262 | "execution_count": None |
no test coverage detected