-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using JSON | ||
|
||
""" | ||
convert_notebook_to_litterate(ipynb_file::String, litterate_file::String) | ||
Function to convert a Jupyter notebook (.ipynb) into a Litterate-compatible Julia script | ||
""" | ||
function convert_notebook_to_litterate(ipynb_file::String, litterate_file::String) | ||
# Read the Jupyter notebook file | ||
notebook_content = JSON.parsefile(ipynb_file) | ||
|
||
# Open the output Julia file for writing | ||
open(litterate_file, "w") do f | ||
# Loop through each cell in the notebook | ||
for cell in notebook_content["cells"] | ||
if cell["cell_type"] == "markdown" | ||
# Convert markdown cells to comments | ||
for line in cell["source"] | ||
println(f, "# ", strip(line)) | ||
end | ||
elseif cell["cell_type"] == "code" | ||
# Write code cells as-is | ||
for line in cell["source"] | ||
println(f, strip(line)) | ||
end | ||
end | ||
# Add a blank line between cells for readability | ||
println(f) | ||
end | ||
end | ||
end |
Oops, something went wrong.