Literate.jl
Literate.jl copied to clipboard
Could Literate accommodate cells of execution (VS code)?
VS code uses 2#'s at the beginning of the line to indicate the start of a cell. Literate interprets this to leave behind a comment.
Could this be accommodated somehow? @pfitzseb Also pointed out that the VS code team is thinking about using #%% as the start-of-cell marker.
This was discussed on https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777 as well (including some concrete examples).
@PetrKryslUCSD you can use the preprocess functionality with a function like the following:
function preprocess(content)
return replace(content, r"^##$."ms => "")
end
This matches lines that are exactly ##, including the trailing newline (. inside the regexp and s postfix option, see https://perldoc.perl.org/perlre#Modifiers) and removes it.
Pass it to Literate by calling e.g. Literate.markdown(script, outputdir; preprocess=preprocess, kwargs...).
It's much cleaner to explicitly use this preprocessing than to build in some hard-coded processing for one specific environment, so should this issue be closed now? (I also pointed out the preprocess solution in the linked discourse thread.)
Could be added to the "Tips and Tricks" section in the manual. Would you like to make a PR?