Module: Asciidoctor::Html::Jupyterlite
- Defined in:
- lib/asciidoctor/html/jupyterlite.rb
Overview
Constants for the jupyterlite library
Constant Summary collapse
- PATH =
"jupyterlite"- REPL_PATH =
"repl/index.html"- CONFIG =
{ toolbar: true, kernel: "python", promptCellPosition: "left", clearCellsOnExecute: true, hideCodeInput: true, clearCodeContentOnExecute: false, showBanner: false, execute: false }.freeze
Class Attribute Summary collapse
-
.cell_id ⇒ Object
Returns the value of attribute cell_id.
Class Method Summary collapse
Class Attribute Details
.cell_id ⇒ Object
Returns the value of attribute cell_id.
8 9 10 |
# File 'lib/asciidoctor/html/jupyterlite.rb', line 8 def cell_id @cell_id end |
Class Method Details
.html(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/asciidoctor/html/jupyterlite.rb', line 42 def self.html(node) @cell_id += 1 cell_id = "jupyter-cell-frame-#{@cell_id}" height_attr = %( style="height: #{node.attr("height")}px;") if node.attr?("height") <<~HTML <div id="#{cell_id}"#{height_attr} class="jupyter-cell"></div> <script> (function(){ const cell = document.getElementById('#{cell_id}'); addEventListener('load', () => { const frame = document.createElement('iframe'); frame.src = '#{PATH}/#{ node}'; frame.width = '100%'; frame.height = '100%'; cell.appendChild(frame); }); })(); </script> HTML end |
.repl_path_with_options(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/html/jupyterlite.rb', line 25 def self.(node) query_string = ["code=#{URI.encode_uri_component node.content}"] query_string << CONFIG.merge( { promptCellPosition: node.attr("prompt-position", "left") } ).map do |k, v| value = if v == true 1 elsif v == false 0 else v end "#{k}=#{URI.encode_uri_component value}" end "#{REPL_PATH}?#{query_string.join "&"}" end |