From 13ee7880e74d5959efaac402be09ec5f6d3f1a56 Mon Sep 17 00:00:00 2001 From: Gelieza K Date: Fri, 4 Aug 2023 17:01:07 +0200 Subject: [PATCH] Automatically convert images to base64 --- docs/make.jl | 21 +- docs/reformat_attached_images.jl | 17 + docs/src/julia_distributed_test.md | 30 + docs/src/notebook-output/julia_Jacobi.html | 16 +- .../notebook-output/julia_distributed.html | 6 +- .../julia_distributed_test.html | 16868 ++++++++++++++++ docs/src/notebook-output/julia_intro.html | 2 +- docs/src/notebook-output/matrix_matrix.html | 355 +- docs/src/notebook-output/notebook-hello.html | 2 +- .../notebook-output/sol_matrix_matrix.html | 15182 ++++++++++++++ docs/src/notebooks/julia_distributed.ipynb | 10 +- .../notebooks/julia_distributed_test.ipynb | 1269 ++ docs/src/notebooks/julia_intro.ipynb | 2 +- docs/src/notebooks/julia_jacobi.ipynb | 16 +- docs/src/notebooks/matrix_matrix.ipynb | 35 +- docs/src/notebooks/notebook-hello.ipynb | 4 +- docs/src/notebooks/sol_matrix_matrix.ipynb | 60 + docs/src/sol_matrix_matrix.md | 30 + 18 files changed, 33825 insertions(+), 100 deletions(-) create mode 100644 docs/reformat_attached_images.jl create mode 100644 docs/src/julia_distributed_test.md create mode 100644 docs/src/notebook-output/julia_distributed_test.html create mode 100644 docs/src/notebook-output/sol_matrix_matrix.html create mode 100644 docs/src/notebooks/julia_distributed_test.ipynb create mode 100644 docs/src/notebooks/sol_matrix_matrix.ipynb create mode 100644 docs/src/sol_matrix_matrix.md diff --git a/docs/make.jl b/docs/make.jl index 3e9743f..20c3d6e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -35,12 +35,28 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/SCR ``` """ +function convert_embedded_img_to_base64(notebook_path) + doc = open(io->read(io, String), notebook_path) + # Regex matching: extract filename and base64 code + regex = r"attachments\\\":\s*\{\s*\\\"(?.*).png\\\":\s*\{\s*\\\"image/png\\\":\s*\\\"(?.*)\\\"" + res = eachmatch(regex, doc) + matches = collect(res) + # Replace img src with base64 code + for m in matches + filename = m[:filename] + base64 = m[:base64code] + doc = replace(doc, "attachment:$filename.png" => "data:image/png;base64,$base64") + end + + write(notebook_path, doc); +end + # Write markdown file that includes notebook html function create_md_nb_file( notebook_path ) global md_nb_template; script_file = splitpath(notebook_path)[end] script_name = splitext(script_file)[1] - content = replace( md_nb_template, "SCRIPT_NAME" => script_name) + content = replace(md_nb_template, "SCRIPT_NAME" => script_name) md_path = joinpath(@__DIR__, "src", script_name * ".md" ) open(md_path, "w") do md_file write(md_file, content) @@ -87,6 +103,7 @@ end # Loop over notebooks and generate html and markdown notebook_files = glob("*.ipynb", "docs/src/notebooks/") for filepath in notebook_files + convert_embedded_img_to_base64(filepath) create_md_nb_file(filepath) filename_with_ext = splitpath(filepath)[end] filename = splitext(filename_with_ext)[1] @@ -109,7 +126,7 @@ makedocs(; "Julia Basics" => "julia_basics.md", "Julia Asynchronous" => "julia_async.md", "Julia Distributed" => "julia_distributed.md", - "Matrix Multiplication"=>"matrix_matrix.md", + "Matrix Multiplication"=>["Matrix Multiplication" => "matrix_matrix.md", "Solutions" => "sol_matrix_matrix.md"], "Jacobi/SOR" => "julia_jacobi.md" ]], ) diff --git a/docs/reformat_attached_images.jl b/docs/reformat_attached_images.jl new file mode 100644 index 0000000..72ede58 --- /dev/null +++ b/docs/reformat_attached_images.jl @@ -0,0 +1,17 @@ + +function convert_embedded_img_to_base64(notebook_path) + doc = open(io->read(io, String), notebook_path) + # Regex matching: extract filename and base64 code + regex = r"attachments\\\":\s*\{\s*\\\"(?.*).png\\\":\s*\{\s*\\\"image/png\\\":\s*\\\"(?.*)\\\"" + res = eachmatch(regex, doc) + matches = collect(res) + # Replace img src with base64 code + for m in matches + global doc; + filename = m[:filename] + base64 = m[:base64code] + doc = replace(doc, "attachment:$filename.png" => "data:image/png;base64,$base64") + end + + write(notebook_path, doc); +end \ No newline at end of file diff --git a/docs/src/julia_distributed_test.md b/docs/src/julia_distributed_test.md new file mode 100644 index 0000000..35655b0 --- /dev/null +++ b/docs/src/julia_distributed_test.md @@ -0,0 +1,30 @@ +```@meta +EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/julia_distributed_test.ipynb" +``` + +```@raw html +
+
Tip
+
+
    +
  • + Download this notebook and run it locally on your machine [recommended]. Click here. +
  • +
  • + You can also run this notebook in the cloud using Binder. Click here + . +
  • +
+
+
+``` + +```@raw html + + +``` diff --git a/docs/src/notebook-output/julia_Jacobi.html b/docs/src/notebook-output/julia_Jacobi.html index a82876f..58d3ef6 100644 --- a/docs/src/notebook-output/julia_Jacobi.html +++ b/docs/src/notebook-output/julia_Jacobi.html @@ -15185,7 +15185,7 @@ body[data-format='mobile'] .jp-OutputArea-child .jp-OutputArea-output {