Skip to content

Commit

Permalink
add html wasm export
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Dec 21, 2024
1 parent b95266d commit c8a2d09
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions scripts/export_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,52 @@ def export_html(notebook_path: str) -> None:
print(result.stderr)


def export_html_wasm(notebook_path: str) -> None:
"""Export a single marimo notebook to HTML format."""
output_path = f"{notebook_path}.wasm.run.html"
print(f"Exporting {notebook_path} to {output_path}")
result = subprocess.run(
[
"marimo",
"export",
"html-wasm",
notebook_path,
"-o",
f"public/{output_path}",
"--mode",
"run",
"--no-show-code",
],
capture_output=True,
text=True,
)

if result.returncode != 0:
print(f"Error exporting {notebook_path}:")
print(result.stderr)

output_path = f"{notebook_path}.wasm.edit.html"
print(f"Exporting {notebook_path} to {output_path}")
result = subprocess.run(
[
"marimo",
"export",
"html-wasm",
notebook_path,
"-o",
f"public/{output_path}",
"--mode",
"edit",
],
capture_output=True,
text=True,
)

if result.returncode != 0:
print(f"Error exporting {notebook_path}:")
print(result.stderr)


def export_ipynb(notebook_path: str) -> None:
"""Export a single marimo notebook to ipynb format."""
output_path = f"{notebook_path}.ipynb"
Expand Down Expand Up @@ -118,13 +164,19 @@ def generate_index(dir: str) -> None:
)
for notebook in WHITELISTED_NOTEBOOKS:
notebook_name = notebook.split("/")[-1].replace(".py", "")
display_name = notebook_name.replace("_", " ").title()

# Static HTML
f.write(
f' <a href="{os.path.join(dir, notebook)}.html" class="block p-4 border border-gray-200 rounded hover:border-black">\n'
)
f.write(
f' <h3 class="text-lg font-semibold">{notebook_name.replace("_", " ").title()}</h3>\n'
f' <div class="p-4 border border-gray-200 rounded">\n'
f' <h3 class="text-lg font-semibold mb-2">{display_name}</h3>\n'
f' <div class="flex gap-2">\n'
f' <a href="{os.path.join(dir, notebook)}.html" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded">Static HTML</a>\n'
f' <a href="{os.path.join(dir, notebook)}.wasm.run.html" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded">WASM Run</a>\n'
f' <a href="{os.path.join(dir, notebook)}.wasm.edit.html" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded">WASM Edit</a>\n'
f" </div>\n"
f" </div>\n"
)
f.write(" </a>\n")
f.write(
""" </div>
</body>
Expand Down Expand Up @@ -154,6 +206,7 @@ def main():
if os.path.exists(notebook_path):
export_markdown(notebook_path)
export_html(notebook_path)
export_html_wasm(notebook_path)
export_ipynb(notebook_path)
export_script(notebook_path)
else:
Expand Down

0 comments on commit c8a2d09

Please sign in to comment.