base.html.j2 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. {%- extends 'display_priority.j2' -%}
  2. {% from 'celltags.j2' import celltags %}
  3. {% from 'cell_id_anchor.j2' import cell_id_anchor %}
  4. {% block codecell %}
  5. <div {{ cell_id_anchor(cell) }} class="cell border-box-sizing code_cell rendered{{ celltags(cell) }}">
  6. {{ super() }}
  7. </div>
  8. {%- endblock codecell %}
  9. {% block input_group -%}
  10. <div class="input">
  11. {{ super() }}
  12. </div>
  13. {% endblock input_group %}
  14. {% block output_group %}
  15. <div class="output_wrapper">
  16. <div class="output">
  17. {{ super() }}
  18. </div>
  19. </div>
  20. {% endblock output_group %}
  21. {% block in_prompt -%}
  22. <div class="prompt input_prompt">
  23. {%- if cell.execution_count is defined -%}
  24. In&nbsp;[{{ cell.execution_count|replace(None, "&nbsp;") }}]:
  25. {%- else -%}
  26. In&nbsp;[&nbsp;]:
  27. {%- endif -%}
  28. </div>
  29. {%- endblock in_prompt %}
  30. {% block empty_in_prompt -%}
  31. <div class="prompt input_prompt">
  32. </div>
  33. {%- endblock empty_in_prompt %}
  34. {#
  35. output_prompt doesn't do anything in HTML,
  36. because there is a prompt div in each output area (see output block)
  37. #}
  38. {% block output_prompt %}
  39. {% endblock output_prompt %}
  40. {% block input %}
  41. <div class="inner_cell">
  42. <div class="input_area">
  43. {{ cell.source | highlight_code(metadata=cell.metadata) | clean_html }}
  44. </div>
  45. </div>
  46. {%- endblock input %}
  47. {% block output_area_prompt %}
  48. {%- if output.output_type == 'execute_result' -%}
  49. <div class="prompt output_prompt">
  50. {%- if cell.execution_count is defined -%}
  51. Out[{{ cell.execution_count|replace(None, "&nbsp;") }}]:
  52. {%- else -%}
  53. Out[&nbsp;]:
  54. {%- endif -%}
  55. {%- else -%}
  56. <div class="prompt">
  57. {%- endif -%}
  58. </div>
  59. {% endblock output_area_prompt %}
  60. {% block output %}
  61. <div class="output_area">
  62. {% if resources.global_content_filter.include_output_prompt %}
  63. {{ self.output_area_prompt() }}
  64. {% endif %}
  65. {{ super() }}
  66. </div>
  67. {% endblock output %}
  68. {% block markdowncell scoped %}
  69. <div {{ cell_id_anchor(cell) }} class="cell border-box-sizing text_cell rendered{{ celltags(cell) }}">
  70. {%- if resources.global_content_filter.include_input_prompt-%}
  71. {{ self.empty_in_prompt() }}
  72. {%- endif -%}
  73. <div class="inner_cell">
  74. <div class="text_cell_render border-box-sizing rendered_html">
  75. {%- if resources.should_sanitize_html %}
  76. {%- set html_value=cell.source | markdown2html | strip_files_prefix | clean_html -%}
  77. {%- else %}
  78. {%- set html_value=cell.source | markdown2html | strip_files_prefix -%}
  79. {%- endif %}
  80. {{ html_value }}
  81. </div>
  82. </div>
  83. </div>
  84. {%- endblock markdowncell %}
  85. {% block rawcell scoped %}
  86. {%- if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) -%}
  87. {{ cell.source | clean_html }}
  88. {%- endif -%}
  89. {%- endblock rawcell %}
  90. {% block unknowncell scoped %}
  91. unknown type {{ cell.type }}
  92. {% endblock unknowncell %}
  93. {% block execute_result -%}
  94. {%- set extra_class="output_execute_result" -%}
  95. {% block data_priority scoped %}
  96. {{ super() }}
  97. {% endblock data_priority %}
  98. {%- set extra_class="" -%}
  99. {%- endblock execute_result %}
  100. {% block stream_stdout -%}
  101. <div class="output_subarea output_stream output_stdout output_text">
  102. <pre>
  103. {{- output.text | ansi2html -}}
  104. </pre>
  105. </div>
  106. {%- endblock stream_stdout %}
  107. {% block stream_stderr -%}
  108. <div class="output_subarea output_stream output_stderr output_text">
  109. <pre>
  110. {{- output.text | ansi2html -}}
  111. </pre>
  112. </div>
  113. {%- endblock stream_stderr %}
  114. {% block data_svg scoped -%}
  115. <div class="output_svg output_subarea {{ extra_class }}">
  116. {%- if output.svg_filename %}
  117. <img src="{{ output.svg_filename | posix_path | escape_html }}">
  118. {%- else %}
  119. {%- if resources.should_not_encode_svg %}
  120. {{ output.data['image/svg+xml'].encode("utf-8") | clean_html }}
  121. {%- else %}
  122. <img src="data:image/svg+xml;base64,{{ output.data['image/svg+xml'] | text_base64 | escape_html }}">
  123. {%- endif %}
  124. {%- endif %}
  125. </div>
  126. {%- endblock data_svg %}
  127. {% block data_html scoped -%}
  128. <div class="output_html rendered_html output_subarea {{ extra_class }}">
  129. {%- if resources.should_sanitize_html %}
  130. {%- set html_value=output.data['text/html'] | clean_html -%}
  131. {%- else %}
  132. {%- set html_value=output.data['text/html'] -%}
  133. {%- endif %}
  134. {%- if output.get('metadata', {}).get('text/html', {}).get('isolated') -%}
  135. <iframe
  136. class="isolated-iframe"
  137. style="height:520px; width:100%; margin:0; padding: 0"
  138. frameborder="0"
  139. scrolling="auto"
  140. src="data:text/html;base64,{{ html_value | text_base64 }}">
  141. </iframe>
  142. {%- else -%}
  143. {{ html_value }}
  144. {%- endif -%}
  145. </div>
  146. {%- endblock data_html %}
  147. {% block data_markdown scoped -%}
  148. {%- if resources.should_sanitize_html %}
  149. {%- set html_value=output.data['text/markdown'] | markdown2html | clean_html -%}
  150. {%- else %}
  151. {%- set html_value=output.data['text/markdown'] | markdown2html -%}
  152. {%- endif %}
  153. <div class="output_markdown rendered_html output_subarea {{ extra_class }}">
  154. {{ html_value }}
  155. </div>
  156. {%- endblock data_markdown %}
  157. {% block data_png scoped %}
  158. <div class="output_png output_subarea {{ extra_class }}">
  159. {%- if 'image/png' in output.metadata.get('filenames', {}) %}
  160. <img src="{{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
  161. {%- else %}
  162. <img src="data:image/png;base64,{{ output.data['image/png'] | escape_html }}"
  163. {%- endif %}
  164. {%- set width=output | get_metadata('width', 'image/png') -%}
  165. {%- if width is not none %}
  166. width={{ width | escape_html }}
  167. {%- endif %}
  168. {%- set height=output | get_metadata('height', 'image/png') -%}
  169. {%- if height is not none %}
  170. height={{ height | escape_html }}
  171. {%- endif %}
  172. {%- if output | get_metadata('unconfined', 'image/png') %}
  173. class="unconfined"
  174. {%- endif %}
  175. {%- set alttext=(output | get_metadata('alt', 'image/png')) or (cell | get_metadata('alt')) -%}
  176. {%- if alttext is not none %}
  177. alt="{{ alttext | escape_html }}"
  178. {%- endif %}
  179. >
  180. </div>
  181. {%- endblock data_png %}
  182. {% block data_jpg scoped %}
  183. <div class="output_jpeg output_subarea {{ extra_class }}">
  184. {%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
  185. <img src="{{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
  186. {%- else %}
  187. <img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] | escape_html }}"
  188. {%- endif %}
  189. {%- set width=output | get_metadata('width', 'image/jpeg') -%}
  190. {%- if width is not none %}
  191. width={{ width | escape_html }}
  192. {%- endif %}
  193. {%- set height=output | get_metadata('height', 'image/jpeg') -%}
  194. {%- if height is not none %}
  195. height={{ height | escape_html }}
  196. {%- endif %}
  197. {%- if output | get_metadata('unconfined', 'image/jpeg') %}
  198. class="unconfined"
  199. {%- endif %}
  200. {%- set alttext=(output | get_metadata('alt', 'image/jpeg')) or (cell | get_metadata('alt')) -%}
  201. {%- if alttext is not none %}
  202. alt="{{ alttext | escape_html }}"
  203. {%- endif %}
  204. >
  205. </div>
  206. {%- endblock data_jpg %}
  207. {% block data_latex scoped %}
  208. <div class="output_latex output_subarea {{ extra_class }}">
  209. {{ output.data['text/latex'] | e }}
  210. </div>
  211. {%- endblock data_latex %}
  212. {% block error -%}
  213. <div class="output_subarea output_text output_error">
  214. <pre>
  215. {{- super() -}}
  216. </pre>
  217. </div>
  218. {%- endblock error %}
  219. {%- block traceback_line %}
  220. {{ line | ansi2html }}
  221. {%- endblock traceback_line %}
  222. {%- block data_text scoped %}
  223. <div class="output_text output_subarea {{ extra_class }}">
  224. <pre>
  225. {{- output.data['text/plain'] | ansi2html -}}
  226. </pre>
  227. </div>
  228. {%- endblock -%}
  229. {%- block data_javascript scoped %}
  230. {% set div_id = uuid4() %}
  231. <div id="{{ div_id }}" class="output_subarea output_javascript {{ extra_class }}">
  232. {%- if not resources.should_sanitize_html %}
  233. <script type="text/javascript">
  234. var element = $('#{{ div_id }}');
  235. {{ output.data['application/javascript'] }}
  236. </script>
  237. {%- endif %}
  238. </div>
  239. {%- endblock -%}
  240. {%- block data_widget_view scoped %}
  241. {%- if not resources.should_sanitize_html %}
  242. {% set div_id = uuid4() %}
  243. {% set datatype_list = output.data | filter_data_type %}
  244. {% set datatype = datatype_list[0]%}
  245. <div id="{{ div_id }}" class="output_subarea output_widget_view {{ extra_class }}">
  246. <script type="text/javascript">
  247. var element = $('#{{ div_id }}');
  248. </script>
  249. <script type="{{ datatype }}">
  250. {{ output.data[datatype] | json_dumps | escape_html_script }}
  251. </script>
  252. </div>
  253. {%- endif %}
  254. {%- endblock data_widget_view -%}
  255. {%- block footer %}
  256. {%- if not resources.should_sanitize_html %}
  257. {% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
  258. {% if mimetype in nb.metadata.get("widgets",{})%}
  259. <script type="{{ mimetype }}">
  260. {{ nb.metadata.widgets[mimetype] | json_dumps | escape_html_script }}
  261. </script>
  262. {% endif %}
  263. {%- endif %}
  264. {{ super() }}
  265. {%- endblock footer-%}