[
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015, 2016, 2017 Gabi de Maeztu and David Lukes\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Jupyter themes\n\nModify CodeMirror's Color Syntax.\n\n<img width=\"987\" alt=\"preview1\" src=\"https://cloud.githubusercontent.com/assets/1485056/14063819/abe2dc18-f3e2-11e5-94d9-978ec774156e.png\">\n<img width=\"989\" alt=\"preview2\" src=\"https://cloud.githubusercontent.com/assets/1485056/14063820/abfab572-f3e2-11e5-9fee-4b6be0fbc9bb.png\">\n\nThis **_Jupyter_ Notebook Extension** let's you select the code syntax highlighting. The selected theme is stored in _notebooks config file_ so every time you open a notebook it will automatically load the theme you selected the last time.\n\n### Installation:\n\n```shell\n# Create required directory in case (optional)\n$ mkdir -p $(jupyter --data-dir)/nbextensions\n$ cd $(jupyter --data-dir)/nbextensions\n$ mkdir jupyter_themes && cd jupyter_themes\n$ wget https://raw.githubusercontent.com/merqurio/jupyter_themes/master/theme_selector.js\n# Activate the extension\n$ cd ../ && jupyter nbextension enable jupyter_themes/theme_selector\n```\n\n### Usage:\nFind your preferred theme and font at Cell's menu.\n\n<img width=\"960\" alt=\"screen shot 2016-03-27 at 06 09 53\" src=\"https://cloud.githubusercontent.com/assets/1485056/14063821/ac094150-f3e2-11e5-9f6f-7861aaa69ec0.png\">\n\n\nChangelog\n=========\n###### NEW in 0.4.1\n- JupyterHub support (thanks @dlukes)\n\n###### NEW in 0.3.0\n- Adds Font modification\n- Adds line number toggle\n\n###### NEW IN 0.2.0\n- Uses CodeMirrors own api & themes\n\n\n\n## License\n\nThe MIT License (MIT) | See LICENSE.md\n\nCopyright (c) 2015, 2016, 2017 Gabi de Maeztu, David Lukes\n"
  },
  {
    "path": "theme_selector.js",
    "content": "/*\n *\n * @author    Gabriel de Maeztu <gabriel.maeztu@gmail.com>\n * @version   2.0.1\n * @license   MIT license\n * @see       http://github.com/merqurio/jupyter_themes\n * @copyright 2015-2016-2017-2018, Gabriel de Maeztu, http://merqur.io\n *\n */\n\n define([\n   'require',\n   'jquery',\n   'base/js/namespace'\n ], function(require, $, Jupyter) {\n   'use strict';\n\n    var themes = {\n      \"Default\": null,\n      \"3024-day\": \"/static/components/codemirror/theme/3024-day.css\",\n      \"3024-night\": \"/static/components/codemirror/theme/3024-night.css\",\n      \"ambiance-mobile\": \"/static/components/codemirror/theme/ambiance-mobile.css\",\n      \"ambiance\": \"/static/components/codemirror/theme/ambiance.css\",\n      \"base16-dark\": \"/static/components/codemirror/theme/base16-dark.css\",\n      \"base16-light\": \"/static/components/codemirror/theme/base16-light.css\",\n      \"blackboard\": \"/static/components/codemirror/theme/blackboard.css\",\n      \"cobalt\": \"/static/components/codemirror/theme/cobalt.css\",\n      \"colorforth\": \"/static/components/codemirror/theme/colorforth.css\",\n      \"dracula\": \"/static/components/codemirror/theme/dracula.css\",\n      \"eclipse\": \"/static/components/codemirror/theme/eclipse.css\",\n      \"elegant\": \"/static/components/codemirror/theme/elegant.css\",\n      \"erlang-dark\": \"/static/components/codemirror/theme/erlang-dark.css\",\n      \"icecoder\": \"/static/components/codemirror/theme/icecoder.css\",\n      \"lesser-dark\": \"/static/components/codemirror/theme/lesser-dark.css\",\n      \"liquibyte\": \"/static/components/codemirror/theme/liquibyte.css\",\n      \"material\": \"/static/components/codemirror/theme/material.css\",\n      \"mbo\": \"/static/components/codemirror/theme/mbo.css\",\n      \"mdn-like\": \"/static/components/codemirror/theme/mdn-like.css\",\n      \"midnight\": \"/static/components/codemirror/theme/midnight.css\",\n      \"monokai\": \"/static/components/codemirror/theme/monokai.css\",\n      \"neat\": \"/static/components/codemirror/theme/neat.css\",\n      \"neo\": \"/static/components/codemirror/theme/neo.css\",\n      \"night\": \"/static/components/codemirror/theme/night.css\",\n      \"paraiso-dark\": \"/static/components/codemirror/theme/paraiso-dark.css\",\n      \"paraiso-light\": \"/static/components/codemirror/theme/paraiso-light.css\",\n      \"pastel-on-dark\": \"/static/components/codemirror/theme/pastel-on-dark.css\",\n      \"rubyblue\": \"/static/components/codemirror/theme/rubyblue.css\",\n      \"seti\": \"/static/components/codemirror/theme/seti.css\",\n      \"solarized\": \"/static/components/codemirror/theme/solarized.css\",\n      \"the-matrix\": \"/static/components/codemirror/theme/the-matrix.css\",\n      \"tomorrow-night-bright\": \"/static/components/codemirror/theme/tomorrow-night-bright.css\",\n      \"tomorrow-night-eighties\": \"/static/components/codemirror/theme/tomorrow-night-eighties.css\",\n      \"ttcn\": \"/static/components/codemirror/theme/ttcn.css\",\n      \"twilight\": \"/static/components/codemirror/theme/twilight.css\",\n      \"vibrant-ink\": \"/static/components/codemirror/theme/vibrant-ink.css\",\n      \"xq-dark\": \"/static/components/codemirror/theme/xq-dark.css\",\n      \"xq-light\": \"/static/components/codemirror/theme/xq-light.css\",\n      \"yeti\": \"/static/components/codemirror/theme/yeti.css\",\n      \"zenburn\": \"/static/components/codemirror/theme/zenburn.css\"\n    };\n\n    var fonts = {\n      \"Default\": {\n        \"css\": \"monospace\",\n        \"url\": null\n      },\n      \"Hack\": {\n        \"css\": \"Hack\",\n        \"url\": \"//cdn.jsdelivr.net/font-hack/2.019/css/hack-extended.min.css\"\n      },\n      \"Inconsolata\": {\n        \"css\": \"Inconsolata\",\n        \"url\": \"//fonts.googleapis.com/css?family=Inconsolata\"\n      },\n      \"Source Code Pro\": {\n        \"css\": \"Source Code Pro\",\n        \"url\": \"//fonts.googleapis.com/css?family=Source+Code+Pro\"\n      },\n      \"Roboto Mono\": {\n        \"css\": \"Roboto Mono\",\n        \"url\": \"//fonts.googleapis.com/css?family=Roboto+Mono\"\n      },\n      \"Droid Sans Mono\": {\n        \"css\": \"Droid Sans Mono\",\n        \"url\": \"//fonts.googleapis.com/css?family=Droid+Sans+Mono\"\n      },\n      \"Ubuntu Mono\": {\n        \"css\": \"Ubuntu Mono\",\n        \"url\": \"//fonts.googleapis.com/css?family=Ubuntu+Mono\"\n      },\n      \"PT Mono\": {\n        \"css\": \"PT Mono\",\n        \"url\": \"//fonts.googleapis.com/css?family=PT+Mono\"\n      },\n      \"Fira Mono\":{\n        \"css\": \"Fira Mono\",\n        \"url\": \"//fonts.googleapis.com/css?family=Fira+Mono\"\n      }\n    };\n\n    var CELLS, CODE_CELL;\n\n\n    function add_to_toolbar(current_theme) {\n\n        var cell_menu = $('#cell_menu'),\n          divider = $('<li/>').addClass('divider'),\n          theme_btn = $('<li/>').addClass('dropdown-submenu'),\n          theme_txt = $('<a/>').text('Code Syntax Theme').attr('href', '#'),\n          theme_list = $('<ul/>').addClass('dropdown-menu').attr('id', 'theme_select'),\n          font_btn = $('<li/>').addClass('dropdown-submenu'),\n          font_txt = $('<a/>').text('Code Font').attr('href', '#'),\n          font_list = $('<ul/>').addClass('dropdown-menu').attr('id', 'font_select'),\n          line_btn = $('<li/>'),\n          line_txt = $('<a/>').text('Code Line Numbers').attr('href', '#');\n\n        // Add label to the toolbar\n        cell_menu\n          .append(divider)\n          .append(theme_btn.append(theme_txt).append(theme_list))\n          .append(font_btn.append(font_txt).append(font_list))\n          .append(line_btn.append(line_txt));\n\n        // Add themes to the selector\n        for (var key in themes){\n            theme_list.append(\n              $('<li/>').append(\n                $('<a/>').text(key)\n                  .attr('href', '#')\n                  .attr('data-value', key)\n              )\n            );\n        }\n\n        theme_list.click(\n          function(e){\n            e.preventDefault;\n            if (e.target.tagName === \"A\"){\n                theme_toggle($(e.target).data(\"value\"));\n            }\n          }\n        );\n\n        // Add fonts to the selector\n        for (var key in fonts){\n            font_list.append(\n              $('<li/>').append(\n                $('<a/>').text(key)\n                  .attr('href', '#')\n                  .attr('data-key', key)\n                  .attr('data-css', fonts[key].css)\n                  .attr('data-url', fonts[key].url)\n              )\n            );\n        }\n\n        font_list.click(\n          function(e){\n            e.preventDefault;\n            if (e.target.tagName === \"A\"){\n                font_toggle(\n                  $(e.target).data(\"key\"),\n                  $(e.target).data(\"css\"),\n                  $(e.target).data(\"url\")\n                );\n            }\n          }\n        );\n\n        // Toggle line numbers\n        line_txt.click(\n          function(e){\n            e.preventDefault;\n\n            var opt = CODE_CELL.config.data.CodeCell.cm_config.lineNumbers;\n            var config = CODE_CELL.config;\n            var patch = {\n              CodeCell:{\n                cm_config:{\n                  lineNumbers: !opt\n                }\n              }\n            }\n            config.update(patch);\n\n            for (var i = 0; i < CELLS.length; i++){\n              if(CELLS[i].cell_type == \"code\"){\n                CELLS[i].code_mirror.setOption('lineNumbers', !opt);\n              }\n            }\n\n          }\n        );\n\n    }\n\n    function load_css(theme) {\n        // Create a link element to attach the styles\n        var link = document.createElement(\"link\");\n        link.type = \"text/css\";\n        link.rel = \"stylesheet\";\n        link.href = window.location.origin + require.toUrl(themes[theme]);\n        link.id = theme + \"-css\";\n        document.getElementsByTagName(\"head\")[0].appendChild(link);\n    }\n\n    function load_font(href) {\n      // Create a link element to attach the font\n      var link = document.createElement(\"link\");\n      link.type = \"text/css\";\n      link.rel = \"stylesheet\";\n      link.href = href;\n      document.getElementsByTagName(\"head\")[0].appendChild(link);\n    }\n\n    function css_toggle(font) {\n\n      var style = document.getElementById(\"font-css\");\n\n      if (!style){\n        // Create a style element\n        var style = document.createElement(\"style\");\n        style.type = \"text/css\";\n        style.id = \"font-css\"\n        document.head.appendChild(style);\n      }\n\n      style.innerText = \".CodeMirror {font-family: z;}\".replace(\"z\", font);\n\n    }\n\n    function theme_toggle(new_theme) {\n\n      new_theme = (new_theme === \"Default\")? \"ipython\" : new_theme;\n\n      if(new_theme !== \"ipython\") load_css(new_theme);\n\n      var config = CODE_CELL.config;\n      var patch = {\n        CodeCell:{\n          cm_config:{\n            theme: new_theme\n          }\n        }\n      }\n      config.update(patch);\n\n      for (var i = 0; i < CELLS.length; i++){\n        if(CELLS[i].cell_type == \"code\"){\n          CELLS[i].code_mirror.setOption('theme', new_theme);\n        }\n      }\n\n    }\n\n    function font_toggle(key, css, url) {\n\n      var config = CODE_CELL.config;\n      var patch = {\n        CodeCell:{\n          cm_config:{\n            font_family: key\n          }\n        }\n      }\n      config.update(patch);\n\n      if (key !== \"default\") {\n        load_font(url);\n      }\n\n      css_toggle(css);\n\n    }\n\n\n    function load_cells() {\n\n        for (var i = 0; i < CELLS.length; i++){\n          if(CELLS[i].cell_type == \"code\"){\n            CODE_CELL = CELLS[i];\n            break;\n          }\n        }\n\n        try {\n          var theme = CODE_CELL.config.data.CodeCell.cm_config.theme;\n          var key = CODE_CELL.config.data.CodeCell.cm_config.font_family;\n\n          load_css(theme);\n\n          if (key !== \"default\") {\n            load_font(fonts[key].url);\n            css_toggle(fonts[key].css);\n          }\n        }\n        catch(error) {\n          console.log(error);\n        }\n\n        add_to_toolbar();\n    }\n\n\n    function load_ipython_extension() {\n\n        CELLS = Jupyter.notebook.get_cells();\n\n        if (CELLS.length < 1) {\n            setTimeout(function(){\n                load_ipython_extension();\n            },250);\n        }\n        else {\n            load_cells()\n        }\n\n    }\n\n    return { load_ipython_extension: load_ipython_extension };\n\n});\n"
  }
]