Guest User

Untitled

a guest
Mar 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import IPython\n",
  10. "import html\n",
  11. "\n",
  12. "raw_html = '''\n",
  13. "<html>\n",
  14. "\n",
  15. "<head>\n",
  16. "\n",
  17. "<h1>Some HTML in an iframe</h1>\n",
  18. "\n",
  19. "<div id=\"control\">\n",
  20. " <a href=\"#\"><small>[-]</small></a>\n",
  21. "</div>\n",
  22. "\n",
  23. "</body>\n",
  24. "</html>\n",
  25. "\n",
  26. "'''\n",
  27. "\n",
  28. "# In my actual case, this JS runs when the [-] is clicked. It is not necessary to reproduce this issue though.\n",
  29. "# d3.select(\"#meta_control\").on(\"click\", function() {\n",
  30. "# d3.select(\"#meta\").style(\"display\", \"none\");\n",
  31. "# });\n",
  32. " \n",
  33. "iframe = f'''<iframe srcdoc=\"{html.escape(raw_html)}\" width=100%% height=250></iframe>'''\n",
  34. "IPython.display.HTML(iframe)"
  35. ]
  36. },
  37. {
  38. "cell_type": "code",
  39. "execution_count": null,
  40. "metadata": {},
  41. "outputs": [],
  42. "source": [
  43. "with open(\"test.html\", \"w\") as f:\n",
  44. " f.write(raw_html)"
  45. ]
  46. },
  47. {
  48. "cell_type": "code",
  49. "execution_count": null,
  50. "metadata": {},
  51. "outputs": [],
  52. "source": [
  53. "iframe = '<iframe src=test.html width=100%% height=250></iframe>'\n",
  54. "IPython.core.display.display(IPython.core.display.HTML(iframe))"
  55. ]
  56. },
  57. {
  58. "cell_type": "code",
  59. "execution_count": null,
  60. "metadata": {},
  61. "outputs": [],
  62. "source": [
  63. "IPython.core.display.display(IPython.display.IFrame('test.html', width=700, height=250))"
  64. ]
  65. },
  66. {
  67. "cell_type": "code",
  68. "execution_count": null,
  69. "metadata": {},
  70. "outputs": [],
  71. "source": []
  72. }
  73. ],
  74. "metadata": {
  75. "kernelspec": {
  76. "display_name": "Python 3",
  77. "language": "python",
  78. "name": "python3"
  79. },
  80. "language_info": {
  81. "codemirror_mode": {
  82. "name": "ipython",
  83. "version": 3
  84. },
  85. "file_extension": ".py",
  86. "mimetype": "text/x-python",
  87. "name": "python",
  88. "nbconvert_exporter": "python",
  89. "pygments_lexer": "ipython3",
  90. "version": "3.6.1"
  91. }
  92. },
  93. "nbformat": 4,
  94. "nbformat_minor": 2
  95. }
Add Comment
Please, Sign In to add comment