Literate.jl icon indicating copy to clipboard operation
Literate.jl copied to clipboard

Could Literate accommodate cells of execution (VS code)?

Open PetrKryslUCSD opened this issue 5 years ago • 4 comments

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.

PetrKryslUCSD avatar Aug 17 '20 19:08 PetrKryslUCSD

This was discussed on https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777 as well (including some concrete examples).

st-- avatar Jul 08 '21 09:07 st--

@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...).

st-- avatar Jul 08 '21 09:07 st--

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.)

st-- avatar Jul 08 '21 10:07 st--

Could be added to the "Tips and Tricks" section in the manual. Would you like to make a PR?

fredrikekre avatar Jul 08 '21 10:07 fredrikekre