-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPL mode for code blocks #1035
Conversation
This is amazing! Thank you SO MUCH 😍 Testing as we speak |
one thing that could be polished is to store code chunks and results in files so that we don't have to re-eval if nothing changes (at the moment these blocks will be re-evaluated on every page change). |
I spent hours this morning trying (and failing) to combine Replay.jl with asciinema to show things like pkg> st help?> map in a reproducible way, so honestly rerunning everything upon page changes is the last of my worries 🤣 |
no unfortunately, these would potentially also be a fair bit more difficult to do (to give a hint: you can't copy paste in the REPL something with a We could imagine having a |
Thanks for the explanation! |
The PR breaks on my macOS: julia> using Franklin
julia> serve()
Activating project at `~/Work/GitHub/ModernJuliaWorkflows`
→ Initial full pass...
┌ Franklin Warning: in <Project.toml>
│ Encountered an issue processing 'Project.toml' in ModernJuliaWorkflows.
│ Verify, then re-start the Franklin server.
│ The error is displayed below:
MethodError(Base._memcmp, (UInt8[0x5b, 0x64, 0x65, 0x70, 0x73, 0x5d, 0x0a, 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x22, 0x37, 0x31, 0x33, 0x63, 0x37, 0x35, 0x65, 0x66, 0x2d, 0x39, 0x66, 0x63, 0x39, 0x2d, 0x34, 0x62, 0x30, 0x35, 0x2d, 0x39, 0x34, 0x61, 0x39, 0x2d, 0x32, 0x31, 0x33, 0x33, 0x34, 0x30, 0x64, 0x61, 0x39, ...
└
ERROR: MethodError: no method matching _memcmp(::Vector{UInt8}, ::Vector{UInt8}, ::Int64)
Closest candidates are:
_memcmp(::Union{Ptr{UInt8}, AbstractString}, ::Union{Ptr{UInt8}, AbstractString}, ::Int64)
@ Base strings/string.jl:129
Stacktrace:
[1] (::FranklinTemplates.var"#5#7"{IOStream})(file2::IOStream)
@ FranklinTemplates ~/.julia/packages/FranklinTemplates/W5V3L/src/utils.jl:219
[2] open(::FranklinTemplates.var"#5#7"{IOStream}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
@ Base ./io.jl:396
[3] open(::FranklinTemplates.var"#5#7"{IOStream}, ::String, ::String)
@ Base ./io.jl:393 [inlined]
[4] (::FranklinTemplates.var"#4#6"{String})(file1::IOStream)
@ FranklinTemplates ~/.julia/packages/FranklinTemplates/W5V3L/src/utils.jl:212 [inlined]
[5] open(::FranklinTemplates.var"#4#6"{String}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
@ Base ./io.jl:396
[6] open(f::Function, args::Vararg{Any})
@ Base ./io.jl:393 [inlined]
[7] filecmp(path1::String, path2::String)
@ FranklinTemplates ~/.julia/packages/FranklinTemplates/W5V3L/src/utils.jl:211 [inlined]
[8] process_file_err(case::Symbol, fpair::Pair{String, String}, head::String, pgfoot::String, foot::String, t::Float64)
@ Franklin ~/.julia/packages/Franklin/Kqtgg/src/manager/file_utils.jl:169
[9] process_file(::Symbol, ::Pair{String, String}, ::String, ::Vararg{Any})
@ Franklin ~/.julia/packages/Franklin/Kqtgg/src/manager/file_utils.jl:104
[10] fd_fullpass(watched_files::@NamedTuple{other::Dict{…}, infra::Dict{…}, md::Dict{…}, html::Dict{…}, literate::Dict{…}}, join_to_prepath::String)
@ Franklin ~/.julia/packages/Franklin/Kqtgg/src/manager/franklin.jl:260
[11]
@ Franklin ~/.julia/packages/Franklin/Kqtgg/src/manager/franklin.jl:124
[12] serve()
@ Franklin ~/.julia/packages/Franklin/Kqtgg/src/manager/franklin.jl:49
[13] top-level scope
@ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types. |
This isn't related, to this PR. Which version of Julia are you using? the error seems to be caused by Can you try |
blank line should be removed for the contrast, yes it's handled by highlight js; there are two things you could do here:
the style sheet are in
you could also use Documenter's one (https://github.com/JuliaDocs/Documenter.jl/tree/master/assets/html/themes) |
Thanks for the pointers! My goal is only to get a slightly darker background, shouldn't be too hard to achieve |
@gdalle the basic stuff is added, you can test the following:
Note: for the |
This is awesome, thank you so much! It will improve the feeling of our blog post by 100. Testing now |
For the REPL mode, here are my first impressions
Test code a = rand(3, 2)
sum(a)
using LinearAlgebra # this should print a void
1 + 1; # this should print a void
# comment alone # this should print a void
using Flux # this should error
sum(exp(a)) # this should error Result |
For the docs mode:
Test code
Result |
And again, please don't take any of the previous messages as criticism. You asked for beta-testing so I'm gladly providing it :) I honestly didn't expect that my problem would be fixable, let alone so quickly, so I'm already beaming with joy and gratitude |
Thanks for the feedback @gdalle, some of these should be fixed in the current PR, some not. Notably capturing errors can be a bit annoying. Separately: would you be open to moving to Xranklin for what you're building now? it might require a few adjustments but fixing some of the stuff you pointed out would be easier there (as I'm a bit reluctant to add a lot of code to Franklin stuff that can be done soon and easily
stuff that is likely to be hard(er)
|
So should I keep using this PR or switch to Xranklin (perhaps on a specific branch?) |
I don't think any julia blog post uses evaluated code blocks The
for instance gives <pre><code class="language-julia-repl">julia> sqrt(-1)
DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
</code></pre> |
Maybe keep using this PR for now, I'll have a look at whether I can backport the Pkg stuff without making too much of a mess. All this stuff is not in Xranklin yet (but it's an ok draft). |
@tlienart maybe it is easy to add an option to render the output using the richest MIME? Then we could have LaTeX output and Images! Reminding you of |
that's definitely out scope for the present PR, however on a more positive note, the situation is much improved in Xranklin which lets the user define their preferred "show" method for objects if you're interested see https://tlienart.github.io/Xranklin.jl/syntax/code_1/#output_of_executable_code_blocks. This already allows image stuff and should make LaTeX output a fair bit easier. |
Indeed the Julia mode looks perfect now! |
@gdalle there's a stray .franklin-toc {
/* Avoid clickable elements being too close together. */
margin: 0.6rem 0;
}
/* ==================================================================
REPL BLOCKS
================================================================== */
.julia-help {
background-color: yellow;
padding: 10px;
font-style: italic;
}
.julia-help h1,h2,h3 {
font-size: 1em;
font-weight: 500;
} |
Awesome, thanks! |
If we want to get the right colors for the |
in .hljs-meta.shell_ {color: red;}
.hljs-meta.pkg_ {color: cornflowerblue;} (to have help mode being parsed in the same way you have to fiddle with |
yeah so if in subLanguage:"julia"}},{className:"meta.help",begin:/^help\?>/,relevance:10,starts:{end:/^(?![ ]{6})/, after
and then in .hljs-meta.help_ {color: goldenrod;} it'll get the styling right. |
Pkg mode is added (including multiline). Each page can activate its own environment now (recommended is to activate a temporary one). The site-wide environment is re-activated at the end of the page by default. You can try
I don't think I'll do the remaining items, so will let you play with this a bit, fix tests and stuff and eventually merge assuming it does what you expect. |
Amazing! I'll test right away |
both should be fixed now |
This looks really good to me, I don't have any other requests (lucky you 🤣). |
Two minor details:
I fixed it in my style sheet but it might be worth harmonizing in the future |
The styling stuff is up to the user; there could be demos in the franklintemplates which someone could pick up with adjusted CSS but for my part I'm going to skip on that in favour of working on Xranklin and upgrading the themes so they can work with it too. (also, you're likely to be the only one using this for a while). I'll merge this in master as it mostly doesn't affect anything else and will do a patch-release with it (it's not what it is but I don't want to release thanks for your input, glad this helps! |
Sounds very reasonable, thank you again for your hard work! I'll make sure to mention you on the blog post |
ongoing todo list here: #1035 (comment)
Can now do
and get the following html
(note
=
is=
)closes #818
cc @gdalle , @kescobo