-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
894beb5
commit c2e5cde
Showing
5 changed files
with
87 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Pluto | ||
using JuliaFormatter | ||
|
||
# from https://github.com/fonsp/Pluto.jl/pull/2471 | ||
function generate_plaintext( | ||
notebook, | ||
strmacrotrim::Union{String,Nothing} = nothing; | ||
header::Function = _ -> nothing, | ||
footer::Function = _ -> nothing, | ||
textcomment::Function = identity, | ||
codewrapper::Function, | ||
) | ||
cell_strings = String[] | ||
header_content = header(notebook) | ||
isnothing(header_content) || push!(cell_strings, header_content) | ||
for cell_id in notebook.cell_order | ||
cell = notebook.cells_dict[cell_id] | ||
scode = strip(cell.code) | ||
(raw, ltrim, rtrim) = if isnothing(strmacrotrim) | ||
false, 0, 0 | ||
elseif startswith(scode, string(strmacrotrim, '"'^3)) | ||
true, length(strmacrotrim) + 3, 3 | ||
elseif startswith(scode, string(strmacrotrim, '"')) | ||
true, length(strmacrotrim) + 1, 1 | ||
else | ||
false, 0, 0 | ||
end | ||
push!( | ||
cell_strings, | ||
if raw | ||
text = strip( | ||
scode[nextind(scode, 1, ltrim):prevind(scode, end, rtrim)], | ||
['\n'], | ||
) | ||
ifelse(Pluto.is_disabled(cell), textcomment, identity)(text) | ||
else | ||
codewrapper(cell, Pluto.is_disabled(cell)) | ||
end, | ||
) | ||
end | ||
footer_content = footer(notebook) | ||
isnothing(footer_content) || push!(cell_strings, footer_content) | ||
return join(cell_strings, "\n\n") | ||
end | ||
|
||
function generate_md(input; output = replace(input, ".jl" => ".md")) | ||
notebook = Pluto.load_notebook(input) | ||
fname = basename(input) | ||
function header(_) | ||
return "[![Pluto notebook](https://img.shields.io/badge/download-Pluto_notebook-blue)]($fname)" | ||
end | ||
function codewrapper(cell, _) | ||
# 1. Strips begin/end block | ||
# 2. Reformats code using JuliaFormatter | ||
# 3. Wraps all code in same ```@example``` block for documenter | ||
code = strip(cell.code) | ||
if startswith(code, "begin") && endswith(code, "end") | ||
# Remove "begin" and "end" and reformat block | ||
code = strip(code[6:end-4]) | ||
code = format_text(String(code)) | ||
end | ||
return if cell.code_folded | ||
string("```@setup $fname\n", code, "\n```") | ||
else | ||
string("```@example $fname\n", code, "\n```") | ||
end | ||
end | ||
textcomment(text) = string("<!-- ", text, " -->") | ||
str = generate_plaintext(notebook, "md"; header, codewrapper, textcomment) | ||
open(output, "w") do io | ||
return write(io, str) | ||
end | ||
return output | ||
end |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
### A Pluto.jl notebook ### | ||
# v0.19.46 | ||
# v0.19.47 | ||
|
||
using Markdown | ||
using InteractiveUtils | ||
|
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